mirror of
https://github.com/frappe/erpnext.git
synced 2026-09-03 16:40:19 +00:00
fix(postgres): replace MySQL IF() with Case in Cheques and Deposits report
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
import frappe
|
import frappe
|
||||||
from frappe import _, qb
|
from frappe import _, qb
|
||||||
from frappe.query_builder import CustomFunction
|
from frappe.query_builder import Case
|
||||||
from frappe.query_builder.custom import ConstantColumn
|
from frappe.query_builder.custom import ConstantColumn
|
||||||
|
|
||||||
|
|
||||||
@@ -93,7 +93,6 @@ def get_amounts_not_reflected_in_system_for_bank_reconciliation_statement(filter
|
|||||||
.run(as_dict=1)
|
.run(as_dict=1)
|
||||||
)
|
)
|
||||||
|
|
||||||
ifelse = CustomFunction("IF", ["condition", "then", "else"])
|
|
||||||
pe = qb.DocType("Payment Entry")
|
pe = qb.DocType("Payment Entry")
|
||||||
doctype_name = ConstantColumn("Payment Entry")
|
doctype_name = ConstantColumn("Payment Entry")
|
||||||
payments = (
|
payments = (
|
||||||
@@ -101,7 +100,10 @@ def get_amounts_not_reflected_in_system_for_bank_reconciliation_statement(filter
|
|||||||
.select(
|
.select(
|
||||||
doctype_name.as_("doctype"),
|
doctype_name.as_("doctype"),
|
||||||
pe.name,
|
pe.name,
|
||||||
ifelse(pe.paid_from.eq(filters.account), pe.paid_amount, pe.received_amount).as_("amount"),
|
Case()
|
||||||
|
.when(pe.paid_from.eq(filters.account), pe.paid_amount)
|
||||||
|
.else_(pe.received_amount)
|
||||||
|
.as_("amount"),
|
||||||
pe.payment_type,
|
pe.payment_type,
|
||||||
pe.party_type,
|
pe.party_type,
|
||||||
pe.posting_date,
|
pe.posting_date,
|
||||||
|
|||||||
@@ -0,0 +1,24 @@
|
|||||||
|
# Copyright (c) 2024, Frappe Technologies Pvt. Ltd. and contributors
|
||||||
|
# For license information, please see license.txt
|
||||||
|
|
||||||
|
import frappe
|
||||||
|
from frappe.utils import nowdate
|
||||||
|
|
||||||
|
from erpnext.accounts.report.cheques_and_deposits_incorrectly_cleared.cheques_and_deposits_incorrectly_cleared import (
|
||||||
|
execute,
|
||||||
|
)
|
||||||
|
from erpnext.tests.utils import ERPNextTestSuite
|
||||||
|
|
||||||
|
|
||||||
|
class TestChequesAndDepositsIncorrectlyCleared(ERPNextTestSuite):
|
||||||
|
def test_report_executes_with_case_amount(self):
|
||||||
|
# Exercises the Payment Entry branch whose amount column uses a db-aware CASE expression
|
||||||
|
# (previously a MySQL-only IF()). IF() does not compile on postgres, so running the report
|
||||||
|
# query guards the portability fix on both databases.
|
||||||
|
company = frappe.db.get_value("Company", {}, "name")
|
||||||
|
account = frappe.db.get_value(
|
||||||
|
"Account", {"account_type": "Bank", "company": company, "is_group": 0}, "name"
|
||||||
|
)
|
||||||
|
columns, data = execute(frappe._dict({"account": account, "report_date": nowdate()}))
|
||||||
|
self.assertTrue(columns)
|
||||||
|
self.assertIsInstance(data, list)
|
||||||
Reference in New Issue
Block a user