Skip to content

Commit

Permalink
fix: Set available-for-use date if missing (#30838)
Browse files Browse the repository at this point in the history
  • Loading branch information
GangaManoj committed May 6, 2022
1 parent e9e2dcc commit bf2eaec
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 28 deletions.
62 changes: 34 additions & 28 deletions erpnext/assets/doctype/asset_repair/asset_repair.py
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down
1 change: 1 addition & 0 deletions erpnext/patches.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
22 changes: 22 additions & 0 deletions erpnext/patches/v13_0/set_available_for_use_date_if_missing.py
Original file line number Diff line number Diff line change
@@ -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"]
)

0 comments on commit bf2eaec

Please sign in to comment.