From d9eb6e6b13c349c9e817576ecd532ad52b4432de Mon Sep 17 00:00:00 2001 From: GangaManoj Date: Thu, 28 Apr 2022 17:27:25 +0530 Subject: [PATCH 1/4] fix: Save asset on Repair submission only if stock_consumption or capitalize_repair_cost is checked --- .../doctype/asset_repair/asset_repair.py | 62 ++++++++++--------- 1 file changed, 34 insertions(+), 28 deletions(-) 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": From 9147f41b2c61087d9f78b84abba54552e0cc87de Mon Sep 17 00:00:00 2001 From: GangaManoj Date: Thu, 28 Apr 2022 17:44:36 +0530 Subject: [PATCH 2/4] fix: Set available-for-use date if missing --- .../set_available_for_use_date_if_missing.py | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 erpnext/patches/v13_0/set_available_for_use_date_if_missing.py 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..2c29878bf6bd --- /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": None + }, + fields = ["name", "purchase_date"] + ) From d5ce06703656664ecf1c6cd8f694417d2b29a382 Mon Sep 17 00:00:00 2001 From: GangaManoj Date: Thu, 28 Apr 2022 18:31:57 +0530 Subject: [PATCH 3/4] fix: Add patch to patches.txt --- erpnext/patches.txt | 3 ++- erpnext/patches/v13_0/set_available_for_use_date_if_missing.py | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/erpnext/patches.txt b/erpnext/patches.txt index 841c59b78a22..a0b9f7638d4d 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -359,4 +359,5 @@ erpnext.patches.v13_0.enable_ksa_vat_docs #1 erpnext.patches.v13_0.create_gst_custom_fields_in_quotation erpnext.patches.v13_0.update_expense_claim_status_for_paid_advances erpnext.patches.v13_0.set_return_against_in_pos_invoice_references -erpnext.patches.v13_0.copy_custom_field_filters_to_website_item \ No newline at end of file +erpnext.patches.v13_0.copy_custom_field_filters_to_website_item +erpnext.patches.v13_0.set_available_for_use_date_if_missing 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 index 2c29878bf6bd..03c098c4ef5e 100644 --- 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 @@ -16,7 +16,7 @@ def get_assets_without_available_for_use_date(): return frappe.get_all( "Asset", filters = { - "available_for_use_date": None + "available_for_use_date": ["in", ["", None]] }, fields = ["name", "purchase_date"] ) From 3b0113eb4854ef282fcdaf5790a7896a49cbdd50 Mon Sep 17 00:00:00 2001 From: GangaManoj Date: Thu, 28 Apr 2022 20:32:35 +0530 Subject: [PATCH 4/4] fix: Fix indentation for docstring --- .../patches/v13_0/set_available_for_use_date_if_missing.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 index 03c098c4ef5e..3cfbd6e7fd05 100644 --- 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 @@ -3,8 +3,8 @@ def execute(): """ - Sets available-for-use date for Assets created in older versions of ERPNext, - before the field was introduced. + 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()