fix: handle cases where distributed discount amount is not set

(cherry picked from commit 816b84be02)
This commit is contained in:
ljain112
2025-07-14 14:56:12 +05:30
committed by Mergify
parent 0151733a25
commit 78df52606f
2 changed files with 31 additions and 0 deletions

View File

@@ -3055,6 +3055,28 @@ class TestSalesInvoice(FrappeTestCase):
check_gl_entries(self, si.name, expected_gle, add_days(nowdate(), -1)) 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): 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. 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.

View File

@@ -1946,6 +1946,15 @@ class AccountsController(TransactionBase):
and self.get("discount_amount") and self.get("discount_amount")
and self.get("additional_discount_account") 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 amount += item.distributed_discount_amount
base_amount += flt( base_amount += flt(
item.distributed_discount_amount * self.get("conversion_rate"), item.distributed_discount_amount * self.get("conversion_rate"),