fix: allow to make BOM against template item (#21146)
* fix: allow to make BOM against template item * Update queries.py Co-authored-by: Nabin Hait <nabinhait@gmail.com>
This commit is contained in:
parent
75ef458b34
commit
05ac7213b3
@ -179,6 +179,12 @@ def item_query(doctype, txt, searchfield, start, page_len, filters, as_dict=Fals
|
|||||||
# scan description only if items are less than 50000
|
# scan description only if items are less than 50000
|
||||||
description_cond = 'or tabItem.description LIKE %(txt)s'
|
description_cond = 'or tabItem.description LIKE %(txt)s'
|
||||||
|
|
||||||
|
extra_cond = " and tabItem.has_variants=0"
|
||||||
|
if (filters and isinstance(filters, dict)
|
||||||
|
and filters.get("doctype") == "BOM"):
|
||||||
|
extra_cond = ""
|
||||||
|
del filters["doctype"]
|
||||||
|
|
||||||
return frappe.db.sql("""select tabItem.name,
|
return frappe.db.sql("""select tabItem.name,
|
||||||
if(length(tabItem.item_name) > 40,
|
if(length(tabItem.item_name) > 40,
|
||||||
concat(substr(tabItem.item_name, 1, 40), "..."), item_name) as item_name,
|
concat(substr(tabItem.item_name, 1, 40), "..."), item_name) as item_name,
|
||||||
@ -188,11 +194,11 @@ def item_query(doctype, txt, searchfield, start, page_len, filters, as_dict=Fals
|
|||||||
{columns}
|
{columns}
|
||||||
from tabItem
|
from tabItem
|
||||||
where tabItem.docstatus < 2
|
where tabItem.docstatus < 2
|
||||||
and tabItem.has_variants=0
|
|
||||||
and tabItem.disabled=0
|
and tabItem.disabled=0
|
||||||
and (tabItem.end_of_life > %(today)s or ifnull(tabItem.end_of_life, '0000-00-00')='0000-00-00')
|
and (tabItem.end_of_life > %(today)s or ifnull(tabItem.end_of_life, '0000-00-00')='0000-00-00')
|
||||||
and ({scond} or tabItem.item_code IN (select parent from `tabItem Barcode` where barcode LIKE %(txt)s)
|
and ({scond} or tabItem.item_code IN (select parent from `tabItem Barcode` where barcode LIKE %(txt)s)
|
||||||
{description_cond})
|
{description_cond})
|
||||||
|
{extra_cond}
|
||||||
{fcond} {mcond}
|
{fcond} {mcond}
|
||||||
order by
|
order by
|
||||||
if(locate(%(_txt)s, name), locate(%(_txt)s, name), 99999),
|
if(locate(%(_txt)s, name), locate(%(_txt)s, name), 99999),
|
||||||
@ -203,6 +209,7 @@ def item_query(doctype, txt, searchfield, start, page_len, filters, as_dict=Fals
|
|||||||
key=searchfield,
|
key=searchfield,
|
||||||
columns=columns,
|
columns=columns,
|
||||||
scond=searchfields,
|
scond=searchfields,
|
||||||
|
extra_cond=extra_cond,
|
||||||
fcond=get_filters_cond(doctype, filters, conditions).replace('%', '%%'),
|
fcond=get_filters_cond(doctype, filters, conditions).replace('%', '%%'),
|
||||||
mcond=get_match_cond(doctype).replace('%', '%%'),
|
mcond=get_match_cond(doctype).replace('%', '%%'),
|
||||||
description_cond = description_cond),
|
description_cond = description_cond),
|
||||||
|
@ -29,7 +29,10 @@ frappe.ui.form.on("BOM", {
|
|||||||
|
|
||||||
frm.set_query("item", function() {
|
frm.set_query("item", function() {
|
||||||
return {
|
return {
|
||||||
query: "erpnext.controllers.queries.item_query"
|
query: "erpnext.controllers.queries.item_query",
|
||||||
|
filters: {
|
||||||
|
"doctype": "BOM"
|
||||||
|
}
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -119,23 +122,58 @@ frappe.ui.form.on("BOM", {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (frm.doc.__onload && frm.doc.__onload["has_variants"]) {
|
||||||
|
frm.set_intro(__('This is a Template BOM and will be used to make the work order for {0} of the item {1}',
|
||||||
|
[
|
||||||
|
`<a class="variants-intro">variants</a>`,
|
||||||
|
`<a href="#Form/Item/${frm.doc.item}">${frm.doc.item}</a>`,
|
||||||
|
]), true);
|
||||||
|
|
||||||
|
frm.$wrapper.find(".variants-intro").on("click", () => {
|
||||||
|
frappe.set_route("List", "Item", {"variant_of": frm.doc.item});
|
||||||
|
});
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
make_work_order: function(frm) {
|
make_work_order: function(frm) {
|
||||||
const fields = [{
|
const fields = [];
|
||||||
|
|
||||||
|
if (frm.doc.__onload && frm.doc.__onload["has_variants"]) {
|
||||||
|
fields.push({
|
||||||
|
fieldtype: 'Link',
|
||||||
|
label: __('Variant Item'),
|
||||||
|
fieldname: 'item',
|
||||||
|
options: "Item",
|
||||||
|
reqd: 1,
|
||||||
|
get_query: function() {
|
||||||
|
return {
|
||||||
|
query: "erpnext.controllers.queries.item_query",
|
||||||
|
filters: {
|
||||||
|
"variant_of": frm.doc.item
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
fields.push({
|
||||||
fieldtype: 'Float',
|
fieldtype: 'Float',
|
||||||
label: __('Qty To Manufacture'),
|
label: __('Qty To Manufacture'),
|
||||||
fieldname: 'qty',
|
fieldname: 'qty',
|
||||||
reqd: 1,
|
reqd: 1,
|
||||||
default: 1
|
default: 1
|
||||||
}];
|
});
|
||||||
|
|
||||||
frappe.prompt(fields, data => {
|
frappe.prompt(fields, data => {
|
||||||
|
let item = data.item || frm.doc.item;
|
||||||
|
|
||||||
frappe.call({
|
frappe.call({
|
||||||
method: "erpnext.manufacturing.doctype.work_order.work_order.make_work_order",
|
method: "erpnext.manufacturing.doctype.work_order.work_order.make_work_order",
|
||||||
args: {
|
args: {
|
||||||
bom_no: frm.doc.name,
|
bom_no: frm.doc.name,
|
||||||
item: frm.doc.item,
|
item: item,
|
||||||
qty: data.qty || 0.0,
|
qty: data.qty || 0.0,
|
||||||
project: frm.doc.project
|
project: frm.doc.project
|
||||||
},
|
},
|
||||||
|
@ -59,6 +59,10 @@ class BOM(WebsiteGenerator):
|
|||||||
|
|
||||||
self.name = name
|
self.name = name
|
||||||
|
|
||||||
|
def onload(self):
|
||||||
|
super(BOM, self).onload()
|
||||||
|
if self.get("item") and cint(frappe.db.get_value("Item", self.item, "has_variants")):
|
||||||
|
self.set_onload("has_variants", True)
|
||||||
|
|
||||||
def validate(self):
|
def validate(self):
|
||||||
self.route = frappe.scrub(self.name).replace('_', '-')
|
self.route = frappe.scrub(self.name).replace('_', '-')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user