feat: item wise tds calculation

item wise tds calculation
This commit is contained in:
niralisatapara 2022-10-25 15:09:59 +05:30
parent 4a35a224e2
commit 397e3b1ade
4 changed files with 29 additions and 14 deletions

View File

@ -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,

View File

@ -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(

View File

@ -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()

View File

@ -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
"""
)