Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"collapsible": 0,
"columns": 0,
"default": null,
"dt": "BOM Scrap Item",
"dt": "BOM Secondary Item",
"fetch_if_empty": 0,
"fieldname": "create_handling_unit",
"fieldtype": "Check",
Expand All @@ -28,7 +28,7 @@
"label": "Create Handling Unit",
"length": 0,
"module": "BEAM",
"name": "BOM Scrap Item-create_handling_unit",
"name": "BOM Secondary Item-create_handling_unit",
"no_copy": 0,
"non_negative": 0,
"permlevel": 0,
Expand All @@ -43,7 +43,7 @@
"unique": 0
}
],
"doctype": "BOM Scrap Item",
"doctype": "BOM Secondary Item",
"property_setters": [],
"sync_on_migrate": 1
}
10 changes: 6 additions & 4 deletions beam/beam/handling_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,11 @@ def generate_handling_units(doc, method=None):
handling_unit.save()
row.handling_unit = handling_unit.name

if doc.doctype == "Stock Entry" and doc.purpose == "Manufacture" and row.is_scrap_item:
if doc.doctype == "Stock Entry" and doc.purpose == "Manufacture" and row.type == "Scrap":
create_handling_unit = frappe.get_value(
"BOM Scrap Item", {"item_code": row.item_code, "parent": doc.bom_no}, "create_handling_unit"
"BOM Secondary Item",
{"item_code": row.item_code, "parent": doc.bom_no, "type": "Scrap"},
"create_handling_unit",
)
if bool(create_handling_unit):
handling_unit = frappe.new_doc("Handling Unit")
Expand All @@ -68,7 +70,7 @@ def generate_handling_units(doc, method=None):
continue

if doc.doctype == "Stock Entry" and not (
any([row.is_finished_item, doc.purpose == "Material Receipt", row.is_scrap_item])
any([row.is_finished_item, doc.purpose == "Material Receipt", row.type == "Scrap"])
):
continue

Expand Down Expand Up @@ -119,7 +121,7 @@ def validate_handling_unit_overconsumption(doc, method=None):
if (
abs(hu.stock_qty - row.get(qty_field)) > 0.0
and (hu.stock_qty - row.get(qty_field) > precision_denominator)
and not row.is_scrap_item
and row.type != "Scrap"
):
error = True
else: # incoming and transfer / same warehouse
Expand Down
8 changes: 4 additions & 4 deletions beam/beam/overrides/stock_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,15 +172,15 @@ def validate_items_with_handling_unit(doc, method=None):
for row in doc.items:
if not frappe.get_value("Item", row.item_code, "enable_handling_unit"):
continue
elif row.is_scrap_item and not frappe.get_value(
"BOM Scrap Item",
{"item_code": row.item_code, "parent": doc.get("bom_no")},
elif row.type == "Scrap" and not frappe.get_value(
"BOM Secondary Item",
{"item_code": row.item_code, "parent": doc.get("bom_no"), "type": "Scrap"},
"create_handling_unit",
):
continue
elif (
doc.stock_entry_type in ("Repack", "Manufacture")
and not (row.t_warehouse or row.is_finished_item or row.is_scrap_item)
and not (row.t_warehouse or row.is_finished_item or row.type == "Scrap")
and not row.handling_unit
):
frappe.throw(frappe._(f"Row #{row.idx}: Handling Unit is missing for item {row.item_code}"))
Expand Down
2 changes: 1 addition & 1 deletion beam/beam/scan/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def get_handling_unit(handling_unit: str, parent_doctype: str | None = None) ->
filters={"handling_unit": handling_unit, "is_cancelled": 0},
fields=[
"item_code",
"SUM(actual_qty) AS stock_qty",
{"SUM": "actual_qty", "as": "stock_qty"},
"company",
"handling_unit",
"voucher_no",
Expand Down
30 changes: 27 additions & 3 deletions beam/tests/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ def create_boms(settings):
b.append("operations", {**operation, "hour_rate": 15.00})
if bom.get("scrap_items"):
for scrap_item in bom.get("scrap_items"):
b.append("scrap_items", {**scrap_item})
b.append("secondary_items", {**scrap_item, "type": "Scrap"})
b.save()
b.submit()

Expand Down Expand Up @@ -477,14 +477,22 @@ def create_production_plan(settings, prod_plan_from_doc):
pp.get_mr_items()
for item in pp.po_items:
item.planned_start_date = settings.day
pp.skip_available_sub_assembly_item = 0
pp.get_sub_assembly_items()
for item in pp.sub_assembly_items:
item.schedule_date = settings.day
pp.for_warehouse = "Storeroom - APC"
raw_materials = get_items_for_material_requests(
pp.as_dict(), warehouses=None, get_parent_warehouse_data=None
)
combined_raw_materials = {}
for row in raw_materials:
item_code = row.get("item_code")
if item_code in combined_raw_materials:
combined_raw_materials[item_code]["quantity"] += row.get("quantity")
else:
combined_raw_materials[item_code] = row
for row in combined_raw_materials.values():
pp.append(
"mr_items",
{
Expand All @@ -497,9 +505,23 @@ def create_production_plan(settings, prod_plan_from_doc):
pp.save()
pp.submit()

pp.make_material_request()
mr = frappe.get_last_doc("Material Request")
mr = frappe.new_doc("Material Request")
mr.company = settings.company
mr.material_request_type = "Purchase"
mr.schedule_date = mr.transaction_date = settings.day
for row in combined_raw_materials.values():
mr.append(
"items",
{
"item_code": row.get("item_code"),
"qty": row.get("quantity"),
"uom": row.get("uom") or row.get("stock_uom"),
"warehouse": frappe.get_value(
"Item Default", {"parent": row.get("item_code")}, "default_warehouse"
),
"schedule_date": settings.day,
},
)
mr.save()
mr.submit()

Expand Down Expand Up @@ -547,6 +569,8 @@ def create_production_plan(settings, prod_plan_from_doc):
for wo in wos:
wo = frappe.get_doc("Work Order", wo)
wo.wip_warehouse = "Kitchen - APC"
if not wo.fg_warehouse:
wo.fg_warehouse = "Kitchen - APC"
wo.actual_start_date = wo.planned_start_date = start_time
wo.required_items = sorted(wo.required_items, key=lambda x: x.get("item_code"))
for idx, w in enumerate(wo.required_items, start=1):
Expand Down
10 changes: 6 additions & 4 deletions beam/tests/test_handling_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ def test_stock_entry_for_manufacture():
):
continue
if (
row.is_finished_item or row.is_scrap_item
row.is_finished_item or row.type == "Scrap"
): # finished and scrap items' handling units will be generated and wouldn't be scanned
continue
hu = frappe.get_value(
Expand All @@ -321,16 +321,18 @@ def test_stock_entry_for_manufacture():
sle = frappe.get_doc(
"Stock Ledger Entry", {"voucher_detail_no": row.name, "handling_unit": row.handling_unit}
)
if not row.is_finished_item and not row.is_scrap_item:
if not row.is_finished_item and row.type != "Scrap":
assert row.transfer_qty == -(sle.actual_qty)
assert row.item_code == sle.item_code
assert row.s_warehouse == sle.warehouse # source/ warehouse
assert sle.handling_unit == row.handling_unit
elif row.is_scrap_item:
elif row.type == "Scrap":
assert row.transfer_qty == sle.actual_qty
assert row.item_code == sle.item_code
create_handling_unit = frappe.get_value(
"BOM Scrap Item", {"item_code": row.item_code, "parent": _se.bom_no}, "create_handling_unit"
"BOM Secondary Item",
{"item_code": row.item_code, "parent": _se.bom_no, "type": "Scrap"},
"create_handling_unit",
)
if create_handling_unit:
assert row.handling_unit == sle.handling_unit
Expand Down
48 changes: 3 additions & 45 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading