diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py index 0b544b13a3..c9cf47d114 100644 --- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py +++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py @@ -732,19 +732,17 @@ class PurchaseInvoice(BuyingController): def set_tax_withholding(self): """ - 1. Get TDS Configurations against Supplier or Pull Default One. - 2. Form Purchase Order, identify partial payments - 3. If sum of all invoices grand total is greater than threshold and If TDS not deducted in previos Invoices - then deduct TDS for sum amount else deduct TDS for current Invoice + 1. Get TDS Configurations against Supplier """ - if not self.get("__islocal"): - return tax_withholding_details = get_patry_tax_withholding_details(self) - - if tax_withholding_details and\ - flt(self.get("rounded_total") or self.grand_total) >= flt(tax_withholding_details['threshold']): - self.append('taxes', tax_withholding_details['taxes']) + for tax_details in tax_withholding_details: + if flt(self.get("rounded_total") or self.grand_total) >= flt(tax_details['threshold']): + if self.taxes: + if tax_details['tax']['description'] not in [tax.description for tax in self.taxes]: + self.append('taxes', tax_details['tax']) + else: + self.append('taxes', tax_details['tax']) @frappe.whitelist() def make_debit_note(source_name, target_doc=None): diff --git a/erpnext/accounts/party.py b/erpnext/accounts/party.py index 6c778f99c8..75089b2ff4 100644 --- a/erpnext/accounts/party.py +++ b/erpnext/accounts/party.py @@ -478,8 +478,8 @@ def get_party_shipping_address(doctype, name): def get_patry_tax_withholding_details(ref_doc): supplier = frappe.get_doc("Supplier", ref_doc.supplier) - tax_withholding_details = {} - + tax_withholding_details = [] + print(supplier) for tax in supplier.tax_withholding_config: tax_mapper = get_tax_mapper() @@ -492,19 +492,16 @@ def get_patry_tax_withholding_details(ref_doc): prepare_tax_withholding_details(tax_mapper, tax_withholding_details) - if not tax_withholding_details: - tax_mapper = get_tax_mapper() - set_tax_withholding_details(tax_mapper, ref_doc, use_default=1) - prepare_tax_withholding_details(tax_mapper, tax_withholding_details) - return tax_withholding_details def prepare_tax_withholding_details(tax_mapper, tax_withholding_details): if tax_mapper.get('account_head'): - tax_withholding_details.update({ + + tax_withholding_details.append({ "threshold": tax_mapper['threshold'], - "taxes": tax_mapper + "tax": tax_mapper }) + del tax_mapper['threshold'] def set_tax_withholding_details(tax_mapper, ref_doc, tax_withholding_category=None, use_default=0): @@ -534,4 +531,4 @@ def get_tax_mapper(): "description": '', "account_head": '', "threshold": 0.0 - } \ No newline at end of file + }