mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-15 11:09:17 +00:00
refactor: updated logic in depreciation and gl to validate acc frozen date company wise
This commit is contained in:
@@ -404,7 +404,7 @@ def save_entries(gl_map, adv_adj, update_outstanding, from_repost=False):
|
|||||||
|
|
||||||
dimension_filter_map = get_dimension_filter_map()
|
dimension_filter_map = get_dimension_filter_map()
|
||||||
if gl_map:
|
if gl_map:
|
||||||
check_freezing_date(gl_map[0]["posting_date"], adv_adj)
|
check_freezing_date(gl_map[0]["posting_date"], gl_map[0]["company"], adv_adj)
|
||||||
is_opening = any(d.get("is_opening") == "Yes" for d in gl_map)
|
is_opening = any(d.get("is_opening") == "Yes" for d in gl_map)
|
||||||
if gl_map[0]["voucher_type"] != "Period Closing Voucher":
|
if gl_map[0]["voucher_type"] != "Period Closing Voucher":
|
||||||
validate_against_pcv(is_opening, gl_map[0]["posting_date"], gl_map[0]["company"])
|
validate_against_pcv(is_opening, gl_map[0]["posting_date"], gl_map[0]["company"])
|
||||||
@@ -765,7 +765,7 @@ def make_reverse_gl_entries(
|
|||||||
make_entry(new_gle, adv_adj, "Yes")
|
make_entry(new_gle, adv_adj, "Yes")
|
||||||
|
|
||||||
|
|
||||||
def check_freezing_date(posting_date, adv_adj=False):
|
def check_freezing_date(posting_date, company, adv_adj=False):
|
||||||
"""
|
"""
|
||||||
Nobody can do GL Entries where posting date is before freezing date
|
Nobody can do GL Entries where posting date is before freezing date
|
||||||
except authorized person
|
except authorized person
|
||||||
@@ -774,17 +774,17 @@ def check_freezing_date(posting_date, adv_adj=False):
|
|||||||
Hence stop admin to bypass if accounts are freezed
|
Hence stop admin to bypass if accounts are freezed
|
||||||
"""
|
"""
|
||||||
if not adv_adj:
|
if not adv_adj:
|
||||||
acc_frozen_upto = frappe.get_single_value("Accounts Settings", "acc_frozen_upto")
|
acc_frozen_till_date = frappe.db.get_value("Company", company, "accounts_frozen_till_date")
|
||||||
if acc_frozen_upto:
|
if acc_frozen_till_date:
|
||||||
frozen_accounts_modifier = frappe.get_single_value(
|
frozen_accounts_modifier = frappe.db.get_value(
|
||||||
"Accounts Settings", "frozen_accounts_modifier"
|
"Company", company, "role_allowed_for_frozen_entries"
|
||||||
)
|
)
|
||||||
if getdate(posting_date) <= getdate(acc_frozen_upto) and (
|
if getdate(posting_date) <= getdate(acc_frozen_till_date) and (
|
||||||
frozen_accounts_modifier not in frappe.get_roles() or frappe.session.user == "Administrator"
|
frozen_accounts_modifier not in frappe.get_roles() or frappe.session.user == "Administrator"
|
||||||
):
|
):
|
||||||
frappe.throw(
|
frappe.throw(
|
||||||
_("You are not authorized to add or update entries before {0}").format(
|
_("You are not authorized to add or update entries before {0}").format(
|
||||||
formatdate(acc_frozen_upto)
|
formatdate(acc_frozen_till_date)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -96,13 +96,26 @@ def get_depreciable_assets_data(date):
|
|||||||
.orderby(a.creation, order=Order.desc)
|
.orderby(a.creation, order=Order.desc)
|
||||||
)
|
)
|
||||||
|
|
||||||
acc_frozen_upto = get_acc_frozen_upto()
|
companies_with_frozen_limits = get_companies_with_frozen_limits()
|
||||||
if acc_frozen_upto:
|
|
||||||
res = res.where(ds.schedule_date > acc_frozen_upto)
|
|
||||||
|
|
||||||
res = res.run()
|
for company, frozen_upto in companies_with_frozen_limits.items():
|
||||||
|
res = res.where((a.company != company) | (ds.schedule_date > frozen_upto))
|
||||||
|
|
||||||
return res
|
return res.run()
|
||||||
|
|
||||||
|
|
||||||
|
def get_companies_with_frozen_limits():
|
||||||
|
companies_with_frozen_limits = {}
|
||||||
|
for d in frappe.get_all(
|
||||||
|
"Company", fields=["name", "accounts_frozen_till_date", "role_allowed_for_frozen_entries"]
|
||||||
|
):
|
||||||
|
if not d.accounts_frozen_till_date:
|
||||||
|
continue
|
||||||
|
|
||||||
|
if d.role_allowed_for_frozen_entries in frappe.get_roles() or frappe.session.user == "Administrator":
|
||||||
|
continue
|
||||||
|
companies_with_frozen_limits[d.name] = getdate(d.accounts_frozen_till_date)
|
||||||
|
return companies_with_frozen_limits
|
||||||
|
|
||||||
|
|
||||||
def make_depreciation_entry_on_disposal(asset_doc, disposal_date=None):
|
def make_depreciation_entry_on_disposal(asset_doc, disposal_date=None):
|
||||||
@@ -111,20 +124,6 @@ def make_depreciation_entry_on_disposal(asset_doc, disposal_date=None):
|
|||||||
make_depreciation_entry(depr_schedule_name, disposal_date)
|
make_depreciation_entry(depr_schedule_name, disposal_date)
|
||||||
|
|
||||||
|
|
||||||
def get_acc_frozen_upto():
|
|
||||||
acc_frozen_upto = frappe.get_single_value("Accounts Settings", "acc_frozen_upto")
|
|
||||||
|
|
||||||
if not acc_frozen_upto:
|
|
||||||
return
|
|
||||||
|
|
||||||
frozen_accounts_modifier = frappe.get_single_value("Accounts Settings", "frozen_accounts_modifier")
|
|
||||||
|
|
||||||
if frozen_accounts_modifier not in frappe.get_roles() or frappe.session.user == "Administrator":
|
|
||||||
return getdate(acc_frozen_upto)
|
|
||||||
|
|
||||||
return
|
|
||||||
|
|
||||||
|
|
||||||
def get_credit_debit_accounts_for_asset(asset_category, company):
|
def get_credit_debit_accounts_for_asset(asset_category, company):
|
||||||
# Returns credit and debit accounts for the given asset category and company.
|
# Returns credit and debit accounts for the given asset category and company.
|
||||||
(_, accumulated_depr_account, depr_expense_account) = get_depreciation_accounts(asset_category, company)
|
(_, accumulated_depr_account, depr_expense_account) = get_depreciation_accounts(asset_category, company)
|
||||||
|
|||||||
Reference in New Issue
Block a user