diff --git a/erpnext/assets/doctype/asset_repair/asset_repair.py b/erpnext/assets/doctype/asset_repair/asset_repair.py index ce942fe8249..5c280404958 100644 --- a/erpnext/assets/doctype/asset_repair/asset_repair.py +++ b/erpnext/assets/doctype/asset_repair/asset_repair.py @@ -328,7 +328,8 @@ class AssetRepair(AccountsController): "voucher_no": self.name, "cost_center": self.cost_center, "posting_date": self.completion_date, - "against_voucher_type": "Purchase Invoice", + "against_voucher_type": "Asset", + "against_voucher": self.asset, "company": self.company, }, item=self, diff --git a/erpnext/assets/doctype/asset_repair/test_asset_repair.py b/erpnext/assets/doctype/asset_repair/test_asset_repair.py index 0e4ea84df86..e9d603e2267 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,31 @@ 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 + ) + asset.reload() + + 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 + (