mirror of
https://github.com/frappe/erpnext.git
synced 2026-04-12 03:15:07 +00:00
fix: process loss with bom path disassembly
(cherry picked from commit 93ad48bc1b)
# Conflicts:
# erpnext/manufacturing/doctype/work_order/test_work_order.py
This commit is contained in:
@@ -3,8 +3,13 @@
|
||||
|
||||
|
||||
import frappe
|
||||
<<<<<<< HEAD
|
||||
from frappe.tests.utils import FrappeTestCase, change_settings, timeout
|
||||
from frappe.utils import add_days, add_months, add_to_date, cint, flt, now, today
|
||||
=======
|
||||
from frappe.tests import timeout
|
||||
from frappe.utils import add_days, add_months, add_to_date, cint, flt, now, nowdate, nowtime, today
|
||||
>>>>>>> 93ad48bc1b (fix: process loss with bom path disassembly)
|
||||
|
||||
from erpnext.manufacturing.doctype.job_card.job_card import JobCardCancelError
|
||||
from erpnext.manufacturing.doctype.job_card.job_card import make_stock_entry as make_stock_entry_from_jc
|
||||
@@ -2633,6 +2638,36 @@ class TestWorkOrder(FrappeTestCase):
|
||||
msg=f"Raw material {bom_item.item_code} qty mismatch",
|
||||
)
|
||||
|
||||
# -- BOM-path disassembly (no source_stock_entry, no work_order) --
|
||||
bom_disassemble_qty = 2
|
||||
bom_se = frappe.get_doc(
|
||||
{
|
||||
"doctype": "Stock Entry",
|
||||
"stock_entry_type": "Disassemble",
|
||||
"purpose": "Disassemble",
|
||||
"from_bom": 1,
|
||||
"bom_no": bom.name,
|
||||
"fg_completed_qty": bom_disassemble_qty,
|
||||
"from_warehouse": wo.fg_warehouse,
|
||||
"to_warehouse": wo.wip_warehouse,
|
||||
"company": wo.company,
|
||||
"posting_date": nowdate(),
|
||||
"posting_time": nowtime(),
|
||||
}
|
||||
)
|
||||
bom_se.get_items()
|
||||
bom_se.save()
|
||||
bom_se.submit()
|
||||
|
||||
bom_scrap_row = next((i for i in bom_se.items if i.item_code == scrap_item), None)
|
||||
self.assertIsNotNone(bom_scrap_row, "Scrap item must appear in BOM-path disassembly")
|
||||
# Without fix 3: qty = 10 * 2 = 20; with fix 3 (process_loss_per=10%): qty = 9 * 2 = 18
|
||||
self.assertEqual(
|
||||
bom_scrap_row.qty,
|
||||
18,
|
||||
f"BOM-path disassembly must apply process_loss_per; expected 18, got {bom_scrap_row.qty}",
|
||||
)
|
||||
|
||||
def test_disassembly_with_additional_rm_not_in_bom(self):
|
||||
"""
|
||||
Test that SE-linked disassembly includes additional raw materials
|
||||
|
||||
@@ -2206,6 +2206,12 @@ class StockEntry(StockController):
|
||||
item["to_warehouse"] = ""
|
||||
item["is_finished_item"] = 0
|
||||
|
||||
if item.get("process_loss_per"):
|
||||
item["qty"] -= flt(
|
||||
item["qty"] * (item["process_loss_per"] / 100),
|
||||
self.precision("fg_completed_qty"),
|
||||
)
|
||||
|
||||
self.add_to_stock_entry_detail(secondary_items, bom_no=self.bom_no)
|
||||
|
||||
# Finished goods
|
||||
|
||||
Reference in New Issue
Block a user