From 3ead28906cb849d50b53e2402704121acdfb5b9d Mon Sep 17 00:00:00 2001 From: Dany Robert Date: Tue, 22 Aug 2023 14:41:07 +0000 Subject: [PATCH 1/6] feat: item(row) wise tax amount rounding --- .../doctype/accounts_settings/accounts_settings.json | 10 +++++----- .../accounts/doctype/payment_entry/payment_entry.py | 5 +++++ erpnext/controllers/taxes_and_totals.py | 5 +++++ 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/erpnext/accounts/doctype/accounts_settings/accounts_settings.json b/erpnext/accounts/doctype/accounts_settings/accounts_settings.json index 6857ba343e..570be095ab 100644 --- a/erpnext/accounts/doctype/accounts_settings/accounts_settings.json +++ b/erpnext/accounts/doctype/accounts_settings/accounts_settings.json @@ -32,6 +32,7 @@ "column_break_19", "add_taxes_from_item_tax_template", "book_tax_discount_loss", + "round_row_wise_tax", "print_settings", "show_inclusive_tax_in_print", "show_taxes_as_table_in_print", @@ -58,7 +59,6 @@ "closing_settings_tab", "period_closing_settings_section", "acc_frozen_upto", - "ignore_account_closing_balance", "column_break_25", "frozen_accounts_modifier", "tab_break_dpet", @@ -410,10 +410,10 @@ }, { "default": "0", - "description": "Financial reports will be generated using GL Entry doctypes (should be enabled if Period Closing Voucher is not posted for all years sequentially or missing) ", - "fieldname": "ignore_account_closing_balance", + "description": "Tax Amount will be rounded on a row(items) level", + "fieldname": "round_row_wise_tax", "fieldtype": "Check", - "label": "Ignore Account Closing Balance" + "label": "Round Tax Amount Row-wise" } ], "icon": "icon-cog", @@ -421,7 +421,7 @@ "index_web_pages_for_search": 1, "issingle": 1, "links": [], - "modified": "2023-07-27 15:05:34.000264", + "modified": "2023-08-22 20:11:00.042840", "modified_by": "Administrator", "module": "Accounts", "name": "Accounts Settings", diff --git a/erpnext/accounts/doctype/payment_entry/payment_entry.py b/erpnext/accounts/doctype/payment_entry/payment_entry.py index ac31e8a1db..39ee497fda 100644 --- a/erpnext/accounts/doctype/payment_entry/payment_entry.py +++ b/erpnext/accounts/doctype/payment_entry/payment_entry.py @@ -1387,6 +1387,9 @@ class PaymentEntry(AccountsController): def calculate_taxes(self): self.total_taxes_and_charges = 0.0 self.base_total_taxes_and_charges = 0.0 + frappe.flags.round_row_wise_tax = ( + frappe.db.get_single_value("Accounts Settings", "round_row_wise_tax") + ) actual_tax_dict = dict( [ @@ -1398,6 +1401,8 @@ class PaymentEntry(AccountsController): for i, tax in enumerate(self.get("taxes")): current_tax_amount = self.get_current_tax_amount(tax) + if frappe.flags.round_row_wise_tax: + current_tax_amount = flt(current_tax_amount, tax.precision("tax_amount")) if tax.charge_type == "Actual": actual_tax_dict[tax.idx] -= current_tax_amount diff --git a/erpnext/controllers/taxes_and_totals.py b/erpnext/controllers/taxes_and_totals.py index 62d4c53868..1cf1788f43 100644 --- a/erpnext/controllers/taxes_and_totals.py +++ b/erpnext/controllers/taxes_and_totals.py @@ -25,6 +25,9 @@ class calculate_taxes_and_totals(object): def __init__(self, doc: Document): self.doc = doc frappe.flags.round_off_applicable_accounts = [] + frappe.flags.round_row_wise_tax = ( + frappe.db.get_single_value("Accounts Settings", "round_row_wise_tax") + ) self._items = self.filter_rows() if self.doc.doctype == "Quotation" else self.doc.get("items") @@ -368,6 +371,8 @@ class calculate_taxes_and_totals(object): for i, tax in enumerate(self.doc.get("taxes")): # tax_amount represents the amount of tax for the current step current_tax_amount = self.get_current_tax_amount(item, tax, item_tax_map) + if frappe.flags.round_row_wise_tax: + current_tax_amount = flt(current_tax_amount, tax.precision("tax_amount")) # Adjust divisional loss to the last item if tax.charge_type == "Actual": From c20258d2a355388b799b6e9eca710d9254cd0388 Mon Sep 17 00:00:00 2001 From: Dany Robert Date: Wed, 23 Aug 2023 03:59:08 +0000 Subject: [PATCH 2/6] fix: tax calc changes in js --- .../accounts/doctype/payment_entry/payment_entry.py | 5 ----- erpnext/public/js/controllers/taxes_and_totals.js | 10 +++++++++- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/erpnext/accounts/doctype/payment_entry/payment_entry.py b/erpnext/accounts/doctype/payment_entry/payment_entry.py index 39ee497fda..ac31e8a1db 100644 --- a/erpnext/accounts/doctype/payment_entry/payment_entry.py +++ b/erpnext/accounts/doctype/payment_entry/payment_entry.py @@ -1387,9 +1387,6 @@ class PaymentEntry(AccountsController): def calculate_taxes(self): self.total_taxes_and_charges = 0.0 self.base_total_taxes_and_charges = 0.0 - frappe.flags.round_row_wise_tax = ( - frappe.db.get_single_value("Accounts Settings", "round_row_wise_tax") - ) actual_tax_dict = dict( [ @@ -1401,8 +1398,6 @@ class PaymentEntry(AccountsController): for i, tax in enumerate(self.get("taxes")): current_tax_amount = self.get_current_tax_amount(tax) - if frappe.flags.round_row_wise_tax: - current_tax_amount = flt(current_tax_amount, tax.precision("tax_amount")) if tax.charge_type == "Actual": actual_tax_dict[tax.idx] -= current_tax_amount diff --git a/erpnext/public/js/controllers/taxes_and_totals.js b/erpnext/public/js/controllers/taxes_and_totals.js index eeb09cb8b0..8062ce05cd 100644 --- a/erpnext/public/js/controllers/taxes_and_totals.js +++ b/erpnext/public/js/controllers/taxes_and_totals.js @@ -185,7 +185,7 @@ erpnext.taxes_and_totals = class TaxesAndTotals extends erpnext.payments { frappe.flags.round_off_applicable_accounts = []; if (me.frm.doc.company) { - return frappe.call({ + frappe.call({ "method": "erpnext.controllers.taxes_and_totals.get_round_off_applicable_accounts", "args": { "company": me.frm.doc.company, @@ -198,6 +198,11 @@ erpnext.taxes_and_totals = class TaxesAndTotals extends erpnext.payments { } }); } + + frappe.db.get_single_value("Accounts Settings", "round_row_wise_tax") + .then((round_row_wise_tax) => { + frappe.flags.round_row_wise_tax = round_row_wise_tax; + }) } determine_exclusive_rate() { @@ -338,6 +343,9 @@ erpnext.taxes_and_totals = class TaxesAndTotals extends erpnext.payments { $.each(me.frm.doc["taxes"] || [], function(i, tax) { // tax_amount represents the amount of tax for the current step var current_tax_amount = me.get_current_tax_amount(item, tax, item_tax_map); + if (frappe.flags.round_row_wise_tax) { + current_tax_amount = flt(current_tax_amount, precision("tax_amount", tax)); + } // Adjust divisional loss to the last item if (tax.charge_type == "Actual") { From dfb5b88abbd3d00f625f18afeb3e0e57d1fcade6 Mon Sep 17 00:00:00 2001 From: Dany Robert Date: Wed, 23 Aug 2023 04:01:00 +0000 Subject: [PATCH 3/6] chore: linters --- erpnext/controllers/taxes_and_totals.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/erpnext/controllers/taxes_and_totals.py b/erpnext/controllers/taxes_and_totals.py index 1cf1788f43..243b5eb96e 100644 --- a/erpnext/controllers/taxes_and_totals.py +++ b/erpnext/controllers/taxes_and_totals.py @@ -25,8 +25,8 @@ class calculate_taxes_and_totals(object): def __init__(self, doc: Document): self.doc = doc frappe.flags.round_off_applicable_accounts = [] - frappe.flags.round_row_wise_tax = ( - frappe.db.get_single_value("Accounts Settings", "round_row_wise_tax") + frappe.flags.round_row_wise_tax = frappe.db.get_single_value( + "Accounts Settings", "round_row_wise_tax" ) self._items = self.filter_rows() if self.doc.doctype == "Quotation" else self.doc.get("items") From 0ebcc2cf2c7c3a7c764bdf378822e542ade73253 Mon Sep 17 00:00:00 2001 From: Dany Robert Date: Wed, 23 Aug 2023 04:51:09 +0000 Subject: [PATCH 4/6] fix: round item_wise_tax_detail in taxes --- erpnext/controllers/taxes_and_totals.py | 9 +++++++-- erpnext/public/js/controllers/taxes_and_totals.js | 11 +++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/erpnext/controllers/taxes_and_totals.py b/erpnext/controllers/taxes_and_totals.py index 243b5eb96e..39d2cf632a 100644 --- a/erpnext/controllers/taxes_and_totals.py +++ b/erpnext/controllers/taxes_and_totals.py @@ -483,8 +483,13 @@ class calculate_taxes_and_totals(object): # store tax breakup for each item key = item.item_code or item.item_name item_wise_tax_amount = current_tax_amount * self.doc.conversion_rate - if tax.item_wise_tax_detail.get(key): - item_wise_tax_amount += tax.item_wise_tax_detail[key][1] + if frappe.flags.round_row_wise_tax: + item_wise_tax_amount = flt(item_wise_tax_amount, tax.precision("tax_amount")) + if tax.item_wise_tax_detail.get(key): + item_wise_tax_amount += flt(tax.item_wise_tax_detail[key][1], tax.precision("tax_amount")) + else: + if tax.item_wise_tax_detail.get(key): + item_wise_tax_amount += tax.item_wise_tax_detail[key][1] tax.item_wise_tax_detail[key] = [tax_rate, flt(item_wise_tax_amount)] diff --git a/erpnext/public/js/controllers/taxes_and_totals.js b/erpnext/public/js/controllers/taxes_and_totals.js index 8062ce05cd..81dcc06471 100644 --- a/erpnext/public/js/controllers/taxes_and_totals.js +++ b/erpnext/public/js/controllers/taxes_and_totals.js @@ -480,8 +480,15 @@ erpnext.taxes_and_totals = class TaxesAndTotals extends erpnext.payments { } let item_wise_tax_amount = current_tax_amount * this.frm.doc.conversion_rate; - if (tax_detail && tax_detail[key]) - item_wise_tax_amount += tax_detail[key][1]; + if (frappe.flags.round_row_wise_tax) { + item_wise_tax_amount = flt(item_wise_tax_amount, precision("tax_amount", tax)); + if (tax_detail && tax_detail[key]) { + item_wise_tax_amount += flt(tax_detail[key][1], precision("tax_amount", tax)); + } + } else { + if (tax_detail && tax_detail[key]) + item_wise_tax_amount += tax_detail[key][1]; + } tax_detail[key] = [tax_rate, flt(item_wise_tax_amount, precision("base_tax_amount", tax))]; } From 9e1b2c9f5799ca5b84bf63f34b64a72d15b99097 Mon Sep 17 00:00:00 2001 From: Dany Robert Date: Thu, 24 Aug 2023 05:02:14 +0000 Subject: [PATCH 5/6] fix: item wise split up rounding --- erpnext/controllers/taxes_and_totals.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/erpnext/controllers/taxes_and_totals.py b/erpnext/controllers/taxes_and_totals.py index 39d2cf632a..c1dc316c54 100644 --- a/erpnext/controllers/taxes_and_totals.py +++ b/erpnext/controllers/taxes_and_totals.py @@ -487,11 +487,15 @@ class calculate_taxes_and_totals(object): item_wise_tax_amount = flt(item_wise_tax_amount, tax.precision("tax_amount")) if tax.item_wise_tax_detail.get(key): item_wise_tax_amount += flt(tax.item_wise_tax_detail[key][1], tax.precision("tax_amount")) + tax.item_wise_tax_detail[key] = [ + tax_rate, + flt(item_wise_tax_amount, tax.precision("tax_amount")), + ] else: if tax.item_wise_tax_detail.get(key): item_wise_tax_amount += tax.item_wise_tax_detail[key][1] - tax.item_wise_tax_detail[key] = [tax_rate, flt(item_wise_tax_amount)] + tax.item_wise_tax_detail[key] = [tax_rate, flt(item_wise_tax_amount)] def round_off_totals(self, tax): if tax.account_head in frappe.flags.round_off_applicable_accounts: From 159be1d40fbc07b619c27f782d872bf2d1f35a3a Mon Sep 17 00:00:00 2001 From: Dany Robert Date: Sun, 27 Aug 2023 18:43:42 +0000 Subject: [PATCH 6/6] fix: revert `ignore_account_closing_balance` field --- .../doctype/accounts_settings/accounts_settings.json | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/erpnext/accounts/doctype/accounts_settings/accounts_settings.json b/erpnext/accounts/doctype/accounts_settings/accounts_settings.json index 570be095ab..061bab320e 100644 --- a/erpnext/accounts/doctype/accounts_settings/accounts_settings.json +++ b/erpnext/accounts/doctype/accounts_settings/accounts_settings.json @@ -59,6 +59,7 @@ "closing_settings_tab", "period_closing_settings_section", "acc_frozen_upto", + "ignore_account_closing_balance", "column_break_25", "frozen_accounts_modifier", "tab_break_dpet", @@ -408,6 +409,13 @@ "fieldtype": "Check", "label": "Enable Fuzzy Matching" }, + { + "default": "0", + "description": "Financial reports will be generated using GL Entry doctypes (should be enabled if Period Closing Voucher is not posted for all years sequentially or missing) ", + "fieldname": "ignore_account_closing_balance", + "fieldtype": "Check", + "label": "Ignore Account Closing Balance" + }, { "default": "0", "description": "Tax Amount will be rounded on a row(items) level", @@ -421,7 +429,7 @@ "index_web_pages_for_search": 1, "issingle": 1, "links": [], - "modified": "2023-08-22 20:11:00.042840", + "modified": "2023-08-28 00:12:02.740633", "modified_by": "Administrator", "module": "Accounts", "name": "Accounts Settings",