fix: consumed qty values in work order

This commit is contained in:
Rohan 2020-03-26 15:26:47 +05:30
parent b7d84725e8
commit ea182051d3

View File

@ -552,24 +552,33 @@ class WorkOrder(Document):
d.db_set('transferred_qty', flt(transferred_qty), update_modified = False) d.db_set('transferred_qty', flt(transferred_qty), update_modified = False)
def update_consumed_qty_for_required_items(self): def update_consumed_qty_for_required_items(self):
'''update consumed qty from submitted stock entries for that item against '''
the work order''' Update consumed qty from submitted stock entries
against a work order for each stock item
'''
for d in self.required_items: for item in self.required_items:
consumed_qty = frappe.db.sql('''select sum(qty) consumed_qty = frappe.db.sql('''
from `tabStock Entry` entry, `tabStock Entry Detail` detail SELECT
where SUM(qty)
FROM
`tabStock Entry` entry,
`tabStock Entry Detail` detail
WHERE
entry.work_order = %(name)s entry.work_order = %(name)s
and (entry.purpose = "Material Consumption for Manufacture" AND (entry.purpose = "Material Consumption for Manufacture"
or entry.purpose = "Manufacture") OR entry.purpose = "Manufacture")
and entry.docstatus = 1 AND entry.docstatus = 1
and detail.parent = entry.name AND detail.parent = entry.name
and (detail.item_code = %(item)s or detail.original_item = %(item)s)''', { AND detail.s_warehouse IS NOT null
'name': self.name, AND (detail.item_code = %(item)s
'item': d.item_code OR detail.original_item = %(item)s)
})[0][0] ''', {
'name': self.name,
'item': item.item_code
})[0][0]
d.db_set('consumed_qty', flt(consumed_qty), update_modified = False) item.db_set('consumed_qty', flt(consumed_qty), update_modified=False)
def make_bom(self): def make_bom(self):
data = frappe.db.sql(""" select sed.item_code, sed.qty, sed.s_warehouse data = frappe.db.sql(""" select sed.item_code, sed.qty, sed.s_warehouse