diff --git a/erpnext/assets/doctype/asset_repair/asset_repair.py b/erpnext/assets/doctype/asset_repair/asset_repair.py index 5bf6011cf805..94b4c641333b 100644 --- a/erpnext/assets/doctype/asset_repair/asset_repair.py +++ b/erpnext/assets/doctype/asset_repair/asset_repair.py @@ -41,40 +41,46 @@ def before_submit(self): if self.get("stock_consumption") or self.get("capitalize_repair_cost"): self.increase_asset_value() - if self.get("stock_consumption"): - self.check_for_stock_items_and_warehouse() - self.decrease_stock_quantity() - if self.get("capitalize_repair_cost"): - self.make_gl_entries() - if ( - frappe.db.get_value("Asset", self.asset, "calculate_depreciation") - and self.increase_in_asset_life - ): - self.modify_depreciation_schedule() - - self.asset_doc.flags.ignore_validate_update_after_submit = True - self.asset_doc.prepare_depreciation_data() - self.asset_doc.save() + + if self.get("stock_consumption"): + self.check_for_stock_items_and_warehouse() + self.decrease_stock_quantity() + + if self.get("capitalize_repair_cost"): + self.make_gl_entries() + + if ( + frappe.db.get_value("Asset", self.asset, "calculate_depreciation") + and self.increase_in_asset_life + ): + self.modify_depreciation_schedule() + + self.asset_doc.flags.ignore_validate_update_after_submit = True + self.asset_doc.prepare_depreciation_data() + self.asset_doc.save() def before_cancel(self): self.asset_doc = frappe.get_doc("Asset", self.asset) if self.get("stock_consumption") or self.get("capitalize_repair_cost"): self.decrease_asset_value() - if self.get("stock_consumption"): - self.increase_stock_quantity() - if self.get("capitalize_repair_cost"): - self.ignore_linked_doctypes = ("GL Entry", "Stock Ledger Entry") - self.make_gl_entries(cancel=True) - if ( - frappe.db.get_value("Asset", self.asset, "calculate_depreciation") - and self.increase_in_asset_life - ): - self.revert_depreciation_schedule_on_cancellation() - - self.asset_doc.flags.ignore_validate_update_after_submit = True - self.asset_doc.prepare_depreciation_data() - self.asset_doc.save() + + if self.get("stock_consumption"): + self.increase_stock_quantity() + + if self.get("capitalize_repair_cost"): + self.ignore_linked_doctypes = ("GL Entry", "Stock Ledger Entry") + self.make_gl_entries(cancel=True) + + if ( + frappe.db.get_value("Asset", self.asset, "calculate_depreciation") + and self.increase_in_asset_life + ): + self.revert_depreciation_schedule_on_cancellation() + + self.asset_doc.flags.ignore_validate_update_after_submit = True + self.asset_doc.prepare_depreciation_data() + self.asset_doc.save() def check_repair_status(self): if self.repair_status == "Pending": diff --git a/erpnext/patches.txt b/erpnext/patches.txt index d90a5e194887..5d95f824dce3 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -361,5 +361,6 @@ erpnext.patches.v13_0.update_expense_claim_status_for_paid_advances erpnext.patches.v13_0.change_default_item_manufacturer_fieldtype erpnext.patches.v13_0.set_return_against_in_pos_invoice_references erpnext.patches.v13_0.copy_custom_field_filters_to_website_item +erpnext.patches.v13_0.set_available_for_use_date_if_missing erpnext.patches.v13_0.education_deprecation_warning erpnext.patches.v13_0.create_accounting_dimensions_in_orders diff --git a/erpnext/patches/v13_0/set_available_for_use_date_if_missing.py b/erpnext/patches/v13_0/set_available_for_use_date_if_missing.py new file mode 100644 index 000000000000..3cfbd6e7fd05 --- /dev/null +++ b/erpnext/patches/v13_0/set_available_for_use_date_if_missing.py @@ -0,0 +1,22 @@ +import frappe + + +def execute(): + """ + Sets available-for-use date for Assets created in older versions of ERPNext, + before the field was introduced. + """ + + assets = get_assets_without_available_for_use_date() + + for asset in assets: + frappe.db.set_value("Asset", asset.name, "available_for_use_date", asset.purchase_date) + +def get_assets_without_available_for_use_date(): + return frappe.get_all( + "Asset", + filters = { + "available_for_use_date": ["in", ["", None]] + }, + fields = ["name", "purchase_date"] + )