refactor: better abstraction for controller code
diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py
index 85ed126..6533e4b 100644
--- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py
+++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py
@@ -536,6 +536,7 @@
"cash_bank_account",
"write_off_account",
"unrealized_profit_loss_account",
+ "is_opening",
]
child_tables = {"items": ("expense_account",), "taxes": ("account_head",)}
self.needs_repost = self.check_if_fields_updated(fields_to_check, child_tables)
diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py
index f380825..cad67cc 100644
--- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py
+++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py
@@ -530,6 +530,7 @@
"write_off_account",
"loyalty_redemption_account",
"unrealized_profit_loss_account",
+ "is_opening",
]
child_tables = {
"items": ("income_account", "expense_account", "discount_account"),
diff --git a/erpnext/controllers/accounts_controller.py b/erpnext/controllers/accounts_controller.py
index 6812940..8d763ac 100644
--- a/erpnext/controllers/accounts_controller.py
+++ b/erpnext/controllers/accounts_controller.py
@@ -2216,27 +2216,20 @@
doc_before_update = self.get_doc_before_save()
accounting_dimensions = get_accounting_dimensions() + ["cost_center", "project"]
- # Check if opening entry check updated
- needs_repost = doc_before_update.get("is_opening") != self.is_opening
+ # Parent Level Accounts excluding party account
+ fields_to_check += accounting_dimensions
+ for field in fields_to_check:
+ if doc_before_update.get(field) != self.get(field):
+ return True
- if not needs_repost:
- # Parent Level Accounts excluding party account
- fields_to_check += accounting_dimensions
- for field in fields_to_check:
- if doc_before_update.get(field) != self.get(field):
- needs_repost = 1
- break
+ # Check for child tables
+ for table in child_tables:
+ if check_if_child_table_updated(
+ doc_before_update.get(table), self.get(table), child_tables[table]
+ ):
+ return True
- if not needs_repost:
- # Check for child tables
- for table in child_tables:
- needs_repost = check_if_child_table_updated(
- doc_before_update.get(table), self.get(table), child_tables[table]
- )
- if needs_repost:
- break
-
- return needs_repost
+ return False
@frappe.whitelist()
def repost_accounting_entries(self):