From 6bc59d23ea8d2cc78036925e9110b4b3ee40cb6c Mon Sep 17 00:00:00 2001 From: Faris Ansari Date: Tue, 27 May 2025 15:27:38 +0530 Subject: [PATCH 1/8] fix: update sql function usage syntax based on https://github.com/frappe/frappe/pull/32381 --- .../payment_reconciliation/test_payment_reconciliation.py | 2 +- erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/erpnext/accounts/doctype/payment_reconciliation/test_payment_reconciliation.py b/erpnext/accounts/doctype/payment_reconciliation/test_payment_reconciliation.py index da1a47bc3db..ab61b85e710 100644 --- a/erpnext/accounts/doctype/payment_reconciliation/test_payment_reconciliation.py +++ b/erpnext/accounts/doctype/payment_reconciliation/test_payment_reconciliation.py @@ -1979,7 +1979,7 @@ class TestPaymentReconciliation(IntegrationTestCase): def test_reconciliation_on_closed_period_payment(self): # create backdated fiscal year - first_fy_start_date = frappe.db.get_value("Fiscal Year", {"disabled": 0}, "min(year_start_date)") + first_fy_start_date = frappe.db.get_value("Fiscal Year", {"disabled": 0}, [{'MIN': 'year_start_date'}]) prev_fy_start_date = add_years(first_fy_start_date, -1) prev_fy_end_date = add_days(first_fy_start_date, -1) create_fiscal_year( diff --git a/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py b/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py index 47c3bbfb993..7c58bdc45a7 100644 --- a/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py +++ b/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py @@ -2128,7 +2128,7 @@ class TestPurchaseReceipt(IntegrationTestCase): self.assertEqual(flt(pr.total * pr.conversion_rate, 2), flt(pr.base_total, 2)) # Test - 2: Sum of Debit or Credit should be equal to Purchase Receipt Base Total - amount = frappe.db.get_value("GL Entry", {"docstatus": 1, "voucher_no": pr.name}, ["sum(debit)"]) + amount = frappe.db.get_value("GL Entry", {"docstatus": 1, "voucher_no": pr.name}, [{'SUM': 'debit'}]) expected_amount = pr.base_total self.assertEqual(amount, expected_amount) From 495bf4b7659a604b8f99b44f6147c820eaee64d5 Mon Sep 17 00:00:00 2001 From: Faris Ansari Date: Mon, 2 Jun 2025 17:25:05 +0530 Subject: [PATCH 2/8] chore: set correct payments app branch --- .github/helper/install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/helper/install.sh b/.github/helper/install.sh index b863bd9d670..95e95b07153 100644 --- a/.github/helper/install.sh +++ b/.github/helper/install.sh @@ -66,7 +66,7 @@ sed -i 's/schedule:/# schedule:/g' Procfile sed -i 's/socketio:/# socketio:/g' Procfile sed -i 's/redis_socketio:/# redis_socketio:/g' Procfile -bench get-app payments --branch ${githubbranch%"-hotfix"} +bench get-app payments --branch develop bench get-app erpnext "${GITHUB_WORKSPACE}" if [ "$TYPE" == "server" ]; then bench setup requirements --dev; fi From 6a3fc36979b28991caed0681a294300c43b56e39 Mon Sep 17 00:00:00 2001 From: Faris Ansari Date: Fri, 6 Jun 2025 12:11:18 +0530 Subject: [PATCH 3/8] fix: update sql function usage syntax --- erpnext/accounts/general_ledger.py | 2 +- erpnext/stock/doctype/packing_slip/packing_slip.py | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/erpnext/accounts/general_ledger.py b/erpnext/accounts/general_ledger.py index 24685bfabe9..45973fa1206 100644 --- a/erpnext/accounts/general_ledger.py +++ b/erpnext/accounts/general_ledger.py @@ -766,7 +766,7 @@ def validate_against_pcv(is_opening, posting_date, company): ) last_pcv_date = frappe.db.get_value( - "Period Closing Voucher", {"docstatus": 1, "company": company}, "max(period_end_date)" + "Period Closing Voucher", {"docstatus": 1, "company": company}, {"MAX": "period_end_date"} ) if last_pcv_date and getdate(posting_date) <= getdate(last_pcv_date): diff --git a/erpnext/stock/doctype/packing_slip/packing_slip.py b/erpnext/stock/doctype/packing_slip/packing_slip.py index fe28b3c5397..afd596aa2a8 100644 --- a/erpnext/stock/doctype/packing_slip/packing_slip.py +++ b/erpnext/stock/doctype/packing_slip/packing_slip.py @@ -5,7 +5,7 @@ import frappe from frappe import _ from frappe.utils import cint, flt - +from frappe.query_builder.functions import Sum from erpnext.controllers.status_updater import StatusUpdater @@ -128,11 +128,11 @@ class PackingSlip(StatusUpdater): item.idx ) ) - + DocType = frappe.qb.DocType("Delivery Note Item" if item.dn_detail else "Packed Item") remaining_qty = frappe.db.get_value( "Delivery Note Item" if item.dn_detail else "Packed Item", {"name": item.dn_detail or item.pi_detail, "docstatus": 0}, - ["sum(qty - packed_qty)"], + Sum(DocType.qty - DocType.packed_qty), ) if remaining_qty is None: @@ -174,7 +174,7 @@ class PackingSlip(StatusUpdater): return ( cint( frappe.db.get_value( - "Packing Slip", {"delivery_note": self.delivery_note, "docstatus": 1}, ["max(to_case_no)"] + "Packing Slip", {"delivery_note": self.delivery_note, "docstatus": 1}, {"MAX": "to_case_no"} ) ) + 1 From 20e2fda1839e46de8645d5a6bc84a2f02881abd0 Mon Sep 17 00:00:00 2001 From: Faris Ansari Date: Fri, 6 Jun 2025 17:05:08 +0530 Subject: [PATCH 4/8] fix: field can't be a dict --- erpnext/accounts/general_ledger.py | 2 +- erpnext/stock/doctype/packing_slip/packing_slip.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/erpnext/accounts/general_ledger.py b/erpnext/accounts/general_ledger.py index 45973fa1206..b1eeab9e6f8 100644 --- a/erpnext/accounts/general_ledger.py +++ b/erpnext/accounts/general_ledger.py @@ -766,7 +766,7 @@ def validate_against_pcv(is_opening, posting_date, company): ) last_pcv_date = frappe.db.get_value( - "Period Closing Voucher", {"docstatus": 1, "company": company}, {"MAX": "period_end_date"} + "Period Closing Voucher", {"docstatus": 1, "company": company}, [{"MAX": "period_end_date"}] ) if last_pcv_date and getdate(posting_date) <= getdate(last_pcv_date): diff --git a/erpnext/stock/doctype/packing_slip/packing_slip.py b/erpnext/stock/doctype/packing_slip/packing_slip.py index afd596aa2a8..c30645f8827 100644 --- a/erpnext/stock/doctype/packing_slip/packing_slip.py +++ b/erpnext/stock/doctype/packing_slip/packing_slip.py @@ -174,7 +174,7 @@ class PackingSlip(StatusUpdater): return ( cint( frappe.db.get_value( - "Packing Slip", {"delivery_note": self.delivery_note, "docstatus": 1}, {"MAX": "to_case_no"} + "Packing Slip", {"delivery_note": self.delivery_note, "docstatus": 1}, [{"MAX": "to_case_no"}] ) ) + 1 From 300530d35aa71a67b9c8d9d897ac312cddde1083 Mon Sep 17 00:00:00 2001 From: Faris Ansari Date: Fri, 6 Jun 2025 17:20:56 +0530 Subject: [PATCH 5/8] fix: change sql function string to pypika sql function string not supported anymore --- erpnext/controllers/accounts_controller.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/erpnext/controllers/accounts_controller.py b/erpnext/controllers/accounts_controller.py index 33d04ecef87..20d8079d648 100644 --- a/erpnext/controllers/accounts_controller.py +++ b/erpnext/controllers/accounts_controller.py @@ -2232,6 +2232,8 @@ class AccountsController(TransactionBase): def set_advance_payment_status(self): new_status = None + + PaymentRequest = frappe.qb.DocType("Payment Request") paid_amount = frappe.get_value( doctype="Payment Request", filters={ @@ -2239,7 +2241,7 @@ class AccountsController(TransactionBase): "reference_name": self.name, "docstatus": 1, }, - fieldname="sum(grand_total - outstanding_amount)", + fieldname=Sum(PaymentRequest.grand_total - PaymentRequest.outstanding_amount), ) if not paid_amount: From a397c1dea8e9cd1a42ef4962b5735adcf627ca5f Mon Sep 17 00:00:00 2001 From: Faris Ansari Date: Fri, 6 Jun 2025 20:05:34 +0530 Subject: [PATCH 6/8] fix: update sql function usage syntax --- .../tax_withholding_category/tax_withholding_category.py | 4 ++-- .../item_wise_sales_register/item_wise_sales_register.py | 2 +- erpnext/controllers/sales_and_purchase_return.py | 6 +++++- erpnext/patches/v12_0/set_total_batch_quantity.py | 2 +- erpnext/setup/doctype/sales_person/sales_person.py | 4 ++-- .../stock/doctype/purchase_receipt/test_purchase_receipt.py | 2 +- .../doctype/stock_ledger_entry/test_stock_ledger_entry.py | 2 +- 7 files changed, 13 insertions(+), 9 deletions(-) diff --git a/erpnext/accounts/doctype/tax_withholding_category/tax_withholding_category.py b/erpnext/accounts/doctype/tax_withholding_category/tax_withholding_category.py index fa9b226374c..2c6d13b3147 100644 --- a/erpnext/accounts/doctype/tax_withholding_category/tax_withholding_category.py +++ b/erpnext/accounts/doctype/tax_withholding_category/tax_withholding_category.py @@ -657,7 +657,7 @@ def get_tcs_amount(parties, inv, tax_details, vouchers, adv_vouchers): "company": inv.company, "voucher_no": ["in", vouchers], }, - "sum(debit)", + [{"SUM": "debit"}], ) or 0.0 ) @@ -735,7 +735,7 @@ def get_limit_consumed(ldc, parties): "posting_date": ("between", (ldc.valid_from, ldc.valid_upto)), "company": ldc.company, }, - "sum(tax_withholding_net_total)", + [{"SUM": "tax_withholding_net_total"}], ) return limit_consumed diff --git a/erpnext/accounts/report/item_wise_sales_register/item_wise_sales_register.py b/erpnext/accounts/report/item_wise_sales_register/item_wise_sales_register.py index a88a36c642c..52096ce365a 100644 --- a/erpnext/accounts/report/item_wise_sales_register/item_wise_sales_register.py +++ b/erpnext/accounts/report/item_wise_sales_register/item_wise_sales_register.py @@ -525,7 +525,7 @@ def get_grand_total(filters, doctype): "docstatus": 1, "posting_date": ("between", [filters.get("from_date"), filters.get("to_date")]), }, - "sum(base_grand_total)", + [{"SUM": "base_grand_total"}], ) ) diff --git a/erpnext/controllers/sales_and_purchase_return.py b/erpnext/controllers/sales_and_purchase_return.py index a7c5b72cbb9..e5864ce13ad 100644 --- a/erpnext/controllers/sales_and_purchase_return.py +++ b/erpnext/controllers/sales_and_purchase_return.py @@ -7,6 +7,7 @@ import frappe from frappe import _ from frappe.model.meta import get_field_precision from frappe.query_builder import DocType +from frappe.query_builder.functions import Abs from frappe.utils import cint, flt, format_datetime, get_datetime import erpnext @@ -661,7 +662,10 @@ def get_rate_for_return( if voucher_type in ("Purchase Receipt", "Purchase Invoice", "Subcontracting Receipt"): select_field = "incoming_rate" else: - select_field = "abs(stock_value_difference / actual_qty)" + StockLedgerEntry = frappe.qb.DocType("Stock Ledger Entry") + select_field = Abs( + StockLedgerEntry.stock_value_difference / StockLedgerEntry.actual_qty + ) rate = flt(frappe.db.get_value("Stock Ledger Entry", filters, select_field)) if not (rate and return_against) and voucher_type in ["Sales Invoice", "Delivery Note"]: diff --git a/erpnext/patches/v12_0/set_total_batch_quantity.py b/erpnext/patches/v12_0/set_total_batch_quantity.py index 068e0a6a4c1..cedcbfa36e9 100644 --- a/erpnext/patches/v12_0/set_total_batch_quantity.py +++ b/erpnext/patches/v12_0/set_total_batch_quantity.py @@ -9,7 +9,7 @@ def execute(): frappe.db.get_value( "Stock Ledger Entry", {"docstatus": 1, "batch_no": batch.batch_id, "is_cancelled": 0}, - "sum(actual_qty)", + [{"SUM": "actual_qty"}], ) or 0.0 ) diff --git a/erpnext/setup/doctype/sales_person/sales_person.py b/erpnext/setup/doctype/sales_person/sales_person.py index 43c5afa313e..73e9e9641d3 100644 --- a/erpnext/setup/doctype/sales_person/sales_person.py +++ b/erpnext/setup/doctype/sales_person/sales_person.py @@ -64,7 +64,7 @@ class SalesPerson(NestedSet): frappe.db.get_value( "Sales Team", {"docstatus": 1, "parenttype": "Sales Order", "sales_person": self.sales_person_name}, - "sum(allocated_amount)", + [{"SUM": "allocated_amount"}], ) ) @@ -72,7 +72,7 @@ class SalesPerson(NestedSet): frappe.db.get_value( "Sales Team", {"docstatus": 1, "parenttype": "Sales Invoice", "sales_person": self.sales_person_name}, - "sum(allocated_amount)", + {"SUM": "allocated_amount"}, ) ) diff --git a/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py b/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py index 7c58bdc45a7..d1e9cd8766b 100644 --- a/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py +++ b/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py @@ -1799,7 +1799,7 @@ class TestPurchaseReceipt(IntegrationTestCase): "voucher_no": pr.name, "is_cancelled": 0, }, - fieldname=["sum(stock_value_difference)"], + fieldname=[{"SUM": "stock_value_difference"}], ) # Value of Stock Account should be equal to the sum of Stock Value Difference diff --git a/erpnext/stock/doctype/stock_ledger_entry/test_stock_ledger_entry.py b/erpnext/stock/doctype/stock_ledger_entry/test_stock_ledger_entry.py index 4855327b08e..af950d04071 100644 --- a/erpnext/stock/doctype/stock_ledger_entry/test_stock_ledger_entry.py +++ b/erpnext/stock/doctype/stock_ledger_entry/test_stock_ledger_entry.py @@ -1039,7 +1039,7 @@ class TestStockLedgerEntry(IntegrationTestCase, StockTestMixin): "is_cancelled": 0, "account": "Stock In Hand - TCP1", }, - "sum(credit)", + [{"SUM": "credit"}], ) def _day(days): From 74bd07f10bb86dfce3570f105aa9e70c7fe613dc Mon Sep 17 00:00:00 2001 From: Faris Ansari Date: Thu, 19 Jun 2025 17:36:12 +0530 Subject: [PATCH 7/8] fix: sql function syntax --- erpnext/setup/doctype/sales_person/sales_person.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/setup/doctype/sales_person/sales_person.py b/erpnext/setup/doctype/sales_person/sales_person.py index 73e9e9641d3..7e0436d225e 100644 --- a/erpnext/setup/doctype/sales_person/sales_person.py +++ b/erpnext/setup/doctype/sales_person/sales_person.py @@ -72,7 +72,7 @@ class SalesPerson(NestedSet): frappe.db.get_value( "Sales Team", {"docstatus": 1, "parenttype": "Sales Invoice", "sales_person": self.sales_person_name}, - {"SUM": "allocated_amount"}, + [{"SUM": "allocated_amount"}], ) ) From 289694ed4caa8ba0cc1955f38a191b1009f0f14b Mon Sep 17 00:00:00 2001 From: ruthra kumar Date: Mon, 23 Jun 2025 17:09:29 +0530 Subject: [PATCH 8/8] chore: resolve linter --- .../payment_reconciliation/test_payment_reconciliation.py | 4 +++- erpnext/controllers/accounts_controller.py | 1 - erpnext/controllers/sales_and_purchase_return.py | 4 +--- erpnext/stock/doctype/packing_slip/packing_slip.py | 7 +++++-- .../doctype/purchase_receipt/test_purchase_receipt.py | 2 +- 5 files changed, 10 insertions(+), 8 deletions(-) diff --git a/erpnext/accounts/doctype/payment_reconciliation/test_payment_reconciliation.py b/erpnext/accounts/doctype/payment_reconciliation/test_payment_reconciliation.py index ab61b85e710..57231ec5bdd 100644 --- a/erpnext/accounts/doctype/payment_reconciliation/test_payment_reconciliation.py +++ b/erpnext/accounts/doctype/payment_reconciliation/test_payment_reconciliation.py @@ -1979,7 +1979,9 @@ class TestPaymentReconciliation(IntegrationTestCase): def test_reconciliation_on_closed_period_payment(self): # create backdated fiscal year - first_fy_start_date = frappe.db.get_value("Fiscal Year", {"disabled": 0}, [{'MIN': 'year_start_date'}]) + first_fy_start_date = frappe.db.get_value( + "Fiscal Year", {"disabled": 0}, [{"MIN": "year_start_date"}] + ) prev_fy_start_date = add_years(first_fy_start_date, -1) prev_fy_end_date = add_days(first_fy_start_date, -1) create_fiscal_year( diff --git a/erpnext/controllers/accounts_controller.py b/erpnext/controllers/accounts_controller.py index 20d8079d648..bb918934a01 100644 --- a/erpnext/controllers/accounts_controller.py +++ b/erpnext/controllers/accounts_controller.py @@ -2232,7 +2232,6 @@ class AccountsController(TransactionBase): def set_advance_payment_status(self): new_status = None - PaymentRequest = frappe.qb.DocType("Payment Request") paid_amount = frappe.get_value( doctype="Payment Request", diff --git a/erpnext/controllers/sales_and_purchase_return.py b/erpnext/controllers/sales_and_purchase_return.py index e5864ce13ad..0a221d9d2c6 100644 --- a/erpnext/controllers/sales_and_purchase_return.py +++ b/erpnext/controllers/sales_and_purchase_return.py @@ -663,9 +663,7 @@ def get_rate_for_return( select_field = "incoming_rate" else: StockLedgerEntry = frappe.qb.DocType("Stock Ledger Entry") - select_field = Abs( - StockLedgerEntry.stock_value_difference / StockLedgerEntry.actual_qty - ) + select_field = Abs(StockLedgerEntry.stock_value_difference / StockLedgerEntry.actual_qty) rate = flt(frappe.db.get_value("Stock Ledger Entry", filters, select_field)) if not (rate and return_against) and voucher_type in ["Sales Invoice", "Delivery Note"]: diff --git a/erpnext/stock/doctype/packing_slip/packing_slip.py b/erpnext/stock/doctype/packing_slip/packing_slip.py index c30645f8827..587d7ecd337 100644 --- a/erpnext/stock/doctype/packing_slip/packing_slip.py +++ b/erpnext/stock/doctype/packing_slip/packing_slip.py @@ -4,8 +4,9 @@ import frappe from frappe import _ -from frappe.utils import cint, flt from frappe.query_builder.functions import Sum +from frappe.utils import cint, flt + from erpnext.controllers.status_updater import StatusUpdater @@ -174,7 +175,9 @@ class PackingSlip(StatusUpdater): return ( cint( frappe.db.get_value( - "Packing Slip", {"delivery_note": self.delivery_note, "docstatus": 1}, [{"MAX": "to_case_no"}] + "Packing Slip", + {"delivery_note": self.delivery_note, "docstatus": 1}, + [{"MAX": "to_case_no"}], ) ) + 1 diff --git a/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py b/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py index d1e9cd8766b..c96536d049a 100644 --- a/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py +++ b/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py @@ -2128,7 +2128,7 @@ class TestPurchaseReceipt(IntegrationTestCase): self.assertEqual(flt(pr.total * pr.conversion_rate, 2), flt(pr.base_total, 2)) # Test - 2: Sum of Debit or Credit should be equal to Purchase Receipt Base Total - amount = frappe.db.get_value("GL Entry", {"docstatus": 1, "voucher_no": pr.name}, [{'SUM': 'debit'}]) + amount = frappe.db.get_value("GL Entry", {"docstatus": 1, "voucher_no": pr.name}, [{"SUM": "debit"}]) expected_amount = pr.base_total self.assertEqual(amount, expected_amount)