Merge pull request #21017 from Alchez/dev-remove-same-item-validation
feat: allow BOM to use same item as raw material (develop)
This commit is contained in:
commit
7845961d46
@ -43,8 +43,7 @@ frappe.ui.form.on("BOM", {
|
||||
|
||||
frm.set_query("item_code", "items", function() {
|
||||
return {
|
||||
query: "erpnext.controllers.queries.item_query",
|
||||
filters: [["Item", "name", "!=", cur_frm.doc.item]]
|
||||
query: "erpnext.controllers.queries.item_query"
|
||||
};
|
||||
});
|
||||
|
||||
|
@ -114,10 +114,6 @@ class BOM(WebsiteGenerator):
|
||||
child = self.append('operations', d)
|
||||
child.hour_rate = flt(d.hour_rate / self.conversion_rate, 2)
|
||||
|
||||
def validate_rm_item(self, item):
|
||||
if (item[0]['name'] in [it.item_code for it in self.items]) and item[0]['name'] == self.item:
|
||||
frappe.throw(_("BOM #{0}: Raw material cannot be same as main Item").format(self.name))
|
||||
|
||||
def set_bom_material_details(self):
|
||||
for item in self.get("items"):
|
||||
self.validate_bom_currecny(item)
|
||||
@ -147,7 +143,6 @@ class BOM(WebsiteGenerator):
|
||||
args = json.loads(args)
|
||||
|
||||
item = self.get_item_det(args['item_code'])
|
||||
self.validate_rm_item(item)
|
||||
|
||||
args['bom_no'] = args['bom_no'] or item and cstr(item[0]['default_bom']) or ''
|
||||
args['transfer_for_manufacture'] = (cstr(args.get('include_item_in_manufacturing', '')) or
|
||||
|
@ -552,24 +552,33 @@ class WorkOrder(Document):
|
||||
d.db_set('transferred_qty', flt(transferred_qty), update_modified = False)
|
||||
|
||||
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:
|
||||
consumed_qty = frappe.db.sql('''select sum(qty)
|
||||
from `tabStock Entry` entry, `tabStock Entry Detail` detail
|
||||
where
|
||||
for item in self.required_items:
|
||||
consumed_qty = frappe.db.sql('''
|
||||
SELECT
|
||||
SUM(qty)
|
||||
FROM
|
||||
`tabStock Entry` entry,
|
||||
`tabStock Entry Detail` detail
|
||||
WHERE
|
||||
entry.work_order = %(name)s
|
||||
and (entry.purpose = "Material Consumption for Manufacture"
|
||||
or entry.purpose = "Manufacture")
|
||||
and entry.docstatus = 1
|
||||
and detail.parent = entry.name
|
||||
and (detail.item_code = %(item)s or detail.original_item = %(item)s)''', {
|
||||
AND (entry.purpose = "Material Consumption for Manufacture"
|
||||
OR entry.purpose = "Manufacture")
|
||||
AND entry.docstatus = 1
|
||||
AND detail.parent = entry.name
|
||||
AND detail.s_warehouse IS NOT null
|
||||
AND (detail.item_code = %(item)s
|
||||
OR detail.original_item = %(item)s)
|
||||
''', {
|
||||
'name': self.name,
|
||||
'item': d.item_code
|
||||
'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):
|
||||
data = frappe.db.sql(""" select sed.item_code, sed.qty, sed.s_warehouse
|
||||
|
@ -238,7 +238,7 @@ class StockEntry(StockController):
|
||||
if self.purpose == "Manufacture" and self.work_order:
|
||||
production_item = frappe.get_value('Work Order', self.work_order, 'production_item')
|
||||
for item in self.items:
|
||||
if item.item_code == production_item and item.qty != self.fg_completed_qty:
|
||||
if item.item_code == production_item and item.t_warehouse and item.qty != self.fg_completed_qty:
|
||||
frappe.throw(_("Finished product quantity <b>{0}</b> and For Quantity <b>{1}</b> cannot be different")
|
||||
.format(item.qty, self.fg_completed_qty))
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user