Browse Source

Merge pull request #26521 from rohitwaghchaure/fixed-fg-items-not-added-for-batch-item-develop

fix: FG item not fetched in manufacture entry
develop
rohitwaghchaure 3 years ago
committed by GitHub
parent
commit
9ed36627d2
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 54
      erpnext/manufacturing/doctype/work_order/test_work_order.py
  2. 22
      erpnext/stock/doctype/stock_entry/stock_entry.py

54
erpnext/manufacturing/doctype/work_order/test_work_order.py

@ -513,6 +513,60 @@ class TestWorkOrder(unittest.TestCase):
work_order1.save()
self.assertEqual(work_order1.operations[0].time_in_mins, 40.0)
def test_batch_size_for_fg_item(self):
fg_item = "Test Batch Size Item For BOM 3"
rm1 = "Test Batch Size Item RM 1 For BOM 3"
frappe.db.set_value('Manufacturing Settings', None, 'make_serial_no_batch_from_work_order', 0)
for item in ["Test Batch Size Item For BOM 3", "Test Batch Size Item RM 1 For BOM 3"]:
item_args = {
"include_item_in_manufacturing": 1,
"is_stock_item": 1
}
if item == fg_item:
item_args['has_batch_no'] = 1
item_args['create_new_batch'] = 1
item_args['batch_number_series'] = 'TBSI3.#####'
make_item(item, item_args)
bom_name = frappe.db.get_value("BOM",
{"item": fg_item, "is_active": 1, "with_operations": 1}, "name")
if not bom_name:
bom = make_bom(item=fg_item, rate=1000, raw_materials = [rm1], do_not_save=True)
bom.save()
bom.submit()
bom_name = bom.name
work_order = make_wo_order_test_record(item=fg_item, skip_transfer=True, planned_start_date=now(), qty=1)
ste1 = frappe.get_doc(make_stock_entry(work_order.name, "Manufacture", 1))
for row in ste1.get('items'):
if row.is_finished_item:
self.assertEqual(row.item_code, fg_item)
work_order = make_wo_order_test_record(item=fg_item, skip_transfer=True, planned_start_date=now(), qty=1)
frappe.db.set_value('Manufacturing Settings', None, 'make_serial_no_batch_from_work_order', 1)
ste1 = frappe.get_doc(make_stock_entry(work_order.name, "Manufacture", 1))
for row in ste1.get('items'):
if row.is_finished_item:
self.assertEqual(row.item_code, fg_item)
work_order = make_wo_order_test_record(item=fg_item, skip_transfer=True, planned_start_date=now(),
qty=30, do_not_save = True)
work_order.batch_size = 10
work_order.insert()
work_order.submit()
self.assertEqual(work_order.has_batch_no, 1)
ste1 = frappe.get_doc(make_stock_entry(work_order.name, "Manufacture", 30))
for row in ste1.get('items'):
if row.is_finished_item:
self.assertEqual(row.item_code, fg_item)
self.assertEqual(row.qty, 10)
frappe.db.set_value('Manufacturing Settings', None, 'make_serial_no_batch_from_work_order', 0)
def test_partial_material_consumption(self):
frappe.db.set_value("Manufacturing Settings", None, "material_consumption", 1)
wo_order = make_wo_order_test_record(planned_start_date=now(), qty=4)

22
erpnext/stock/doctype/stock_entry/stock_entry.py

@ -1090,13 +1090,13 @@ class StockEntry(StockController):
"is_finished_item": 1
}
if self.work_order and self.pro_doc.has_batch_no:
if self.work_order and self.pro_doc.has_batch_no and cint(frappe.db.get_single_value('Manufacturing Settings',
'make_serial_no_batch_from_work_order', cache=True)):
self.set_batchwise_finished_goods(args, item)
else:
self.add_finisged_goods(args, item)
self.add_finished_goods(args, item)
def set_batchwise_finished_goods(self, args, item):
qty = flt(self.fg_completed_qty)
filters = {
"reference_name": self.pro_doc.name,
"reference_doctype": self.pro_doc.doctype,
@ -1105,7 +1105,17 @@ class StockEntry(StockController):
fields = ["qty_to_produce as qty", "produced_qty", "name"]
for row in frappe.get_all("Batch", filters = filters, fields = fields, order_by="creation asc"):
data = frappe.get_all("Batch", filters = filters, fields = fields, order_by="creation asc")
if not data:
self.add_finished_goods(args, item)
else:
self.add_batchwise_finished_good(data, args, item)
def add_batchwise_finished_good(self, data, args, item):
qty = flt(self.fg_completed_qty)
for row in data:
batch_qty = flt(row.qty) - flt(row.produced_qty)
if not batch_qty:
continue
@ -1121,9 +1131,9 @@ class StockEntry(StockController):
args["qty"] = fg_qty
args["batch_no"] = row.name
self.add_finisged_goods(args, item)
self.add_finished_goods(args, item)
def add_finisged_goods(self, args, item):
def add_finished_goods(self, args, item):
self.add_to_stock_entry_detail({
item.name: args
}, bom_no = self.bom_no)

Loading…
Cancel
Save