fix(manufacturing): keep MPS cumulative lead-time fractional across engines

get_item_lead_time in Master Production Schedule computes
manufacturing_time_in_mins / 1440 + purchase_time + buffer_time. As in the
MRP report, manufacturing_time_in_mins is an Int column and 1440 an int
literal, so the division truncates on PostgreSQL (720/1440 -> 0) while
MariaDB yields 0.5. The value is summed over the BOM tree, ceil'd, and
drives the planned order-release date, so it diverged by engine.

Use a float numerator (1440.0). MariaDB output is unchanged; PostgreSQL
now matches it.
This commit is contained in:
Mihir Kandoi
2026-06-23 10:37:21 +05:30
parent b0b20edd3e
commit 28b5efcbe1
2 changed files with 27 additions and 2 deletions

View File

@@ -453,7 +453,7 @@ def get_item_lead_time(item_code):
query = (
frappe.qb.from_(doctype)
.select(
((doctype.manufacturing_time_in_mins / 1440) + doctype.purchase_time + doctype.buffer_time).as_(
((doctype.manufacturing_time_in_mins / 1440.0) + doctype.purchase_time + doctype.buffer_time).as_(
"cumulative_lead_time"
)
)

View File

@@ -1,4 +1,29 @@
# Copyright (c) 2025, Frappe Technologies Pvt. Ltd. and Contributors
# See license.txt
# import frappe
import frappe
from erpnext.manufacturing.doctype.master_production_schedule.master_production_schedule import (
get_item_lead_time,
)
from erpnext.stock.doctype.item.test_item import make_item
from erpnext.tests.utils import ERPNextTestSuite
class TestMasterProductionSchedule(ERPNextTestSuite):
def test_cumulative_lead_time_is_not_int_truncated(self):
"""cumulative_lead_time = manufacturing_time_in_mins / 1440 + purchase_time + buffer_time.
manufacturing_time_in_mins is an Int column; integer/integer division truncates on
PostgreSQL (720/1440 -> 0) while MariaDB yields 0.5, changing the planned release date."""
item = make_item("_Test MPS Lead Time Item", {"is_stock_item": 1}).name
frappe.get_doc(
{
"doctype": "Item Lead Time",
"item_code": item,
"manufacturing_time_in_mins": 720,
"purchase_time": 0,
"buffer_time": 0,
}
).insert()
# 720 / 1440 = 0.5; a truncating integer division on PostgreSQL would give 0.
self.assertAlmostEqual(float(get_item_lead_time(item)), 0.5, places=2)