mirror of
https://github.com/frappe/erpnext.git
synced 2026-04-28 02:58:30 +00:00
refactor: get frozen accounts settings from Company in patches
This commit is contained in:
@@ -10,15 +10,17 @@ def execute():
|
||||
purchase_invoices = frappe.db.sql(
|
||||
"""
|
||||
select
|
||||
parenttype as type, parent as name
|
||||
PI.company, PI_ADV.parenttype as type, PI_ADV.parent as name
|
||||
from
|
||||
`tabPurchase Invoice Advance`
|
||||
`tabPurchase Invoice Advance` as PI_ADV join `tabPurchase Invoice` as PI
|
||||
on
|
||||
PI_ADV.parent = PI.name
|
||||
where
|
||||
ref_exchange_rate = 1
|
||||
and docstatus = 1
|
||||
and ifnull(exchange_gain_loss, 0) != 0
|
||||
PI_ADV.ref_exchange_rate = 1
|
||||
and PI_ADV.docstatus = 1
|
||||
and ifnull(PI_ADV.exchange_gain_loss, 0) != 0
|
||||
group by
|
||||
parent
|
||||
PI_ADV.parent
|
||||
""",
|
||||
as_dict=1,
|
||||
)
|
||||
@@ -26,15 +28,17 @@ def execute():
|
||||
sales_invoices = frappe.db.sql(
|
||||
"""
|
||||
select
|
||||
parenttype as type, parent as name
|
||||
SI.company, SI_ADV.parenttype as type, SI_ADV.parent as name
|
||||
from
|
||||
`tabSales Invoice Advance`
|
||||
`tabSales Invoice Advance` as SI_ADV join `tabSales Invoice` as SI
|
||||
on
|
||||
SI_ADV.parent = SI.name
|
||||
where
|
||||
ref_exchange_rate = 1
|
||||
and docstatus = 1
|
||||
and ifnull(exchange_gain_loss, 0) != 0
|
||||
SI_ADV.ref_exchange_rate = 1
|
||||
and SI_ADV.docstatus = 1
|
||||
and ifnull(SI_ADV.exchange_gain_loss, 0) != 0
|
||||
group by
|
||||
parent
|
||||
SI_ADV.parent
|
||||
""",
|
||||
as_dict=1,
|
||||
)
|
||||
@@ -45,11 +49,21 @@ def execute():
|
||||
message=json.dumps(purchase_invoices + sales_invoices, indent=2),
|
||||
)
|
||||
|
||||
acc_frozen_upto = frappe.db.get_single_value("Accounts Settings", "acc_frozen_upto")
|
||||
if acc_frozen_upto:
|
||||
frappe.db.set_single_value("Accounts Settings", "acc_frozen_upto", None)
|
||||
original_frozen_dates = {}
|
||||
|
||||
for invoice in purchase_invoices + sales_invoices:
|
||||
company = invoice.company
|
||||
|
||||
# Unfreeze only once per company
|
||||
if company not in original_frozen_dates:
|
||||
accounts_frozen_till_date = frappe.get_cached_value(
|
||||
"Company", company, "accounts_frozen_till_date"
|
||||
)
|
||||
original_frozen_dates[company] = accounts_frozen_till_date
|
||||
|
||||
if accounts_frozen_till_date:
|
||||
frappe.db.set_value("Company", company, "accounts_frozen_till_date", None)
|
||||
|
||||
try:
|
||||
doc = frappe.get_doc(invoice.type, invoice.name)
|
||||
doc.docstatus = 2
|
||||
@@ -64,5 +78,6 @@ def execute():
|
||||
frappe.db.rollback()
|
||||
print(f"Failed to correct gl entries of {invoice.name}")
|
||||
|
||||
if acc_frozen_upto:
|
||||
frappe.db.set_single_value("Accounts Settings", "acc_frozen_upto", acc_frozen_upto)
|
||||
for company, frozen_date in original_frozen_dates.items():
|
||||
if frozen_date:
|
||||
frappe.db.set_value("Company", company, "accounts_frozen_till_date", frozen_date)
|
||||
|
||||
@@ -77,4 +77,4 @@ def get_accounts_closing_date():
|
||||
else:
|
||||
can_edit_accounts_after = accounts_frozen_till or period_closing_date
|
||||
|
||||
return can_edit_accounts_after
|
||||
return can_edit_accounts_after
|
||||
@@ -58,9 +58,9 @@ def execute():
|
||||
):
|
||||
posting_date = period_closing_voucher[0].period_end_date
|
||||
|
||||
acc_frozen_upto = frappe.db.get_single_value("Accounts Settings", "acc_frozen_upto")
|
||||
if acc_frozen_upto and getdate(acc_frozen_upto) > getdate(posting_date):
|
||||
posting_date = acc_frozen_upto
|
||||
acc_frozen_till_date = frappe.db.get_value("Company", company, "accounts_frozen_till_date")
|
||||
if acc_frozen_till_date and getdate(acc_frozen_till_date) > getdate(posting_date):
|
||||
posting_date = acc_frozen_till_date
|
||||
|
||||
stock_frozen_upto = frappe.db.get_single_value("Stock Settings", "stock_frozen_upto")
|
||||
if stock_frozen_upto and getdate(stock_frozen_upto) > getdate(posting_date):
|
||||
|
||||
@@ -168,16 +168,19 @@ class RepostItemValuation(Document):
|
||||
return query[0][0] if query and query[0][0] else None
|
||||
|
||||
def validate_accounts_freeze(self):
|
||||
acc_settings = frappe.get_cached_doc("Accounts Settings")
|
||||
if not acc_settings.acc_frozen_upto:
|
||||
acc_frozen_till_date = frappe.db.get_value("Company", self.company, "accounts_frozen_till_date")
|
||||
frozen_accounts_modifier = frappe.db.get_value(
|
||||
"Company", self.company, "role_allowed_for_frozen_entries"
|
||||
)
|
||||
if not acc_frozen_till_date:
|
||||
return
|
||||
if getdate(self.posting_date) <= getdate(acc_settings.acc_frozen_upto):
|
||||
if acc_settings.frozen_accounts_modifier and frappe.session.user in get_users_with_role(
|
||||
acc_settings.frozen_accounts_modifier
|
||||
if getdate(self.posting_date) <= getdate(acc_frozen_till_date):
|
||||
if frozen_accounts_modifier and frappe.session.user in get_users_with_role(
|
||||
frozen_accounts_modifier
|
||||
):
|
||||
frappe.msgprint(_("Caution: This might alter frozen accounts."))
|
||||
return
|
||||
frappe.throw(_("You cannot repost item valuation before {}").format(acc_settings.acc_frozen_upto))
|
||||
frappe.throw(_("You cannot repost item valuation before {}").format(acc_frozen_till_date))
|
||||
|
||||
def reset_field_values(self):
|
||||
if self.based_on == "Transaction":
|
||||
|
||||
Reference in New Issue
Block a user