From 766c5bbe2b64dc48d52489ef509acffb9ae66d4c Mon Sep 17 00:00:00 2001 From: khushi8112 Date: Fri, 18 Jul 2025 17:10:58 +0530 Subject: [PATCH] fix: make completion mandatory and fix test case --- .../test_asset_depreciation_schedule.py | 2 +- erpnext/assets/doctype/asset_repair/asset_repair.json | 3 ++- erpnext/assets/doctype/asset_repair/asset_repair.py | 2 +- erpnext/assets/doctype/asset_repair/test_asset_repair.py | 3 ++- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/erpnext/assets/doctype/asset_depreciation_schedule/test_asset_depreciation_schedule.py b/erpnext/assets/doctype/asset_depreciation_schedule/test_asset_depreciation_schedule.py index e0366cbf790..06f4e60a7d5 100644 --- a/erpnext/assets/doctype/asset_depreciation_schedule/test_asset_depreciation_schedule.py +++ b/erpnext/assets/doctype/asset_depreciation_schedule/test_asset_depreciation_schedule.py @@ -659,7 +659,7 @@ class TestAssetDepreciationSchedule(IntegrationTestCase): self.assertEqual(schedules, expected_depreciation_before_repair) - def test_daily_prorata_based_depreciation_schedule_after_cancelling_asset_repair_for(self): + def test_daily_prorata_based_depreciation_schedule_after_cancelling_asset_repair(self): asset = create_asset( item_code="Macbook Pro", gross_purchase_amount=500, diff --git a/erpnext/assets/doctype/asset_repair/asset_repair.json b/erpnext/assets/doctype/asset_repair/asset_repair.json index 935ed1b4e98..8f693cce6b0 100644 --- a/erpnext/assets/doctype/asset_repair/asset_repair.json +++ b/erpnext/assets/doctype/asset_repair/asset_repair.json @@ -68,6 +68,7 @@ "fieldname": "completion_date", "fieldtype": "Datetime", "label": "Completion Date", + "mandatory_depends_on": "eval:doc.repair_status==\"Completed\"", "no_copy": 1 }, { @@ -260,7 +261,7 @@ "index_web_pages_for_search": 1, "is_submittable": 1, "links": [], - "modified": "2025-06-29 22:30:00.589597", + "modified": "2025-07-18 15:59:53.981224", "modified_by": "Administrator", "module": "Assets", "name": "Asset Repair", diff --git a/erpnext/assets/doctype/asset_repair/asset_repair.py b/erpnext/assets/doctype/asset_repair/asset_repair.py index 42dce63a534..1614fd05c43 100644 --- a/erpnext/assets/doctype/asset_repair/asset_repair.py +++ b/erpnext/assets/doctype/asset_repair/asset_repair.py @@ -75,7 +75,7 @@ class AssetRepair(AccountsController): ) def validate_dates(self): - if self.completion_date and (self.failure_date > self.completion_date): + if self.completion_date and (getdate(self.failure_date) > getdate(self.completion_date)): frappe.throw( _("Completion Date can not be before Failure Date. Please adjust the dates accordingly.") ) diff --git a/erpnext/assets/doctype/asset_repair/test_asset_repair.py b/erpnext/assets/doctype/asset_repair/test_asset_repair.py index 0a9f1d7189a..0e4ea84df86 100644 --- a/erpnext/assets/doctype/asset_repair/test_asset_repair.py +++ b/erpnext/assets/doctype/asset_repair/test_asset_repair.py @@ -4,7 +4,7 @@ import unittest import frappe from frappe.tests import IntegrationTestCase -from frappe.utils import add_months, flt, get_first_day, nowdate, nowtime, today +from frappe.utils import add_days, add_months, flt, get_first_day, nowdate, nowtime, today from erpnext.assets.doctype.asset.asset import ( get_asset_account, @@ -388,6 +388,7 @@ def create_asset_repair(**args): if args.submit: asset_repair.repair_status = "Completed" + asset_repair.completion_date = add_days(args.failure_date, 1) asset_repair.cost_center = frappe.db.get_value("Company", asset.company, "cost_center") if args.stock_consumption: