fix: honor overproduction allowance in duplicate entry check

This commit is contained in:
Mihir Kandoi
2026-10-26 10:49:42 +00:00
parent 0a3b4e33d3
commit 310fe20bd8
2 changed files with 40 additions and 2 deletions
@@ -1273,7 +1273,13 @@ class StockEntry(StockController):
and ifnull(s_warehouse,'')='' """.format(", ".join(["%s" * len(other_ste)]), "%s"),
args,
)[0][0]
if fg_qty_already_entered and fg_qty_already_entered >= qty:
allowance_percentage = flt(
frappe.db.get_single_value(
"Manufacturing Settings", "overproduction_percentage_for_work_order"
)
)
allowed_qty = flt(qty) + (allowance_percentage / 100 * flt(qty))
if fg_qty_already_entered and fg_qty_already_entered >= allowed_qty:
frappe.throw(
_("Stock Entries already created for Work Order {0}: {1}").format(
self.work_order, ", ".join(other_ste)
@@ -30,7 +30,11 @@ from erpnext.stock.doctype.serial_and_batch_bundle.test_serial_and_batch_bundle
make_serial_batch_bundle,
)
from erpnext.stock.doctype.serial_no.serial_no import *
from erpnext.stock.doctype.stock_entry.stock_entry import FinishedGoodError, make_stock_in_entry
from erpnext.stock.doctype.stock_entry.stock_entry import (
DuplicateEntryForWorkOrderError,
FinishedGoodError,
make_stock_in_entry,
)
from erpnext.stock.doctype.stock_entry.stock_entry_utils import make_stock_entry
from erpnext.stock.doctype.stock_ledger_entry.stock_ledger_entry import StockFreezeError
from erpnext.stock.doctype.stock_reconciliation.stock_reconciliation import (
@@ -1966,6 +1970,34 @@ class TestStockEntry(FrappeTestCase):
se_ok.submit()
self.assertEqual(se_ok.docstatus, 1)
def test_duplicate_entry_for_work_order(self):
from erpnext.manufacturing.doctype.work_order.test_work_order import make_wo_order_test_record
from erpnext.manufacturing.doctype.work_order.work_order import (
make_stock_entry as make_wo_stock_entry,
)
wo = make_wo_order_test_record(qty=1)
make_stock_entry(item_code="_Test Item", target="Stores - _TC", qty=10, basic_rate=100)
make_stock_entry(
item_code="_Test Item Home Desktop 100", target="Stores - _TC", qty=10, basic_rate=100
)
transfer = frappe.get_doc(make_wo_stock_entry(wo.name, "Material Transfer for Manufacture", 1))
for d in transfer.get("items"):
d.s_warehouse = "Stores - _TC"
transfer.insert()
transfer.submit()
mfg = frappe.get_doc(make_wo_stock_entry(wo.name, "Manufacture", 1))
mfg.insert()
duplicate = frappe.get_doc(make_wo_stock_entry(wo.name, "Manufacture", 1))
self.assertRaises(DuplicateEntryForWorkOrderError, duplicate.insert)
with change_settings("Manufacturing Settings", {"overproduction_percentage_for_work_order": 100}):
within_allowance = frappe.get_doc(make_wo_stock_entry(wo.name, "Manufacture", 1))
within_allowance.insert()
@change_settings("Stock Settings", {"action_if_quality_inspection_is_rejected": "Stop"})
def test_quality_inspection_required_for_manufacture(self):
from erpnext.controllers.stock_controller import (