From 00102a15e3870888bcf74a5215141e77d1aaf8b0 Mon Sep 17 00:00:00 2001 From: Rohit Waghchaure Date: Thu, 2 Jan 2025 09:44:32 +0530 Subject: [PATCH] fix: BOM cost update issue (cherry picked from commit 28ea3ddd51e3ec3c0043722b5477386a77b5357e) --- .../doctype/bom_update_tool/bom_update_tool.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/erpnext/manufacturing/doctype/bom_update_tool/bom_update_tool.py b/erpnext/manufacturing/doctype/bom_update_tool/bom_update_tool.py index 2e8dba1ccfe..983dd2d4cd8 100644 --- a/erpnext/manufacturing/doctype/bom_update_tool/bom_update_tool.py +++ b/erpnext/manufacturing/doctype/bom_update_tool/bom_update_tool.py @@ -9,6 +9,7 @@ if TYPE_CHECKING: import frappe from frappe.model.document import Document +from frappe.utils import date_diff, get_datetime, now class BOMUpdateTool(Document): @@ -50,13 +51,21 @@ def auto_update_latest_price_in_all_boms() -> None: if frappe.db.get_single_value("Manufacturing Settings", "update_bom_costs_automatically"): wip_log = frappe.get_all( "BOM Update Log", - {"update_type": "Update Cost", "status": ["in", ["Queued", "In Progress"]]}, + fields=["creation", "status"], + filters={"update_type": "Update Cost", "status": ["in", ["Queued", "In Progress"]]}, limit_page_length=1, + order_by="creation desc", ) - if not wip_log: + + if not wip_log or is_older_log(wip_log[0]): create_bom_update_log(update_type="Update Cost") +def is_older_log(log: dict) -> bool: + no_of_days = date_diff(get_datetime(now()), get_datetime(log.creation)) + return no_of_days > 10 + + def create_bom_update_log( boms: dict[str, str] | None = None, update_type: Literal["Replace BOM", "Update Cost"] = "Replace BOM",