From 6f59fa9e5bc4246cd4f1039f82da5577a26d4cfa Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Wed, 14 Jun 2023 09:01:04 +0530 Subject: [PATCH] fix: Lower deduction certificate not getting applied (#35667) * fix: Lower deduction certificate not getting applied (#35667) (cherry picked from commit 937c0feefe302d0a63fca2bee84da1580f7b6e26) # Conflicts: # erpnext/accounts/doctype/tax_withholding_category/tax_withholding_category.py * chore: resolve conflicts --------- Co-authored-by: Deepesh Garg --- .../tax_withholding_category.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/erpnext/accounts/doctype/tax_withholding_category/tax_withholding_category.py b/erpnext/accounts/doctype/tax_withholding_category/tax_withholding_category.py index 1f2d9803739..d8827e09662 100644 --- a/erpnext/accounts/doctype/tax_withholding_category/tax_withholding_category.py +++ b/erpnext/accounts/doctype/tax_withholding_category/tax_withholding_category.py @@ -5,7 +5,7 @@ import frappe from frappe import _ from frappe.model.document import Document -from frappe.utils import cint, getdate +from frappe.utils import cint, flt, getdate class TaxWithholdingCategory(Document): @@ -569,7 +569,12 @@ def get_tds_amount_from_ldc(ldc, parties, tax_details, posting_date, net_total): tds_amount = 0 limit_consumed = frappe.db.get_value( "Purchase Invoice", - {"supplier": ("in", parties), "apply_tds": 1, "docstatus": 1}, + { + "supplier": ("in", parties), + "apply_tds": 1, + "docstatus": 1, + "posting_date": ("between", (ldc.valid_from, ldc.valid_upto)), + }, "sum(tax_withholding_net_total)", ) @@ -584,10 +589,10 @@ def get_tds_amount_from_ldc(ldc, parties, tax_details, posting_date, net_total): def get_ltds_amount(current_amount, deducted_amount, certificate_limit, rate, tax_details): - if current_amount < (certificate_limit - deducted_amount): + if certificate_limit - flt(deducted_amount) - flt(current_amount) >= 0: return current_amount * rate / 100 else: - ltds_amount = certificate_limit - deducted_amount + ltds_amount = certificate_limit - flt(deducted_amount) tds_amount = current_amount - ltds_amount return ltds_amount * rate / 100 + tds_amount * tax_details.rate / 100 @@ -598,9 +603,9 @@ def is_valid_certificate( ): valid = False - if ( - getdate(valid_from) <= getdate(posting_date) <= getdate(valid_upto) - ) and certificate_limit > deducted_amount: + available_amount = flt(certificate_limit) - flt(deducted_amount) - flt(current_amount) + + if (getdate(valid_from) <= getdate(posting_date) <= getdate(valid_upto)) and available_amount > 0: valid = True return valid