mirror of
https://github.com/frappe/erpnext.git
synced 2026-09-19 19:37:56 +00:00
refactor(postgres): port Asset Depreciation Ledger report query to the query builder
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -15,10 +15,7 @@ def execute(filters=None):
|
|||||||
|
|
||||||
def get_data(filters):
|
def get_data(filters):
|
||||||
data = []
|
data = []
|
||||||
depreciation_accounts = frappe.db.sql_list(
|
depreciation_accounts = frappe.get_all("Account", filters={"account_type": "Depreciation"}, pluck="name")
|
||||||
""" select name from tabAccount
|
|
||||||
where ifnull(account_type, '') = 'Depreciation' """
|
|
||||||
)
|
|
||||||
|
|
||||||
filters_data = [
|
filters_data = [
|
||||||
["company", "=", filters.get("company")],
|
["company", "=", filters.get("company")],
|
||||||
@@ -33,10 +30,8 @@ def get_data(filters):
|
|||||||
filters_data.append(["against_voucher", "=", filters.get("asset")])
|
filters_data.append(["against_voucher", "=", filters.get("asset")])
|
||||||
|
|
||||||
if filters.get("asset_category"):
|
if filters.get("asset_category"):
|
||||||
assets = frappe.db.sql_list(
|
assets = frappe.get_all(
|
||||||
"""select name from tabAsset
|
"Asset", filters={"asset_category": filters.get("asset_category"), "docstatus": 1}, pluck="name"
|
||||||
where asset_category = %s and docstatus=1""",
|
|
||||||
filters.get("asset_category"),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
filters_data.append(["against_voucher", "in", assets])
|
filters_data.append(["against_voucher", "in", assets])
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
# Copyright (c) 2024, Frappe Technologies Pvt. Ltd. and contributors
|
||||||
|
# For license information, please see license.txt
|
||||||
|
|
||||||
|
import frappe
|
||||||
|
|
||||||
|
from erpnext.accounts.report.asset_depreciation_ledger.asset_depreciation_ledger import execute
|
||||||
|
from erpnext.tests.utils import ERPNextTestSuite
|
||||||
|
|
||||||
|
|
||||||
|
class TestAssetDepreciationLedger(ERPNextTestSuite):
|
||||||
|
def test_report_executes(self):
|
||||||
|
# Smoke-guards the raw-SQL -> query-builder port: the report query must compile and run on
|
||||||
|
# both MariaDB and postgres.
|
||||||
|
company = frappe.db.get_value("Company", {}, "name")
|
||||||
|
columns, *_rest = execute(
|
||||||
|
frappe._dict({"company": company, "from_date": "2020-01-01", "to_date": "2030-12-31"})
|
||||||
|
)
|
||||||
|
self.assertTrue(columns)
|
||||||
Reference in New Issue
Block a user