fix: undo incorrect patch modification

This commit is contained in:
khushi8112
2025-12-02 14:24:27 +05:30
parent c7e7e02b5b
commit 4f33ee01cf

View File

@@ -10,17 +10,15 @@ def execute():
purchase_invoices = frappe.db.sql( purchase_invoices = frappe.db.sql(
""" """
select select
PI.company, PI_ADV.parenttype as type, PI_ADV.parent as name parenttype as type, parent as name
from from
`tabPurchase Invoice Advance` as PI_ADV join `tabPurchase Invoice` as PI `tabPurchase Invoice Advance`
on
PI_ADV.parent = PI.name
where where
PI_ADV.ref_exchange_rate = 1 ref_exchange_rate = 1
and PI_ADV.docstatus = 1 and docstatus = 1
and ifnull(PI_ADV.exchange_gain_loss, 0) != 0 and ifnull(exchange_gain_loss, 0) != 0
group by group by
PI_ADV.parent parent
""", """,
as_dict=1, as_dict=1,
) )
@@ -28,17 +26,15 @@ def execute():
sales_invoices = frappe.db.sql( sales_invoices = frappe.db.sql(
""" """
select select
SI.company, SI_ADV.parenttype as type, SI_ADV.parent as name parenttype as type, parent as name
from from
`tabSales Invoice Advance` as SI_ADV join `tabSales Invoice` as SI `tabSales Invoice Advance`
on
SI_ADV.parent = SI.name
where where
SI_ADV.ref_exchange_rate = 1 ref_exchange_rate = 1
and SI_ADV.docstatus = 1 and docstatus = 1
and ifnull(SI_ADV.exchange_gain_loss, 0) != 0 and ifnull(exchange_gain_loss, 0) != 0
group by group by
SI_ADV.parent parent
""", """,
as_dict=1, as_dict=1,
) )
@@ -49,21 +45,11 @@ def execute():
message=json.dumps(purchase_invoices + sales_invoices, indent=2), message=json.dumps(purchase_invoices + sales_invoices, indent=2),
) )
original_frozen_dates = {} 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)
for invoice in purchase_invoices + sales_invoices: 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: try:
doc = frappe.get_doc(invoice.type, invoice.name) doc = frappe.get_doc(invoice.type, invoice.name)
doc.docstatus = 2 doc.docstatus = 2
@@ -78,6 +64,5 @@ def execute():
frappe.db.rollback() frappe.db.rollback()
print(f"Failed to correct gl entries of {invoice.name}") print(f"Failed to correct gl entries of {invoice.name}")
for company, frozen_date in original_frozen_dates.items(): if acc_frozen_upto:
if frozen_date: frappe.db.set_single_value("Accounts Settings", "acc_frozen_upto", acc_frozen_upto)
frappe.db.set_value("Company", company, "accounts_frozen_till_date", frozen_date)