Skip to content

Commit

Permalink
Merge pull request #42130 from frappe/mergify/bp/version-15-hotfix/pr…
Browse files Browse the repository at this point in the history
…-42105

fix: add auto-update for overdue status (backport #42105)
  • Loading branch information
khushi8112 authored Jul 2, 2024
2 parents 8b3ffc9 + 317cc03 commit 28e8bb7
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
9 changes: 6 additions & 3 deletions erpnext/assets/doctype/asset_maintenance/asset_maintenance.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ class AssetMaintenance(Document):
if TYPE_CHECKING:
from frappe.types import DF

from erpnext.assets.doctype.asset_maintenance_task.asset_maintenance_task import (
AssetMaintenanceTask,
)
from erpnext.assets.doctype.asset_maintenance_task.asset_maintenance_task import AssetMaintenanceTask

asset_category: DF.ReadOnly | None
asset_maintenance_tasks: DF.Table[AssetMaintenanceTask]
Expand All @@ -47,6 +45,11 @@ def on_update(self):
assign_tasks(self.name, task.assign_to, task.maintenance_task, task.next_due_date)
self.sync_maintenance_tasks()

def after_delete(self):
asset = frappe.get_doc("Asset", self.asset_name)
if asset.status == "In Maintenance":
asset.set_status()

def sync_maintenance_tasks(self):
tasks_names = []
for task in self.get("asset_maintenance_tasks"):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
import frappe
from frappe import _
from frappe.model.document import Document
from frappe.utils import getdate, nowdate
from frappe.query_builder import DocType
from frappe.utils import getdate, nowdate, today

from erpnext.assets.doctype.asset_maintenance.asset_maintenance import calculate_next_due_date

Expand Down Expand Up @@ -75,6 +76,17 @@ def update_maintenance_task(self):
asset_maintenance_doc.save()


def update_asset_maintenance_log_status():
AssetMaintenanceLog = DocType("Asset Maintenance Log")
(
frappe.qb.update(AssetMaintenanceLog)
.set(AssetMaintenanceLog.maintenance_status, "Overdue")
.where(
(AssetMaintenanceLog.maintenance_status == "Planned") & (AssetMaintenanceLog.due_date < today())
)
).run()


@frappe.whitelist()
@frappe.validate_and_sanitize_search_inputs
def get_maintenance_tasks(doctype, txt, searchfield, start, page_len, filters):
Expand Down
1 change: 1 addition & 0 deletions erpnext/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,7 @@
"erpnext.accounts.doctype.process_statement_of_accounts.process_statement_of_accounts.send_auto_email",
"erpnext.accounts.utils.auto_create_exchange_rate_revaluation_daily",
"erpnext.accounts.utils.run_ledger_health_checks",
"erpnext.assets.doctype.asset.asset_maintenance_log.update_asset_maintenance_log_status",
],
"weekly": [
"erpnext.accounts.utils.auto_create_exchange_rate_revaluation_weekly",
Expand Down

0 comments on commit 28e8bb7

Please sign in to comment.