From 0ded6b664de27c1eb066b6ded26d4bc60a62cf04 Mon Sep 17 00:00:00 2001 From: ljain112 Date: Tue, 2 Jul 2024 19:07:31 +0530 Subject: [PATCH 1/2] fix: updated logic for calculating tax_withholding_net_total in payment entry --- .../doctype/payment_entry/payment_entry.py | 39 ++++++++++++++----- 1 file changed, 29 insertions(+), 10 deletions(-) diff --git a/erpnext/accounts/doctype/payment_entry/payment_entry.py b/erpnext/accounts/doctype/payment_entry/payment_entry.py index bbeb1aeb18..fad208605c 100644 --- a/erpnext/accounts/doctype/payment_entry/payment_entry.py +++ b/erpnext/accounts/doctype/payment_entry/payment_entry.py @@ -165,7 +165,6 @@ class PaymentEntry(AccountsController): self.set_exchange_rate() self.validate_mandatory() self.validate_reference_documents() - self.set_tax_withholding() self.set_amounts() self.validate_amounts() self.apply_taxes() @@ -179,7 +178,7 @@ class PaymentEntry(AccountsController): self.validate_allocated_amount() self.validate_paid_invoices() self.ensure_supplier_is_not_blocked() - self.update_unreconciled_amount() + self.set_tax_withholding() self.set_status() self.set_total_in_words() self.set_accounting_journal() # @dokos @@ -879,9 +878,7 @@ class PaymentEntry(AccountsController): if not self.apply_tax_withholding_amount: return - order_amount = self.get_order_net_total() - - net_total = flt(order_amount) + flt(self.unallocated_amount) + net_total = self.calculate_tax_withholding_net_total() # Adding args as purchase invoice to get TDS amount args = frappe._dict( @@ -925,7 +922,26 @@ class PaymentEntry(AccountsController): for d in to_remove: self.remove(d) - def get_order_net_total(self): + def calculate_tax_withholding_net_total(self): + net_total = 0 + order_details = self.get_order_wise_tax_withholding_net_total() + + for d in self.references: + tax_withholding_net_total = order_details.get(d.reference_name) + if not tax_withholding_net_total: + continue + + net_taxable_outstanding = max( + 0, d.outstanding_amount - (d.total_amount - tax_withholding_net_total) + ) + + net_total += min(net_taxable_outstanding, d.allocated_amount) + + net_total += self.unallocated_amount + + return net_total + + def get_order_wise_tax_withholding_net_total(self): if self.party_type == "Supplier": doctype = "Purchase Order" else: @@ -933,12 +949,15 @@ class PaymentEntry(AccountsController): docnames = [d.reference_name for d in self.references if d.reference_doctype == doctype] - tax_withholding_net_total = frappe.db.get_value( - doctype, {"name": ["in", docnames]}, ["sum(base_tax_withholding_net_total)"] + return frappe._dict( + frappe.db.get_all( + doctype, + filters={"name": ["in", docnames]}, + fields=["name", "base_tax_withholding_net_total"], + as_list=True, + ) ) - return tax_withholding_net_total - def apply_taxes(self): self.initialize_taxes() self.determine_exclusive_rate() -- GitLab From 3cb9be5f7b458cd1f3bb284a7ca6cf36195b7660 Mon Sep 17 00:00:00 2001 From: Charles-Henri Decultot Date: Thu, 11 Jul 2024 10:28:33 +0200 Subject: [PATCH 2/2] fix: merge conflict --- erpnext/accounts/doctype/payment_entry/payment_entry.py | 1 + 1 file changed, 1 insertion(+) diff --git a/erpnext/accounts/doctype/payment_entry/payment_entry.py b/erpnext/accounts/doctype/payment_entry/payment_entry.py index fad208605c..1422912f39 100644 --- a/erpnext/accounts/doctype/payment_entry/payment_entry.py +++ b/erpnext/accounts/doctype/payment_entry/payment_entry.py @@ -179,6 +179,7 @@ class PaymentEntry(AccountsController): self.validate_paid_invoices() self.ensure_supplier_is_not_blocked() self.set_tax_withholding() + self.update_unreconciled_amount() # @dokos self.set_status() self.set_total_in_words() self.set_accounting_journal() # @dokos -- GitLab