refactor: move reposting logic to common controller
This commit is contained in:
@@ -2186,6 +2186,44 @@ class AccountsController(TransactionBase):
|
||||
_("Select finance book for the item {0} at row {1}").format(item.item_code, item.idx)
|
||||
)
|
||||
|
||||
def check_if_fields_updated(self, fields_to_check, child_tables):
|
||||
# Check if any field affecting accounting entry is altered
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
@frappe.whitelist()
|
||||
def repost_accounting_entries(self):
|
||||
if self.repost_required:
|
||||
self.docstatus = 2
|
||||
self.make_gl_entries_on_cancel()
|
||||
self.docstatus = 1
|
||||
self.make_gl_entries()
|
||||
self.db_set("repost_required", 0)
|
||||
else:
|
||||
frappe.throw(_("No updates pending for reposting"))
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_tax_rate(account_head):
|
||||
@@ -3191,6 +3229,23 @@ def update_child_qty_rate(parent_doctype, trans_items, parent_doctype_name, chil
|
||||
parent.create_stock_reservation_entries()
|
||||
|
||||
|
||||
def check_if_child_table_updated(
|
||||
child_table_before_update, child_table_after_update, fields_to_check
|
||||
):
|
||||
accounting_dimensions = get_accounting_dimensions() + ["cost_center", "project"]
|
||||
# Check if any field affecting accounting entry is altered
|
||||
for index, item in enumerate(child_table_after_update):
|
||||
for field in fields_to_check:
|
||||
if child_table_before_update[index].get(field) != item.get(field):
|
||||
return True
|
||||
|
||||
for dimension in accounting_dimensions:
|
||||
if child_table_before_update[index].get(dimension) != item.get(dimension):
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
|
||||
@erpnext.allow_regional
|
||||
def validate_regional(doc):
|
||||
pass
|
||||
|
||||
Reference in New Issue
Block a user