From f977c65e804054a7bbd8b6b3670859821ccd9d1d Mon Sep 17 00:00:00 2001 From: GangaManoj Date: Fri, 13 Aug 2021 17:12:45 +0530 Subject: [PATCH] fix: Make enable_discount_accounting a class property --- .../doctype/purchase_invoice/purchase_invoice.py | 14 +++++++++----- .../doctype/sales_invoice/sales_invoice.py | 13 ++++++++----- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py index a95f971e00..574a353cdf 100644 --- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py +++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py @@ -523,8 +523,6 @@ class PurchaseInvoice(BuyingController): exchange_rate_map, net_rate_map = get_purchase_document_details(self) - enable_discount_accounting = cint(frappe.db.get_single_value('Accounts Settings', 'enable_discount_accounting')) - for item in self.get("items"): if flt(item.base_net_amount): account_currency = get_account_currency(item.expense_account) @@ -615,7 +613,7 @@ class PurchaseInvoice(BuyingController): if (not item.enable_deferred_expense or self.is_return) else item.deferred_expense_account) if not item.is_fixed_asset: - dummy, amount = self.get_amount_and_base_amount(item, enable_discount_accounting) + dummy, amount = self.get_amount_and_base_amount(item, self.enable_discount_accounting) else: amount = flt(item.base_net_amount + item.item_tax_amount, item.precision("base_net_amount")) @@ -857,10 +855,9 @@ class PurchaseInvoice(BuyingController): def make_tax_gl_entries(self, gl_entries): # tax table gl entries valuation_tax = {} - enable_discount_accounting = cint(frappe.db.get_single_value('Accounts Settings', 'enable_discount_accounting')) for tax in self.get("taxes"): - amount, base_amount = self.get_tax_amounts(tax, enable_discount_accounting) + amount, base_amount = self.get_tax_amounts(tax, self.enable_discount_accounting) if tax.category in ("Total", "Valuation and Total") and flt(base_amount): account_currency = get_account_currency(tax.account_head) @@ -925,6 +922,13 @@ class PurchaseInvoice(BuyingController): "remarks": self.remarks or "Accounting Entry for Stock" }, item=tax)) + @property + def enable_discount_accounting(self): + if not hasattr(self, "_enable_discount_accounting"): + self._enable_discount_accounting = cint(frappe.db.get_single_value('Accounts Settings', 'enable_discount_accounting')) + + return self._enable_discount_accounting + def make_internal_transfer_gl_entries(self, gl_entries): if self.is_internal_transfer() and flt(self.base_total_taxes_and_charges): account_currency = get_account_currency(self.unrealized_profit_loss_account) diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py index 1e1fe9001a..0db426ad5e 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py @@ -888,10 +888,8 @@ class SalesInvoice(SellingController): ) def make_tax_gl_entries(self, gl_entries): - enable_discount_accounting = cint(frappe.db.get_single_value('Accounts Settings', 'enable_discount_accounting')) - for tax in self.get("taxes"): - amount, base_amount = self.get_tax_amounts(tax, enable_discount_accounting) + amount, base_amount = self.get_tax_amounts(tax, self.enable_discount_accounting) if flt(tax.base_tax_amount_after_discount_amount): account_currency = get_account_currency(tax.account_head) @@ -922,7 +920,6 @@ class SalesInvoice(SellingController): def make_item_gl_entries(self, gl_entries): # income account gl entries - enable_discount_accounting = cint(frappe.db.get_single_value('Accounts Settings', 'enable_discount_accounting')) for item in self.get("items"): if flt(item.base_net_amount, item.precision("base_net_amount")): @@ -957,7 +954,7 @@ class SalesInvoice(SellingController): income_account = (item.income_account if (not item.enable_deferred_revenue or self.is_return) else item.deferred_revenue_account) - amount, base_amount = self.get_amount_and_base_amount(item, enable_discount_accounting) + amount, base_amount = self.get_amount_and_base_amount(item, self.enable_discount_accounting) account_currency = get_account_currency(income_account) gl_entries.append( @@ -1060,6 +1057,12 @@ class SalesInvoice(SellingController): if orginal_schedule_date == posting_date_of_original_invoice: return True return False + @property + def enable_discount_accounting(self): + if not hasattr(self, "_enable_discount_accounting"): + self._enable_discount_accounting = cint(frappe.db.get_single_value('Accounts Settings', 'enable_discount_accounting')) + + return self._enable_discount_accounting def set_asset_status(self, asset): if self.is_return: