From 2bd8bd224ba7f0414cdd74126012887da1d10445 Mon Sep 17 00:00:00 2001 From: niralisatapara Date: Tue, 22 Nov 2022 14:15:36 +0530 Subject: [PATCH] feat: item wise tds calculation for purchase order. (cherry picked from commit 46e8cdf31a75bbd1be7a8f8be2bc6031fb573be4) --- .../test_tax_withholding_category.py | 69 +++++++++++++++++++ ...fields.py => update_partial_tds_fields.py} | 16 +++++ 2 files changed, 85 insertions(+) rename erpnext/patches/v14_0/{update_tds_fields.py => update_partial_tds_fields.py} (64%) diff --git a/erpnext/accounts/doctype/tax_withholding_category/test_tax_withholding_category.py b/erpnext/accounts/doctype/tax_withholding_category/test_tax_withholding_category.py index 40c732bae527..23caac047adf 100644 --- a/erpnext/accounts/doctype/tax_withholding_category/test_tax_withholding_category.py +++ b/erpnext/accounts/doctype/tax_withholding_category/test_tax_withholding_category.py @@ -226,6 +226,42 @@ def test_tds_calculation_on_net_total_partial_tds(self): for d in reversed(invoices): d.cancel() + orders = [] + + po = create_purchase_order(supplier="Test TDS Supplier4", rate=20000, do_not_save=True) + po.extend( + "items", + [ + { + "doctype": "Purchase Order Item", + "item_code": frappe.db.get_value("Item", {"item_name": "TDS Item"}, "name"), + "qty": 1, + "rate": 20000, + "cost_center": "Main - _TC", + "expense_account": "Stock Received But Not Billed - _TC", + "apply_tds": 0, + }, + { + "doctype": "Purchase Order Item", + "item_code": frappe.db.get_value("Item", {"item_name": "TDS Item"}, "name"), + "qty": 1, + "rate": 35000, + "cost_center": "Main - _TC", + "expense_account": "Stock Received But Not Billed - _TC", + "apply_tds": 1, + }, + ], + ) + po.save() + po.submit() + orders.append(po) + + self.assertEqual(po.taxes[0].tax_amount, 5500) + + # cancel orders to avoid clashing + for d in reversed(orders): + d.cancel() + def test_multi_category_single_supplier(self): frappe.db.set_value( "Supplier", "Test TDS Supplier5", "tax_withholding_category", "Test Service Category" @@ -348,6 +384,39 @@ def create_purchase_invoice(**args): return pi +def create_purchase_order(**args): + # return purchase order doc object + item = frappe.db.get_value("Item", {"item_name": "TDS Item"}, "name") + + args = frappe._dict(args) + po = frappe.get_doc( + { + "doctype": "Purchase Order", + "transaction_date": today(), + "schedule_date": today(), + "apply_tds": 0 if args.do_not_apply_tds else 1, + "supplier": args.supplier, + "company": "_Test Company", + "taxes_and_charges": "", + "currency": "INR", + "taxes": [], + "items": [ + { + "doctype": "Purchase Order Item", + "item_code": item, + "qty": args.qty or 1, + "rate": args.rate or 10000, + "cost_center": "Main - _TC", + "expense_account": "Stock Received But Not Billed - _TC", + } + ], + } + ) + + po.save() + return po + + def create_sales_invoice(**args): # return sales invoice doc object item = frappe.db.get_value("Item", {"item_name": "TCS Item"}, "name") diff --git a/erpnext/patches/v14_0/update_tds_fields.py b/erpnext/patches/v14_0/update_partial_tds_fields.py similarity index 64% rename from erpnext/patches/v14_0/update_tds_fields.py rename to erpnext/patches/v14_0/update_partial_tds_fields.py index a333c5d7a50d..5ccc2dc3aa27 100644 --- a/erpnext/patches/v14_0/update_tds_fields.py +++ b/erpnext/patches/v14_0/update_partial_tds_fields.py @@ -25,5 +25,21 @@ def execute(): ).where( purchase_invoice.docstatus == 1 ).run() + + purchase_order = frappe.qb.DocType("Purchase Order") + + frappe.qb.update(purchase_order).set( + purchase_order.tax_withholding_net_total, purchase_order.net_total + ).set( + purchase_order.base_tax_withholding_net_total, purchase_order.base_net_total + ).where( + purchase_order.company == company.name + ).where( + purchase_order.apply_tds == 1 + ).where( + purchase_order.transaction_date >= fiscal_year_details.year_start_date + ).where( + purchase_order.docstatus == 1 + ).run() except FiscalYearError: pass