diff --git a/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py index bae372250ea..70d09ab70ed 100644 --- a/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py +++ b/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py @@ -3055,6 +3055,28 @@ class TestSalesInvoice(FrappeTestCase): check_gl_entries(self, si.name, expected_gle, add_days(nowdate(), -1)) + # cases where distributed discount amount is not set + frappe.db.set_value( + "Sales Invoice Item", + {"name": ["in", [d.name for d in si.items]]}, + "distributed_discount_amount", + 0, + ) + + si.load_from_db() + si.additional_discount_account = additional_discount_account + # Ledger reposted implicitly upon 'Update After Submit' + si.save() + + expected_gle = [ + ["Debtors - _TC", 88, 0.0, nowdate()], + ["Discount Account - _TC", 22.0, 0.0, nowdate()], + ["Service - _TC", 0.0, 100.0, nowdate()], + ["TDS Payable - _TC", 0.0, 10.0, nowdate()], + ] + + check_gl_entries(self, si.name, expected_gle, add_days(nowdate(), -1)) + def test_asset_depreciation_on_sale_with_pro_rata(self): """ Tests if an Asset set to depreciate yearly on June 30, that gets sold on Sept 30, creates an additional depreciation entry on its date of sale. diff --git a/erpnext/controllers/accounts_controller.py b/erpnext/controllers/accounts_controller.py index 33c5783861d..e0e53adeebd 100644 --- a/erpnext/controllers/accounts_controller.py +++ b/erpnext/controllers/accounts_controller.py @@ -1946,6 +1946,15 @@ class AccountsController(TransactionBase): and self.get("discount_amount") and self.get("additional_discount_account") ): + # cases where distributed_discount_amount is not patched + if not hasattr(self, "__has_distributed_discount_set"): + self.__has_distributed_discount_set = any( + i.distributed_discount_amount for i in self.get("items") + ) + + if not self.__has_distributed_discount_set: + return item.amount, item.base_amount + amount += item.distributed_discount_amount base_amount += flt( item.distributed_discount_amount * self.get("conversion_rate"),