Merge pull request #42261 from frappe/mergify/bp/version-14-hotfix/pr-42060
fix: updated logic for calculating tax_withholding_net_total in payment entry (backport #42060)
This commit is contained in:
@@ -74,7 +74,6 @@ class PaymentEntry(AccountsController):
|
|||||||
self.set_exchange_rate()
|
self.set_exchange_rate()
|
||||||
self.validate_mandatory()
|
self.validate_mandatory()
|
||||||
self.validate_reference_documents()
|
self.validate_reference_documents()
|
||||||
self.set_tax_withholding()
|
|
||||||
self.set_amounts()
|
self.set_amounts()
|
||||||
self.validate_amounts()
|
self.validate_amounts()
|
||||||
self.apply_taxes()
|
self.apply_taxes()
|
||||||
@@ -89,6 +88,7 @@ class PaymentEntry(AccountsController):
|
|||||||
self.validate_allocated_amount()
|
self.validate_allocated_amount()
|
||||||
self.validate_paid_invoices()
|
self.validate_paid_invoices()
|
||||||
self.ensure_supplier_is_not_blocked()
|
self.ensure_supplier_is_not_blocked()
|
||||||
|
self.set_tax_withholding()
|
||||||
self.set_status()
|
self.set_status()
|
||||||
|
|
||||||
def on_submit(self):
|
def on_submit(self):
|
||||||
@@ -674,9 +674,7 @@ class PaymentEntry(AccountsController):
|
|||||||
if not self.apply_tax_withholding_amount:
|
if not self.apply_tax_withholding_amount:
|
||||||
return
|
return
|
||||||
|
|
||||||
order_amount = self.get_order_net_total()
|
net_total = self.calculate_tax_withholding_net_total()
|
||||||
|
|
||||||
net_total = flt(order_amount) + flt(self.unallocated_amount)
|
|
||||||
|
|
||||||
# Adding args as purchase invoice to get TDS amount
|
# Adding args as purchase invoice to get TDS amount
|
||||||
args = frappe._dict(
|
args = frappe._dict(
|
||||||
@@ -720,7 +718,26 @@ class PaymentEntry(AccountsController):
|
|||||||
for d in to_remove:
|
for d in to_remove:
|
||||||
self.remove(d)
|
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":
|
if self.party_type == "Supplier":
|
||||||
doctype = "Purchase Order"
|
doctype = "Purchase Order"
|
||||||
else:
|
else:
|
||||||
@@ -728,12 +745,15 @@ class PaymentEntry(AccountsController):
|
|||||||
|
|
||||||
docnames = [d.reference_name for d in self.references if d.reference_doctype == doctype]
|
docnames = [d.reference_name for d in self.references if d.reference_doctype == doctype]
|
||||||
|
|
||||||
tax_withholding_net_total = frappe.db.get_value(
|
return frappe._dict(
|
||||||
doctype, {"name": ["in", docnames]}, ["sum(base_tax_withholding_net_total)"]
|
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):
|
def apply_taxes(self):
|
||||||
self.initialize_taxes()
|
self.initialize_taxes()
|
||||||
self.determine_exclusive_rate()
|
self.determine_exclusive_rate()
|
||||||
|
|||||||
Reference in New Issue
Block a user