From 0e39e5e86852cad9a995df03a69c68e6828beecf Mon Sep 17 00:00:00 2001 From: ruthra kumar Date: Fri, 28 Apr 2023 14:06:04 +0530 Subject: [PATCH 1/4] refactor: checkbox in purchase invoice (cherry picked from commit b44331c981974cae72175fa10c8d10f0378129b9) --- .../doctype/purchase_invoice/purchase_invoice.json | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.json b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.json index 1c8c4b3193b..719ef7d4c44 100644 --- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.json +++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.json @@ -89,6 +89,7 @@ "column_break8", "grand_total", "rounding_adjustment", + "use_company_roundoff_cost_center", "rounded_total", "in_words", "total_advance", @@ -1559,13 +1560,19 @@ "fieldname": "only_include_allocated_payments", "fieldtype": "Check", "label": "Only Include Allocated Payments" + }, + { + "default": "0", + "fieldname": "use_company_roundoff_cost_center", + "fieldtype": "Check", + "label": "Use Company Default Round Off Cost Center" } ], "icon": "fa fa-file-text", "idx": 204, "is_submittable": 1, "links": [], - "modified": "2023-04-03 22:57:14.074982", + "modified": "2023-04-28 12:57:50.832598", "modified_by": "Administrator", "module": "Accounts", "name": "Purchase Invoice", From 25b37737a2a7cdc8486ed7b663420663e1640cdd Mon Sep 17 00:00:00 2001 From: ruthra kumar Date: Fri, 28 Apr 2023 14:07:28 +0530 Subject: [PATCH 2/4] refactor: checkbox to toggle parent doc cost center preference (cherry picked from commit ebe67875103e4b2aecad8cc5cd20a896cfe5ebd9) --- .../doctype/purchase_invoice/purchase_invoice.py | 12 ++++++++---- erpnext/accounts/general_ledger.py | 6 ++++-- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py index 0ded4a883bb..6d905a37cde 100644 --- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py +++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py @@ -978,7 +978,7 @@ class PurchaseInvoice(BuyingController): def make_precision_loss_gl_entry(self, gl_entries): round_off_account, round_off_cost_center = get_round_off_account_and_cost_center( - self.company, "Purchase Invoice", self.name + self.company, "Purchase Invoice", self.name, self.use_company_roundoff_cost_center ) precision_loss = self.get("base_net_total") - flt( @@ -992,7 +992,9 @@ class PurchaseInvoice(BuyingController): "account": round_off_account, "against": self.supplier, "credit": precision_loss, - "cost_center": self.cost_center or round_off_cost_center, + "cost_center": round_off_cost_center + if self.use_company_roundoff_cost_center + else self.cost_center or round_off_cost_center, "remarks": _("Net total calculation precision loss"), } ) @@ -1386,7 +1388,7 @@ class PurchaseInvoice(BuyingController): not self.is_internal_transfer() and self.rounding_adjustment and self.base_rounding_adjustment ): round_off_account, round_off_cost_center = get_round_off_account_and_cost_center( - self.company, "Purchase Invoice", self.name + self.company, "Purchase Invoice", self.name, self.use_company_roundoff_cost_center ) gl_entries.append( @@ -1396,7 +1398,9 @@ class PurchaseInvoice(BuyingController): "against": self.supplier, "debit_in_account_currency": self.rounding_adjustment, "debit": self.base_rounding_adjustment, - "cost_center": self.cost_center or round_off_cost_center, + "cost_center": round_off_cost_center + if self.use_company_roundoff_cost_center + else (self.cost_center or round_off_cost_center), }, item=self, ) diff --git a/erpnext/accounts/general_ledger.py b/erpnext/accounts/general_ledger.py index 41fdb6a97f8..7beb7cc3b19 100644 --- a/erpnext/accounts/general_ledger.py +++ b/erpnext/accounts/general_ledger.py @@ -472,7 +472,9 @@ def update_accounting_dimensions(round_off_gle): round_off_gle[dimension] = dimension_values.get(dimension) -def get_round_off_account_and_cost_center(company, voucher_type, voucher_no): +def get_round_off_account_and_cost_center( + company, voucher_type, voucher_no, use_company_default=False +): round_off_account, round_off_cost_center = frappe.get_cached_value( "Company", company, ["round_off_account", "round_off_cost_center"] ) or [None, None] @@ -480,7 +482,7 @@ def get_round_off_account_and_cost_center(company, voucher_type, voucher_no): meta = frappe.get_meta(voucher_type) # Give first preference to parent cost center for round off GLE - if meta.has_field("cost_center"): + if not use_company_default and meta.has_field("cost_center"): parent_cost_center = frappe.db.get_value(voucher_type, voucher_no, "cost_center") if parent_cost_center: round_off_cost_center = parent_cost_center From 3810b02023eb8e61509587122d60e574119c3b44 Mon Sep 17 00:00:00 2001 From: ruthra kumar Date: Fri, 28 Apr 2023 14:18:08 +0530 Subject: [PATCH 3/4] refactor: checkbox in Sales Invoice (cherry picked from commit 0f3b06cc8aa36e8f3695d32b3f4a0b915744814b) --- .../accounts/doctype/sales_invoice/sales_invoice.json | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.json b/erpnext/accounts/doctype/sales_invoice/sales_invoice.json index 9a0d71a3850..0e6118abe6b 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.json +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.json @@ -79,6 +79,7 @@ "column_break5", "grand_total", "rounding_adjustment", + "use_company_roundoff_cost_center", "rounded_total", "in_words", "total_advance", @@ -2134,6 +2135,12 @@ "fieldname": "only_include_allocated_payments", "fieldtype": "Check", "label": "Only Include Allocated Payments" + }, + { + "default": "0", + "fieldname": "use_company_roundoff_cost_center", + "fieldtype": "Check", + "label": "Use Company default Cost Center for Round off" } ], "icon": "fa fa-file-text", @@ -2146,7 +2153,7 @@ "link_fieldname": "consolidated_invoice" } ], - "modified": "2023-04-03 22:55:14.206473", + "modified": "2023-04-28 14:15:59.901154", "modified_by": "Administrator", "module": "Accounts", "name": "Sales Invoice", From 8ac718d98cdcc9c4c64cd197b28f23b5220f7306 Mon Sep 17 00:00:00 2001 From: ruthra kumar Date: Fri, 28 Apr 2023 14:20:06 +0530 Subject: [PATCH 4/4] refactor: checkbox to toggle parent doc cost center preference (cherry picked from commit 4ccce933941d9caab29ac1c551f55777b7da8e0b) --- erpnext/accounts/doctype/sales_invoice/sales_invoice.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py index 7af98ddf934..bb85fedab05 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py @@ -1450,7 +1450,7 @@ class SalesInvoice(SellingController): and not self.is_internal_transfer() ): round_off_account, round_off_cost_center = get_round_off_account_and_cost_center( - self.company, "Sales Invoice", self.name + self.company, "Sales Invoice", self.name, self.use_company_roundoff_cost_center ) gl_entries.append( @@ -1462,7 +1462,9 @@ class SalesInvoice(SellingController): self.rounding_adjustment, self.precision("rounding_adjustment") ), "credit": flt(self.base_rounding_adjustment, self.precision("base_rounding_adjustment")), - "cost_center": self.cost_center or round_off_cost_center, + "cost_center": round_off_cost_center + if self.use_company_roundoff_cost_center + else (self.cost_center or round_off_cost_center), }, item=self, )