refactor: better abstraction for controller code

This commit is contained in:
Gursheen Anand 2023-10-12 12:48:14 +05:30
parent e4d657e6fd
commit 9ab55a5bd8
3 changed files with 14 additions and 19 deletions

View File

@ -536,6 +536,7 @@ class PurchaseInvoice(BuyingController):
"cash_bank_account", "cash_bank_account",
"write_off_account", "write_off_account",
"unrealized_profit_loss_account", "unrealized_profit_loss_account",
"is_opening",
] ]
child_tables = {"items": ("expense_account",), "taxes": ("account_head",)} child_tables = {"items": ("expense_account",), "taxes": ("account_head",)}
self.needs_repost = self.check_if_fields_updated(fields_to_check, child_tables) self.needs_repost = self.check_if_fields_updated(fields_to_check, child_tables)

View File

@ -530,6 +530,7 @@ class SalesInvoice(SellingController):
"write_off_account", "write_off_account",
"loyalty_redemption_account", "loyalty_redemption_account",
"unrealized_profit_loss_account", "unrealized_profit_loss_account",
"is_opening",
] ]
child_tables = { child_tables = {
"items": ("income_account", "expense_account", "discount_account"), "items": ("income_account", "expense_account", "discount_account"),

View File

@ -2216,27 +2216,20 @@ class AccountsController(TransactionBase):
doc_before_update = self.get_doc_before_save() doc_before_update = self.get_doc_before_save()
accounting_dimensions = get_accounting_dimensions() + ["cost_center", "project"] accounting_dimensions = get_accounting_dimensions() + ["cost_center", "project"]
# Check if opening entry check updated # Parent Level Accounts excluding party account
needs_repost = doc_before_update.get("is_opening") != self.is_opening 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: # Check for child tables
# Parent Level Accounts excluding party account for table in child_tables:
fields_to_check += accounting_dimensions if check_if_child_table_updated(
for field in fields_to_check: doc_before_update.get(table), self.get(table), child_tables[table]
if doc_before_update.get(field) != self.get(field): ):
needs_repost = 1 return True
break
if not needs_repost: return False
# 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
@frappe.whitelist() @frappe.whitelist()
def repost_accounting_entries(self): def repost_accounting_entries(self):