diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py index 71a0da59520..65d753776d1 100644 --- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py +++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py @@ -1709,6 +1709,9 @@ class PurchaseInvoice(BuyingController): self.db_set("release_date", None) def set_tax_withholding(self): + self.set("advance_tax", []) + self.set("tax_withheld_vouchers", []) + if not self.apply_tds: return @@ -1750,8 +1753,6 @@ class PurchaseInvoice(BuyingController): self.remove(d) ## Add pending vouchers on which tax was withheld - self.set("tax_withheld_vouchers", []) - for voucher_no, voucher_details in voucher_wise_amount.items(): self.append( "tax_withheld_vouchers", @@ -1766,7 +1767,6 @@ class PurchaseInvoice(BuyingController): self.calculate_taxes_and_totals() def allocate_advance_tds(self, tax_withholding_details, advance_taxes): - self.set("advance_tax", []) for tax in advance_taxes: allocated_amount = 0 pending_amount = flt(tax.tax_amount - tax.allocated_amount) 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 1549b45d004..95381eaa1f7 100644 --- a/erpnext/accounts/doctype/tax_withholding_category/tax_withholding_category.py +++ b/erpnext/accounts/doctype/tax_withholding_category/tax_withholding_category.py @@ -268,6 +268,11 @@ def get_tax_amount(party_type, parties, inv, tax_details, posting_date, pan_no=N vouchers, voucher_wise_amount = get_invoice_vouchers( parties, tax_details, inv.company, party_type=party_type ) + + payment_entry_vouchers = get_payment_entry_vouchers( + parties, tax_details, inv.company, party_type=party_type + ) + advance_vouchers = get_advance_vouchers( parties, company=inv.company, @@ -275,7 +280,8 @@ def get_tax_amount(party_type, parties, inv, tax_details, posting_date, pan_no=N to_date=tax_details.to_date, party_type=party_type, ) - taxable_vouchers = vouchers + advance_vouchers + + taxable_vouchers = vouchers + advance_vouchers + payment_entry_vouchers tax_deducted_on_advances = 0 if inv.doctype == "Purchase Invoice": @@ -387,6 +393,20 @@ def get_invoice_vouchers(parties, tax_details, company, party_type="Supplier"): return vouchers, voucher_wise_amount +def get_payment_entry_vouchers(parties, tax_details, company, party_type="Supplier"): + payment_entry_filters = { + "party_type": party_type, + "party": ("in", parties), + "docstatus": 1, + "apply_tax_withholding_amount": 1, + "posting_date": ["between", (tax_details.from_date, tax_details.to_date)], + "tax_withholding_category": tax_details.get("tax_withholding_category"), + "company": company, + } + + return frappe.db.get_all("Payment Entry", filters=payment_entry_filters, pluck="name") + + def get_advance_vouchers(parties, company=None, from_date=None, to_date=None, party_type="Supplier"): """ Use Payment Ledger to fetch unallocated Advance Payments