From bcf6deec9a73c43d68e13890cb445d5dd5433ec5 Mon Sep 17 00:00:00 2001 From: Navin-S-R Date: Mon, 1 Dec 2025 23:48:14 +0530 Subject: [PATCH] test: add unit test to validate capitalized asset repair gl entries being booked against the asset --- .../doctype/asset_repair/test_asset_repair.py | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/erpnext/assets/doctype/asset_repair/test_asset_repair.py b/erpnext/assets/doctype/asset_repair/test_asset_repair.py index 0e4ea84df86..41affd64dc6 100644 --- a/erpnext/assets/doctype/asset_repair/test_asset_repair.py +++ b/erpnext/assets/doctype/asset_repair/test_asset_repair.py @@ -3,6 +3,8 @@ import unittest import frappe +from frappe import qb +from frappe.query_builder.functions import Sum from frappe.tests import IntegrationTestCase from frappe.utils import add_days, add_months, flt, get_first_day, nowdate, nowtime, today @@ -322,6 +324,30 @@ class TestAssetRepair(IntegrationTestCase): stock_entry = frappe.get_last_doc("Stock Entry") self.assertEqual(stock_entry.asset_repair, asset_repair.name) + def test_gl_entries_with_capitalized_asset_repair(self): + asset = create_asset(is_existing_asset=1, calculate_depreciation=1, submit=1) + asset_repair = create_asset_repair( + asset=asset, capitalize_repair_cost=1, item="_Test Non Stock Item", submit=1 + ) + + GLEntry = qb.DocType("GL Entry") + res = ( + qb.from_(GLEntry) + .select(Sum(GLEntry.debit_in_account_currency).as_("total_debit")) + .where( + (GLEntry.voucher_type == "Asset Repair") + & (GLEntry.voucher_no == asset_repair.name) + & (GLEntry.against_voucher_type == "Asset") + & (GLEntry.against_voucher == asset.name) + & (GLEntry.company == asset.company) + & (GLEntry.is_cancelled == 0) + ) + ).run(as_dict=True) + booked_value = res[0].total_debit if res else 0 + + self.assertEqual(asset.additional_asset_cost, asset_repair.repair_cost) + self.assertEqual(booked_value, asset_repair.repair_cost) + def num_of_depreciations(asset): return asset.finance_books[0].total_number_of_depreciations + (