Skip to content

Commit 5a2fb13

Browse files
committed
fix: update TDS application logic to consider tax withholding group in addition to category for sales and purchase invoices.
1 parent 2f705e5 commit 5a2fb13

6 files changed

Lines changed: 23 additions & 16 deletions

File tree

erpnext/accounts/doctype/purchase_invoice/purchase_invoice.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,8 @@ erpnext.accounts.PurchaseInvoice = class PurchaseInvoice extends erpnext.buying.
363363
},
364364
function () {
365365
me.apply_pricing_rule();
366-
me.frm.doc.apply_tds = me.frm.tax_withholding_category ? 1 : 0;
366+
me.frm.doc.apply_tds =
367+
me.frm.tax_withholding_category || me.frm.tax_withholding_group ? 1 : 0;
367368
me.frm.clear_table("tax_withholding_entries");
368369

369370
// while duplicating, don't change payment terms
@@ -670,7 +671,7 @@ frappe.ui.form.on("Purchase Invoice", {
670671
onload: function (frm) {
671672
if (frm.doc.__onload && frm.doc.supplier) {
672673
if (frm.is_new()) {
673-
frm.doc.apply_tds = frm.doc.__onload.tax_withholding_category ? 1 : 0;
674+
frm.doc.apply_tds = frm.doc.__onload.apply_tds ? 1 : 0;
674675
}
675676
}
676677

erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -241,10 +241,10 @@ def __init__(self, *args, **kwargs):
241241

242242
def onload(self):
243243
super().onload()
244-
tax_withholding_category = frappe.get_cached_value(
245-
"Supplier", self.supplier, "tax_withholding_category"
244+
tax_withholding_category, tax_withholding_group = frappe.get_cached_value(
245+
"Supplier", self.supplier, ["tax_withholding_category", "tax_withholding_group"]
246246
)
247-
self.set_onload("tax_withholding_category", tax_withholding_category)
247+
self.set_onload("apply_tds", tax_withholding_category or tax_withholding_group)
248248

249249
if self.is_new():
250250
self.set("tax_withholding_entries", [])
@@ -351,10 +351,12 @@ def set_missing_values(self, for_validate=False):
351351
template_name=self.payment_terms_template,
352352
)
353353

354-
tds_category = frappe.get_cached_value("Supplier", self.supplier, "tax_withholding_category")
355-
if tds_category and not for_validate:
356-
self.apply_tds = 1
357-
self.set_onload("tax_withholding_category", tds_category)
354+
tax_withholding_category, tax_withholding_group = frappe.get_cached_value(
355+
"Supplier", self.supplier, ["tax_withholding_category", "tax_withholding_group"]
356+
)
357+
if not for_validate:
358+
if tax_withholding_category or tax_withholding_group:
359+
self.apply_tds = 1
358360

359361
super().set_missing_values(for_validate)
360362

erpnext/accounts/doctype/sales_invoice/sales_invoice.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -383,8 +383,8 @@ erpnext.accounts.SalesInvoiceController = class SalesInvoiceController extends (
383383
),
384384
},
385385
function () {
386-
me.frm.doc.apply_tds = me.frm.tax_withholding_category ? 1 : 0;
387-
me.frm.set_df_property("apply_tds", "read_only", me.frm.tax_withholding_category ? 0 : 1);
386+
me.frm.doc.apply_tds =
387+
me.frm.tax_withholding_category || me.frm.tax_withholding_group ? 1 : 0;
388388
me.frm.clear_table("tax_withholding_entries");
389389
me.apply_pricing_rule();
390390
}
@@ -825,7 +825,7 @@ frappe.ui.form.on("Sales Invoice", {
825825

826826
if (frm.doc.__onload && frm.doc.customer) {
827827
if (frm.is_new()) {
828-
frm.doc.apply_tds = frm.doc.__onload.tax_withholding_category ? 1 : 0;
828+
frm.doc.apply_tds = frm.doc.__onload.apply_tds ? 1 : 0;
829829
}
830830
}
831831

erpnext/accounts/doctype/sales_invoice/sales_invoice.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -288,10 +288,10 @@ def set_indicator(self):
288288

289289
def onload(self):
290290
super().onload()
291-
tax_withholding_category = frappe.get_cached_value(
292-
"Customer", self.customer, "tax_withholding_category"
291+
tax_withholding_category, tax_withholding_group = frappe.get_cached_value(
292+
"Customer", self.customer, ["tax_withholding_category", "tax_withholding_group"]
293293
)
294-
self.set_onload("tax_withholding_category", tax_withholding_category)
294+
self.set_onload("apply_tds", tax_withholding_category or tax_withholding_group)
295295

296296
def validate(self):
297297
self.validate_auto_set_posting_time()

erpnext/accounts/doctype/subscription/subscription.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,10 @@ def create_invoice(
411411
invoice.customer = self.party
412412
else:
413413
invoice.supplier = self.party
414-
if frappe.db.get_value("Supplier", self.party, "tax_withholding_category"):
414+
tax_withholding_category, tax_withholding_group = frappe.get_cached_value(
415+
"Supplier", self.party, ["tax_withholding_category", "tax_withholding_group"]
416+
)
417+
if tax_withholding_category or tax_withholding_group:
415418
invoice.apply_tds = 1
416419

417420
# Add currency to invoice

erpnext/public/js/utils/party.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ erpnext.utils.get_party_details = function (frm, method, args, callback) {
109109
callback: function (r) {
110110
if (r.message) {
111111
frm.tax_withholding_category = r.message.tax_withholding_category;
112+
frm.tax_withholding_group = r.message.tax_withholding_group;
112113
frm.updating_party_details = true;
113114
frappe.run_serially([
114115
() => frm.set_value(r.message),

0 commit comments

Comments
 (0)