Skip to content

Commit

Permalink
chore: Break into smaller functions
Browse files Browse the repository at this point in the history
  • Loading branch information
deepeshgarg007 committed Oct 17, 2022
1 parent e626107 commit 42e4c37
Showing 1 changed file with 27 additions and 20 deletions.
47 changes: 27 additions & 20 deletions erpnext/accounts/doctype/sales_invoice/sales_invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -551,31 +551,38 @@ def on_update_after_submit(self):
needs_repost = 1
break

# Check for parent level
for index, item in enumerate(self.get("items")):
for field in ("income_account", "expense_account", "discount_account"):
if doc_before_update.get("items")[index].get(field) != item.get(field):
needs_repost = 1
break

for dimension in accounting_dimensions:
if doc_before_update.get("items")[index].get(dimension) != item.get(dimension):
needs_repost = 1
break

for index, tax in enumerate(self.get("taxes")):
if doc_before_update.get("taxes")[index].get("account_head") != tax.get("account_head"):
needs_repost = 1
break
# Check for child tables
if self.check_if_child_table_updated(
"items",
doc_before_update,
("income_account", "expense_account", "discount_account"),
accounting_dimensions,
):
needs_repost = 1

for dimension in accounting_dimensions:
if doc_before_update.get("taxes")[index].get(dimension) != tax.get(dimension):
needs_repost = 1
break
if self.check_if_child_table_updated(
"taxes", doc_before_update, ("account_head",), accounting_dimensions
):
needs_repost = 1

self.validate_accounts()
self.db_set("repost_required", needs_repost)

def check_if_child_table_updated(
self, child_table, doc_before_update, fields_to_check, accounting_dimensions
):
# Check if any field affecting accounting entry is altered
for index, item in enumerate(self.get(child_table)):
for field in fields_to_check:
if doc_before_update.get(child_table)[index].get(field) != item.get(field):
return True

for dimension in accounting_dimensions:
if doc_before_update.get(child_table)[index].get(dimension) != item.get(dimension):
return True

return False

@frappe.whitelist()
def repost_accounting_entries(self):
self.docstatus = 2
Expand Down

0 comments on commit 42e4c37

Please sign in to comment.