mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-31 18:59:08 +00:00
Create Material Requests considering projected qty of items
This commit is contained in:
@@ -344,36 +344,56 @@ class ProductionPlanningTool(Document):
|
|||||||
self.make_items_dict(item_list)
|
self.make_items_dict(item_list)
|
||||||
|
|
||||||
def get_subitems(self,bom_wise_item_details, bom, parent_qty, include_sublevel, only_raw, supply_subs,non_stock_item=0):
|
def get_subitems(self,bom_wise_item_details, bom, parent_qty, include_sublevel, only_raw, supply_subs,non_stock_item=0):
|
||||||
for d in frappe.db.sql("""SELECT bom_item.item_code, default_material_request_type,
|
items = frappe.db.sql("""
|
||||||
ifnull(%(parent_qty)s * sum(bom_item.qty/ifnull(bom.quantity, 1)), 0) as qty,
|
SELECT
|
||||||
item.is_sub_contracted_item as is_sub_contracted, item.default_bom as default_bom,
|
bom_item.item_code,
|
||||||
bom_item.description as description, bom_item.stock_uom as stock_uom, item.min_order_qty
|
default_material_request_type,
|
||||||
as min_order_qty FROM `tabBOM Item` bom_item, `tabBOM` bom, tabItem item
|
ifnull(%(parent_qty)s * sum(bom_item.qty/ifnull(bom.quantity, 1)), 0) as qty,
|
||||||
where bom.name = bom_item.parent and bom.name = %(bom)s and bom_item.docstatus < 2
|
item.is_sub_contracted_item as is_sub_contracted,
|
||||||
and bom_item.item_code = item.name
|
item.default_bom as default_bom,
|
||||||
""" + ("and item.is_stock_item = 1","")[non_stock_item] + """
|
bom_item.description as description,
|
||||||
group by bom_item.item_code""", {"bom": bom, "parent_qty": parent_qty}, as_dict=1):
|
bom_item.stock_uom as stock_uom,
|
||||||
if (d.default_material_request_type == "Purchase" and not (d.is_sub_contracted \
|
item.min_order_qty as min_order_qty
|
||||||
and only_raw and include_sublevel)) or (d.default_material_request_type == \
|
FROM
|
||||||
"Manufacture" and not only_raw):
|
`tabBOM Item` bom_item,
|
||||||
|
`tabBOM` bom,
|
||||||
|
tabItem item
|
||||||
|
where
|
||||||
|
bom.name = bom_item.parent
|
||||||
|
and bom.name = %(bom)s
|
||||||
|
and bom_item.docstatus < 2
|
||||||
|
and bom_item.item_code = item.name
|
||||||
|
""" + ("and item.is_stock_item = 1", "")[non_stock_item] + """
|
||||||
|
group by bom_item.item_code""", {"bom": bom, "parent_qty": parent_qty}, as_dict=1)
|
||||||
|
|
||||||
|
for d in items:
|
||||||
|
if ((d.default_material_request_type == "Purchase"
|
||||||
|
and not (d.is_sub_contracted and only_raw and include_sublevel))
|
||||||
|
or (d.default_material_request_type == "Manufacture" and not only_raw)):
|
||||||
|
|
||||||
if d.item_code in bom_wise_item_details:
|
if d.item_code in bom_wise_item_details:
|
||||||
bom_wise_item_details[d.item_code].qty = bom_wise_item_details[d.item_code].qty\
|
bom_wise_item_details[d.item_code].qty = bom_wise_item_details[d.item_code].qty + d.qty
|
||||||
+ d.qty
|
|
||||||
else:
|
else:
|
||||||
bom_wise_item_details[d.item_code] = d
|
bom_wise_item_details[d.item_code] = d
|
||||||
|
|
||||||
if include_sublevel:
|
if include_sublevel:
|
||||||
if (d.default_material_request_type == "Purchase" and d.is_sub_contracted \
|
if ((d.default_material_request_type == "Purchase" and d.is_sub_contracted and supply_subs)
|
||||||
and supply_subs) or (d.default_material_request_type == "Manufacture"):
|
or (d.default_material_request_type == "Manufacture")):
|
||||||
|
|
||||||
my_qty = 0
|
my_qty = 0
|
||||||
|
projected_qty = self.get_item_projected_qty(d.item_code)
|
||||||
|
|
||||||
if self.create_material_requests_for_all_required_qty:
|
if self.create_material_requests_for_all_required_qty:
|
||||||
my_qty = d.qty
|
my_qty = d.qty
|
||||||
elif (bom_wise_item_details[d.item_code].qty - d.qty) < self.get_item_projected_qty(d.item_code):
|
elif (bom_wise_item_details[d.item_code].qty - d.qty) < projected_qty:
|
||||||
my_qty = bom_wise_item_details[d.item_code].qty - self.get_item_projected_qty(d.item_code)
|
my_qty = bom_wise_item_details[d.item_code].qty - projected_qty
|
||||||
else:
|
else:
|
||||||
my_qty = d.qty
|
my_qty = d.qty
|
||||||
|
|
||||||
if my_qty > 0:
|
if my_qty > 0:
|
||||||
self.get_subitems(bom_wise_item_details,d.default_bom, \
|
self.get_subitems(bom_wise_item_details,
|
||||||
my_qty, include_sublevel, only_raw, supply_subs)
|
d.default_bom, my_qty, include_sublevel, only_raw, supply_subs)
|
||||||
|
|
||||||
return bom_wise_item_details
|
return bom_wise_item_details
|
||||||
|
|
||||||
def make_items_dict(self, item_list):
|
def make_items_dict(self, item_list):
|
||||||
@@ -388,9 +408,12 @@ class ProductionPlanningTool(Document):
|
|||||||
item_list.append([item, self.item_dict[item][0][1], self.item_dict[item][0][2], total_qty])
|
item_list.append([item, self.item_dict[item][0][1], self.item_dict[item][0][2], total_qty])
|
||||||
item_qty = frappe.db.sql("""select warehouse, indented_qty, ordered_qty, actual_qty
|
item_qty = frappe.db.sql("""select warehouse, indented_qty, ordered_qty, actual_qty
|
||||||
from `tabBin` where item_code = %s""", item, as_dict=1)
|
from `tabBin` where item_code = %s""", item, as_dict=1)
|
||||||
|
|
||||||
i_qty, o_qty, a_qty = 0, 0, 0
|
i_qty, o_qty, a_qty = 0, 0, 0
|
||||||
for w in item_qty:
|
for w in item_qty:
|
||||||
i_qty, o_qty, a_qty = i_qty + flt(w.indented_qty), o_qty + flt(w.ordered_qty), a_qty + flt(w.actual_qty)
|
i_qty, o_qty, a_qty = i_qty + flt(w.indented_qty), o_qty + \
|
||||||
|
flt(w.ordered_qty), a_qty + flt(w.actual_qty)
|
||||||
|
|
||||||
item_list.append(['', '', '', '', w.warehouse, flt(w.indented_qty),
|
item_list.append(['', '', '', '', w.warehouse, flt(w.indented_qty),
|
||||||
flt(w.ordered_qty), flt(w.actual_qty)])
|
flt(w.ordered_qty), flt(w.actual_qty)])
|
||||||
if item_qty:
|
if item_qty:
|
||||||
@@ -460,10 +483,15 @@ class ProductionPlanningTool(Document):
|
|||||||
return items_to_be_requested
|
return items_to_be_requested
|
||||||
|
|
||||||
def get_item_projected_qty(self,item):
|
def get_item_projected_qty(self,item):
|
||||||
item_projected_qty = frappe.db.sql("""select ifnull(sum(projected_qty),0) as qty from `tabBin`
|
item_projected_qty = frappe.db.sql("""
|
||||||
where item_code = %(item_code)s and warehouse=%(warehouse)s""", \
|
select ifnull(sum(projected_qty),0) as qty
|
||||||
{"item_code":item, "warehouse": self.purchase_request_for_warehouse},as_dict=1)
|
from `tabBin`
|
||||||
#frappe.msgprint(item_projected_qty)
|
where item_code = %(item_code)s and warehouse=%(warehouse)s
|
||||||
|
""", {
|
||||||
|
"item_code": item,
|
||||||
|
"warehouse": self.purchase_request_for_warehouse
|
||||||
|
}, as_dict=1)
|
||||||
|
|
||||||
return item_projected_qty[0].qty
|
return item_projected_qty[0].qty
|
||||||
|
|
||||||
def get_projected_qty(self):
|
def get_projected_qty(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user