From 09a5616e2dce7d0d9962326781cd7c0a4bcaebbc Mon Sep 17 00:00:00 2001 From: Deepesh Garg Date: Thu, 28 Oct 2021 19:01:24 +0530 Subject: [PATCH] fix: Rewrite patch using query builder --- .../update_category_in_ltds_certificate.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/erpnext/patches/v13_0/update_category_in_ltds_certificate.py b/erpnext/patches/v13_0/update_category_in_ltds_certificate.py index f8a0646fcb..4d4645269c 100644 --- a/erpnext/patches/v13_0/update_category_in_ltds_certificate.py +++ b/erpnext/patches/v13_0/update_category_in_ltds_certificate.py @@ -2,9 +2,17 @@ import frappe def execute(): + company = frappe.get_all('Company', filters = {'country': 'India'}) + if not company: + return - frappe.db.sql(""" - UPDATE `tabLower Deduction Certificate` l, `tabSupplier` s - SET l.tax_withholding_category = s.tax_withholding_category - WHERE l.supplier = s.name - """) \ No newline at end of file + ldc = frappe.qb.DocType("Lower Deduction Certificate").as_("ldc") + supplier = frappe.qb.DocType("Supplier") + + frappe.qb.update(ldc).inner_join(supplier).on( + ldc.supplier == supplier.name + ).set( + ldc.tax_withholding_category, supplier.tax_withholding_category + ).where( + ldc.tax_withholding_category.isnull() + ).run() \ No newline at end of file