From e626107d3de7f95f15627a266e652cdfedf020a1 Mon Sep 17 00:00:00 2001 From: Deepesh Garg Date: Mon, 17 Oct 2022 16:48:13 +0530 Subject: [PATCH] chore: Update allow on submit for Sales Invoice fields --- .../doctype/sales_invoice/sales_invoice.js | 6 ++---- .../doctype/sales_invoice/sales_invoice.py | 20 ++++++++++++------- .../sales_invoice_item.json | 8 ++++++-- .../sales_taxes_and_charges.json | 7 +++++-- erpnext/public/js/controllers/accounts.js | 6 ++++++ 5 files changed, 32 insertions(+), 15 deletions(-) diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.js b/erpnext/accounts/doctype/sales_invoice/sales_invoice.js index 7a5d3922f3..435ae9e482 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.js +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.js @@ -76,13 +76,11 @@ erpnext.accounts.SalesInvoiceController = class SalesInvoiceController extends e callback: (r) => { if (!r.exc) { frappe.msgprint(__('Accounting Entries are reposted')); - this.frm.trigger('refresh'); + me.frm.refresh(); } } }); - }); - - $(`["${encodeURIComponent("Repost Accounting Entries")}"]`).css('color', 'red'); + }).removeClass('btn-default').addClass('btn-warning'); } if (this.frm.doc.is_return) { diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py index 4c38883913..891ae1c4b2 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py @@ -522,9 +522,10 @@ class SalesInvoice(SellingController): def on_update_after_submit(self): needs_repost = 0 + # Check if any field affecting accounting entry is altered doc_before_update = self.get_doc_before_save() - accounting_dimensions = get_accounting_dimensions() + accounting_dimensions = get_accounting_dimensions() + ["cost_center", "project"] # Check if opening entry check updated if doc_before_update.get("is_opening") != self.is_opening: @@ -552,12 +553,7 @@ class SalesInvoice(SellingController): # Check for parent level for index, item in enumerate(self.get("items")): - for field in ( - "income_account", - "expense_account", - "discount_account", - "deferred_revenue_account", - ): + 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 @@ -567,6 +563,16 @@ class SalesInvoice(SellingController): 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 + + for dimension in accounting_dimensions: + if doc_before_update.get("taxes")[index].get(dimension) != tax.get(dimension): + needs_repost = 1 + break + self.validate_accounts() self.db_set("repost_required", needs_repost) diff --git a/erpnext/accounts/doctype/sales_invoice_item/sales_invoice_item.json b/erpnext/accounts/doctype/sales_invoice_item/sales_invoice_item.json index a307a6c17c..342a3cc98b 100644 --- a/erpnext/accounts/doctype/sales_invoice_item/sales_invoice_item.json +++ b/erpnext/accounts/doctype/sales_invoice_item/sales_invoice_item.json @@ -436,6 +436,7 @@ "label": "Accounting Details" }, { + "allow_on_submit": 1, "fieldname": "income_account", "fieldtype": "Link", "label": "Income Account", @@ -448,6 +449,7 @@ "width": "120px" }, { + "allow_on_submit": 1, "fieldname": "expense_account", "fieldtype": "Link", "label": "Expense Account", @@ -467,6 +469,7 @@ "print_hide": 1 }, { + "allow_on_submit": 1, "default": ":Company", "fieldname": "cost_center", "fieldtype": "Link", @@ -798,6 +801,7 @@ "options": "Finance Book" }, { + "allow_on_submit": 1, "fieldname": "project", "fieldtype": "Link", "label": "Project", @@ -820,7 +824,6 @@ "label": "Incoming Rate (Costing)", "no_copy": 1, "options": "Company:company:default_currency", - "precision": "6", "print_hide": 1 }, { @@ -833,6 +836,7 @@ "read_only": 1 }, { + "allow_on_submit": 1, "fieldname": "discount_account", "fieldtype": "Link", "label": "Discount Account", @@ -876,7 +880,7 @@ "idx": 1, "istable": 1, "links": [], - "modified": "2022-10-10 20:57:38.340026", + "modified": "2022-10-17 12:51:44.825398", "modified_by": "Administrator", "module": "Accounts", "name": "Sales Invoice Item", diff --git a/erpnext/accounts/doctype/sales_taxes_and_charges/sales_taxes_and_charges.json b/erpnext/accounts/doctype/sales_taxes_and_charges/sales_taxes_and_charges.json index 3a871bfced..e236577e11 100644 --- a/erpnext/accounts/doctype/sales_taxes_and_charges/sales_taxes_and_charges.json +++ b/erpnext/accounts/doctype/sales_taxes_and_charges/sales_taxes_and_charges.json @@ -51,6 +51,7 @@ "oldfieldtype": "Data" }, { + "allow_on_submit": 1, "columns": 2, "fieldname": "account_head", "fieldtype": "Link", @@ -63,6 +64,7 @@ "search_index": 1 }, { + "allow_on_submit": 1, "default": ":Company", "fieldname": "cost_center", "fieldtype": "Link", @@ -216,12 +218,13 @@ "index_web_pages_for_search": 1, "istable": 1, "links": [], - "modified": "2021-08-05 20:04:01.726867", + "modified": "2022-10-17 13:08:17.776528", "modified_by": "Administrator", "module": "Accounts", "name": "Sales Taxes and Charges", "owner": "Administrator", "permissions": [], "sort_field": "modified", - "sort_order": "ASC" + "sort_order": "ASC", + "states": [] } \ No newline at end of file diff --git a/erpnext/public/js/controllers/accounts.js b/erpnext/public/js/controllers/accounts.js index c1fe72bb48..a07f75d1c5 100644 --- a/erpnext/public/js/controllers/accounts.js +++ b/erpnext/public/js/controllers/accounts.js @@ -143,6 +143,12 @@ var get_payment_mode_account = function(frm, mode_of_payment, callback) { cur_frm.cscript.account_head = function(doc, cdt, cdn) { var d = locals[cdt][cdn]; + + if (doc.docstatus == 1) { + // Should not trigger any changes on change post submit + return; + } + if(!d.charge_type && d.account_head){ frappe.msgprint(__("Please select Charge Type first")); frappe.model.set_value(cdt, cdn, "account_head", "");