diff --git a/erpnext/assets/doctype/asset_repair/asset_repair.json b/erpnext/assets/doctype/asset_repair/asset_repair.json index accb5bf54b5..ef65296c728 100644 --- a/erpnext/assets/doctype/asset_repair/asset_repair.json +++ b/erpnext/assets/doctype/asset_repair/asset_repair.json @@ -76,6 +76,7 @@ "fieldname": "completion_date", "fieldtype": "Datetime", "label": "Completion Date", + "mandatory_depends_on": "eval:doc.repair_status==\"Completed\"", "no_copy": 1 }, { @@ -264,7 +265,11 @@ "index_web_pages_for_search": 1, "is_submittable": 1, "links": [], +<<<<<<< HEAD "modified": "2022-08-16 15:55:25.023471", +======= + "modified": "2025-07-29 15:14:34.044564", +>>>>>>> 5a82b723c2 (fix: post gl entry on completion date of asset repair) "modified_by": "Administrator", "module": "Assets", "name": "Asset Repair", @@ -302,6 +307,7 @@ "write": 1 } ], + "row_format": "Dynamic", "sort_field": "modified", "sort_order": "DESC", "states": [], diff --git a/erpnext/assets/doctype/asset_repair/asset_repair.py b/erpnext/assets/doctype/asset_repair/asset_repair.py index da933c96057..89e6f4a455f 100644 --- a/erpnext/assets/doctype/asset_repair/asset_repair.py +++ b/erpnext/assets/doctype/asset_repair/asset_repair.py @@ -20,6 +20,23 @@ class AssetRepair(AccountsController): self.set_stock_items_cost() self.calculate_total_repair_cost() +<<<<<<< HEAD +======= + def validate_asset(self): + if self.asset_doc.status in ("Sold", "Fully Depreciated", "Scrapped"): + frappe.throw( + _("Asset {0} is in {1} status and cannot be repaired.").format( + get_link_to_form("Asset", self.asset), self.asset_doc.status + ) + ) + + def validate_dates(self): + 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.") + ) + +>>>>>>> 5a82b723c2 (fix: post gl entry on completion date of asset repair) def update_status(self): if self.repair_status == "Pending": frappe.db.set_value("Asset", self.asset, "status", "Out of Order") @@ -195,7 +212,7 @@ class AssetRepair(AccountsController): "voucher_type": self.doctype, "voucher_no": self.name, "cost_center": self.cost_center, - "posting_date": getdate(), + "posting_date": self.completion_date, "against_voucher_type": "Purchase Invoice", "against_voucher": self.purchase_invoice, "company": self.company, @@ -214,7 +231,7 @@ class AssetRepair(AccountsController): "voucher_type": self.doctype, "voucher_no": self.name, "cost_center": self.cost_center, - "posting_date": getdate(), + "posting_date": self.completion_date, "company": self.company, }, item=self, @@ -248,7 +265,7 @@ class AssetRepair(AccountsController): "voucher_type": self.doctype, "voucher_no": self.name, "cost_center": self.cost_center, - "posting_date": getdate(), + "posting_date": self.completion_date, "company": self.company, }, item=self, @@ -265,7 +282,7 @@ class AssetRepair(AccountsController): "voucher_type": self.doctype, "voucher_no": self.name, "cost_center": self.cost_center, - "posting_date": getdate(), + "posting_date": self.completion_date, "against_voucher_type": "Stock Entry", "against_voucher": self.stock_entry, "company": self.company, diff --git a/erpnext/assets/doctype/asset_repair/test_asset_repair.py b/erpnext/assets/doctype/asset_repair/test_asset_repair.py index 274c1768179..c7bad5ee2ed 100644 --- a/erpnext/assets/doctype/asset_repair/test_asset_repair.py +++ b/erpnext/assets/doctype/asset_repair/test_asset_repair.py @@ -4,7 +4,11 @@ import unittest import frappe +<<<<<<< HEAD from frappe.utils import flt, nowdate +======= +from frappe.utils import add_days, add_months, flt, get_first_day, nowdate, nowtime, today +>>>>>>> 5a82b723c2 (fix: post gl entry on completion date of asset repair) from erpnext.assets.doctype.asset.asset import ( get_asset_account, @@ -288,6 +292,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: