feat(Production Plan): Consider Safety Stock in Required Qty Calculation

This commit is contained in:
Rucha Mahabal 2021-03-08 20:58:57 +05:30
parent f66aab6d98
commit efe2b425b1
3 changed files with 25 additions and 6 deletions

View File

@ -15,6 +15,7 @@
"uom",
"projected_qty",
"actual_qty",
"safety_stock",
"item_details",
"description",
"min_order_qty",
@ -129,11 +130,17 @@
"fieldtype": "Link",
"label": "From Warehouse",
"options": "Warehouse"
},
{
"fetch_from": "item_code.safety_stock",
"fieldname": "safety_stock",
"fieldtype": "Float",
"label": "Safety Stock"
}
],
"istable": 1,
"links": [],
"modified": "2020-02-03 12:22:29.913302",
"modified": "2021-03-08 18:39:17.553611",
"modified_by": "Administrator",
"module": "Manufacturing",
"name": "Material Request Plan Item",

View File

@ -32,6 +32,7 @@
"material_request_planning",
"include_non_stock_items",
"include_subcontracted_items",
"include_safety_stock",
"ignore_existing_ordered_qty",
"column_break_25",
"for_warehouse",
@ -309,13 +310,19 @@
"fieldtype": "Select",
"label": "Sales Order Status",
"options": "\nTo Deliver and Bill\nTo Bill\nTo Deliver"
},
{
"default": "0",
"fieldname": "include_safety_stock",
"fieldtype": "Check",
"label": "Include Safety Stock in Required Qty Calculation"
}
],
"icon": "fa fa-calendar",
"index_web_pages_for_search": 1,
"is_submittable": 1,
"links": [],
"modified": "2020-11-10 18:01:54.991970",
"modified": "2021-03-08 11:17:25.470147",
"modified_by": "Administrator",
"module": "Manufacturing",
"name": "Production Plan",

View File

@ -482,7 +482,7 @@ def get_subitems(doc, data, item_details, bom_no, company, include_non_stock_ite
ifnull(%(parent_qty)s * sum(bom_item.stock_qty/ifnull(bom.quantity, 1)) * %(planned_qty)s, 0) as qty,
item.is_sub_contracted_item as is_sub_contracted, bom_item.source_warehouse,
item.default_bom as default_bom, bom_item.description as description,
bom_item.stock_uom as stock_uom, item.min_order_qty as min_order_qty,
bom_item.stock_uom as stock_uom, item.min_order_qty as min_order_qty, item.safety_stock as safety_stock,
item_default.default_warehouse, item.purchase_uom, item_uom.conversion_factor
FROM
`tabBOM Item` bom_item
@ -518,8 +518,8 @@ def get_subitems(doc, data, item_details, bom_no, company, include_non_stock_ite
include_non_stock_items, include_subcontracted_items, d.qty)
return item_details
def get_material_request_items(row, sales_order,
company, ignore_existing_ordered_qty, warehouse, bin_dict):
def get_material_request_items(row, sales_order, company,
ignore_existing_ordered_qty, include_safety_stock, warehouse, bin_dict):
total_qty = row['qty']
required_qty = 0
@ -543,6 +543,9 @@ def get_material_request_items(row, sales_order,
if frappe.db.get_value("UOM", row['purchase_uom'], "must_be_whole_number"):
required_qty = ceil(required_qty)
if include_safety_stock:
required_qty += flt(row['safety_stock'])
if required_qty > 0:
return {
'item_code': row.item_code,
@ -660,6 +663,7 @@ def get_items_for_material_requests(doc, warehouses=None):
company = doc.get('company')
ignore_existing_ordered_qty = doc.get('ignore_existing_ordered_qty')
include_safety_stock = doc.get('include_safety_stock')
so_item_details = frappe._dict()
for data in po_items:
@ -711,6 +715,7 @@ def get_items_for_material_requests(doc, warehouses=None):
'description' : item_master.description,
'stock_uom' : item_master.stock_uom,
'conversion_factor' : conversion_factor,
'safety_stock': item_master.safety_stock
}
)
@ -732,7 +737,7 @@ def get_items_for_material_requests(doc, warehouses=None):
if details.qty > 0:
items = get_material_request_items(details, sales_order, company,
ignore_existing_ordered_qty, warehouse, bin_dict)
ignore_existing_ordered_qty, include_safety_stock, warehouse, bin_dict)
if items:
mr_items.append(items)