From f3f438ad183e13ba9ea56fe96dd11941fc6d203f Mon Sep 17 00:00:00 2001 From: Saurabh Date: Mon, 14 May 2018 20:19:39 +0530 Subject: [PATCH] tds fixed for PI --- .../purchase_invoice/purchase_invoice.py | 18 ++++++++---------- erpnext/accounts/party.py | 17 +++++++---------- 2 files changed, 15 insertions(+), 20 deletions(-) diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py index 0b544b13a30..c9cf47d114a 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 6c778f99c81..75089b2ff4c 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 + }