From 397e3b1ade6a52d542b27ac3a02165acf8797f41 Mon Sep 17 00:00:00 2001 From: niralisatapara Date: Tue, 25 Oct 2022 15:09:59 +0530 Subject: [PATCH] feat: item wise tds calculation item wise tds calculation --- .../purchase_invoice_item.json | 7 ++++++ .../tax_withholding_category.py | 12 +++++----- erpnext/controllers/taxes_and_totals.py | 1 + erpnext/patches/v14_0/update_tds_fields.py | 23 ++++++++++++------- 4 files changed, 29 insertions(+), 14 deletions(-) diff --git a/erpnext/accounts/doctype/purchase_invoice_item/purchase_invoice_item.json b/erpnext/accounts/doctype/purchase_invoice_item/purchase_invoice_item.json index 9de90368871..0a39a62ef12 100644 --- a/erpnext/accounts/doctype/purchase_invoice_item/purchase_invoice_item.json +++ b/erpnext/accounts/doctype/purchase_invoice_item/purchase_invoice_item.json @@ -40,6 +40,7 @@ "discount_amount", "base_rate_with_margin", "sec_break2", + "apply_tds", "rate", "amount", "item_tax_template", @@ -866,6 +867,12 @@ "label": "Product Bundle", "options": "Product Bundle", "read_only": 1 + }, + { + "default": "1", + "fieldname": "apply_tds", + "fieldtype": "Check", + "label": "Apply TDS" } ], "idx": 1, 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 280cc24e2ce..b4f46cca307 100644 --- a/erpnext/accounts/doctype/tax_withholding_category/tax_withholding_category.py +++ b/erpnext/accounts/doctype/tax_withholding_category/tax_withholding_category.py @@ -245,7 +245,7 @@ def get_tax_amount(party_type, parties, inv, tax_details, posting_date, pan_no=N if party_type == "Supplier": ldc = get_lower_deduction_certificate(tax_details, pan_no) if tax_deducted: - net_total = inv.net_total + net_total = inv.tax_withholding_net_total if ldc: tax_amount = get_tds_amount_from_ldc( ldc, parties, pan_no, tax_details, posting_date, net_total @@ -395,7 +395,7 @@ def get_tds_amount(ldc, parties, inv, tax_details, tax_deducted, vouchers): tds_amount = 0 invoice_filters = {"name": ("in", vouchers), "docstatus": 1, "apply_tds": 1} - field = "sum(net_total)" + field = "sum(tax_withholding_net_total)" if cint(tax_details.consider_party_ledger_amount): invoice_filters.pop("apply_tds", None) @@ -418,12 +418,12 @@ def get_tds_amount(ldc, parties, inv, tax_details, tax_deducted, vouchers): ) supp_credit_amt += supp_jv_credit_amt - supp_credit_amt += inv.net_total + supp_credit_amt += inv.tax_withholding_net_total threshold = tax_details.get("threshold", 0) cumulative_threshold = tax_details.get("cumulative_threshold", 0) - if (threshold and inv.net_total >= threshold) or ( + if (threshold and inv.tax_withholding_net_total >= threshold) or ( cumulative_threshold and supp_credit_amt >= cumulative_threshold ): if (cumulative_threshold and supp_credit_amt >= cumulative_threshold) and cint( @@ -443,7 +443,7 @@ def get_tds_amount(ldc, parties, inv, tax_details, tax_deducted, vouchers): ldc.valid_upto, inv.get("posting_date") or inv.get("transaction_date"), tax_deducted, - inv.net_total, + inv.tax_withholding_net_total, ldc.certificate_limit, ): tds_amount = get_ltds_amount(supp_credit_amt, 0, ldc.certificate_limit, ldc.rate, tax_details) @@ -526,7 +526,7 @@ def get_tds_amount_from_ldc(ldc, parties, pan_no, tax_details, posting_date, net limit_consumed = frappe.db.get_value( "Purchase Invoice", {"supplier": ("in", parties), "apply_tds": 1, "docstatus": 1}, - "sum(net_total)", + "sum(tax_withholding_net_total)", ) if is_valid_certificate( diff --git a/erpnext/controllers/taxes_and_totals.py b/erpnext/controllers/taxes_and_totals.py index ee19adc425f..42da4cf1818 100644 --- a/erpnext/controllers/taxes_and_totals.py +++ b/erpnext/controllers/taxes_and_totals.py @@ -58,6 +58,7 @@ class calculate_taxes_and_totals(object): self.initialize_taxes() self.determine_exclusive_rate() self.calculate_net_total() + self.calculate_tax_withholding_net_total() self.calculate_taxes() self.manipulate_grand_total_for_inclusive_tax() self.calculate_totals() diff --git a/erpnext/patches/v14_0/update_tds_fields.py b/erpnext/patches/v14_0/update_tds_fields.py index a8358c3a5dd..98feee2ac73 100644 --- a/erpnext/patches/v14_0/update_tds_fields.py +++ b/erpnext/patches/v14_0/update_tds_fields.py @@ -1,7 +1,8 @@ import frappe def execute(): - frappe.db.sql(""" + frappe.db.sql( + """ UPDATE `tabPurchase Invoice Item` INNER JOIN @@ -13,11 +14,17 @@ def execute(): WHERE `tabPurchase Invoice`.apply_tds = 1 and `tabPurchase Invoice`.docstatus = 1 - """) + """ + ) - frappe.db.sql(""" - UPDATE `tabPurchase Invoice` - SET tax_withholding_net_total = net_total, - base_tax_withholding_net_total = base_net_total - WHERE apply_tds = 1 and docstatus = 1""") - + frappe.db.sql( + """ + UPDATE + `tabPurchase Invoice` + SET + tax_withholding_net_total = net_total, + base_tax_withholding_net_total = base_net_total + WHERE + apply_tds = 1 and docstatus = 1 + """ + )