refactor: updated logic in depreciation and gl to validate acc frozen date company wise

This commit is contained in:
Khushi Rawat
2025-06-10 16:01:51 +05:30
committed by khushi8112
parent 936b81b404
commit 1affdaa94d
2 changed files with 26 additions and 27 deletions

View File

@@ -404,7 +404,7 @@ def save_entries(gl_map, adv_adj, update_outstanding, from_repost=False):
dimension_filter_map = get_dimension_filter_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)
if gl_map[0]["voucher_type"] != "Period Closing Voucher":
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")
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
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
"""
if not adv_adj:
acc_frozen_upto = frappe.get_single_value("Accounts Settings", "acc_frozen_upto")
if acc_frozen_upto:
frozen_accounts_modifier = frappe.get_single_value(
"Accounts Settings", "frozen_accounts_modifier"
acc_frozen_till_date = frappe.db.get_value("Company", company, "accounts_frozen_till_date")
if acc_frozen_till_date:
frozen_accounts_modifier = frappe.db.get_value(
"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"
):
frappe.throw(
_("You are not authorized to add or update entries before {0}").format(
formatdate(acc_frozen_upto)
formatdate(acc_frozen_till_date)
)
)

View File

@@ -96,13 +96,26 @@ def get_depreciable_assets_data(date):
.orderby(a.creation, order=Order.desc)
)
acc_frozen_upto = get_acc_frozen_upto()
if acc_frozen_upto:
res = res.where(ds.schedule_date > acc_frozen_upto)
companies_with_frozen_limits = get_companies_with_frozen_limits()
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):
@@ -111,20 +124,6 @@ def make_depreciation_entry_on_disposal(asset_doc, disposal_date=None):
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):
# Returns credit and debit accounts for the given asset category and company.
(_, accumulated_depr_account, depr_expense_account) = get_depreciation_accounts(asset_category, company)