bom cleanup

This commit is contained in:
Nabin Hait 2012-12-14 14:25:51 +05:30
parent fce76cd5b2
commit 3adaf607f0
14 changed files with 170 additions and 153 deletions

View File

@ -17,9 +17,40 @@
// On REFRESH
cur_frm.cscript.refresh = function(doc,dt,dn){
cur_frm.toggle_enable("item", doc.__islocal);
if (!doc.__islocal && doc.docstatus==0) {
cur_frm.set_intro("Submit the BOM to use it in production");
} else cur_frm.set_intro("");
cur_frm.cscript.track_operations(doc);
set_operation_no(doc);
}
cur_frm.cscript.track_operations = function(doc) {
cur_frm.fields_dict["bom_materials"].grid.set_column_disp("operation_no", doc.track_operations);
cur_frm.fields_dict["bom_materials"].grid.toggle_reqd("operation_no", doc.track_operations)
}
cur_frm.cscript.operation_no = function(doc, cdt, cdn) {
var child = locals[cdt][cdn];
if(child.parentfield=="bom_operations") set_operation_no(doc);
}
var set_operation_no = function(doc) {
var op_table = getchildren('BOM Operation', doc.name, 'bom_operations');
var operations = [];
for (var i=0, j=op_table.length; i<j; i++) {
var op = op_table[i].operation_no;
if (op && !inList(operations, op)) operations.push(op);
}
cur_frm.fields_dict["bom_materials"].grid.get_field("operation_no")
.df.options = operations.join("\n");
refresh_field("bom_materials");
}
cur_frm.fields_dict["bom_operations"].grid.on_row_delete = function(cdt, cdn){
set_operation_no(doc);
}
cur_frm.cscript.item = function(doc, dt, dn) {
@ -28,7 +59,6 @@ cur_frm.cscript.item = function(doc, dt, dn) {
}
}
cur_frm.cscript.workstation = function(doc,dt,dn) {
var d = locals[dt][dn];
if (d.workstation) {
@ -167,11 +197,11 @@ cur_frm.fields_dict['bom_materials'].grid.get_field('item_code').get_query = fun
cur_frm.fields_dict['bom_materials'].grid.get_field('bom_no').get_query = function(doc, cdt, cdn) {
var d = locals[cdt][cdn];
msgprint('SELECT DISTINCT `tabBOM`.`name`, `tabBOM`.`remarks` FROM `tabBOM` \
WHERE `tabBOM`.`item` = "' + d.item_code + '" AND `tabBOM`.`is_active` = "Yes" AND \
WHERE `tabBOM`.`item` = "' + d.item_code + '" AND `tabBOM`.`is_active` = 1 AND \
`tabBOM`.docstatus = 1 AND `tabBOM`.`name` like "%s" \
ORDER BY `tabBOM`.`name` LIMIT 50');
return 'SELECT DISTINCT `tabBOM`.`name`, `tabBOM`.`remarks` FROM `tabBOM` \
WHERE `tabBOM`.`item` = "' + d.item_code + '" AND `tabBOM`.`is_active` = "Yes" AND \
WHERE `tabBOM`.`item` = "' + d.item_code + '" AND `tabBOM`.`is_active` = 1 AND \
`tabBOM`.docstatus = 1 AND `tabBOM`.`name` like "%s" \
ORDER BY `tabBOM`.`name` LIMIT 50';
}

View File

@ -108,7 +108,7 @@ class DocType:
def get_bom_unitcost(self, bom_no):
bom = sql("""select name, total_cost/quantity as unit_cost from `tabBOM`
where is_active = 'Yes' and name = %s""", bom_no, as_dict=1)
where is_active = 1 and name = %s""", bom_no, as_dict=1)
return bom and bom[0]['unit_cost'] or 0
def get_valuation_rate(self, arg):
@ -134,7 +134,7 @@ class DocType:
update default bom in item master
"""
if self.doc.is_default and self.doc.is_active == 'Yes':
if self.doc.is_default and self.doc.is_active:
sql("update `tabBOM` set is_default = 0 where name != %s and item=%s",
(self.doc.name, self.doc.item))
@ -178,7 +178,7 @@ class DocType:
check_list = []
for m in getlist(self.doclist, 'bom_materials'):
# check if operation no not in op table
if cstr(m.operation_no) not in self.op:
if self.doc.track_operations and cstr(m.operation_no) not in self.op:
msgprint("""Operation no: %s against item: %s at row no: %s \
is not present at Operations table""" %
(m.operation_no, m.item_code, m.idx), raise_exception = 1)
@ -207,7 +207,7 @@ class DocType:
def validate_bom_no(self, item, bom_no, idx):
"""Validate BOM No of sub-contracted items"""
bom = sql("""select name from `tabBOM` where name = %s and item = %s
and ifnull(is_active, 'No') = 'Yes' and docstatus < 2 """,
and is_active = 1 and docstatus < 2 """,
(bom_no, item), as_dict =1)
if not bom:
msgprint("""Incorrect BOM No: %s against item: %s at row no: %s.
@ -374,12 +374,12 @@ class DocType:
# check if used in any other bom
par = sql("""select t1.parent from `tabBOM Item` t1, `tabBOM` t2
where t1.parent = t2.name and t1.bom_no = %s and t1.docstatus = 1
and t2.is_active = 'Yes'""", self.doc.name)
and t2.is_active = 1""", self.doc.name)
if par:
msgprint("""BOM can not be cancelled, as it is a child item \
in following active BOM %s""" % [d[0] for d in par], raise_exception=1)
webnotes.conn.set(self.doc, "is_active", "No")
webnotes.conn.set(self.doc, "is_active", 0)
webnotes.conn.set(self.doc, "is_default", 0)
self.manage_default_bom()
self.update_cost_and_exploded_items(calculate_cost=False)
@ -391,9 +391,9 @@ class DocType:
def validate_inactive_bom(self):
if self.doc.is_active == 'No':
if not self.doc.is_active:
act_pbom = sql("""select distinct t1.parent from `tabBOM Item` t1, `tabBOM` t2
where t1.bom_no =%s and t2.name = t1.parent and t2.is_active = 'Yes'
where t1.bom_no =%s and t2.name = t1.parent and t2.is_active = 1
and t2.docstatus = 1 and t1.docstatus =1 """, self.doc.name)
if act_pbom and act_pbom[0][0]:
msgprint("""Sorry cannot inactivate as BOM: %s is child

View File

@ -2,9 +2,9 @@
{
"owner": "Administrator",
"docstatus": 0,
"creation": "2012-12-12 10:17:41",
"creation": "2012-12-14 10:15:15",
"modified_by": "Administrator",
"modified": "2012-12-13 11:48:39"
"modified": "2012-12-14 13:40:48"
},
{
"istable": 0,
@ -44,14 +44,6 @@
"name": "BOM",
"doctype": "DocType"
},
{
"oldfieldtype": "Column Break",
"doctype": "DocField",
"width": "50%",
"fieldname": "column_break0",
"fieldtype": "Column Break",
"permlevel": 0
},
{
"description": "Select the item code for which Bill of Material is being created",
"oldfieldtype": "Link",
@ -67,55 +59,15 @@
"options": "Item"
},
{
"description": "Total quantity of items for which raw materials required and operations done will be defined",
"default": "1",
"oldfieldtype": "Currency",
"doctype": "DocField",
"label": "Quantity",
"oldfieldname": "quantity",
"fieldname": "quantity",
"fieldtype": "Currency",
"reqd": 1,
"permlevel": 0
},
{
"doctype": "DocField",
"label": "Item UOM",
"options": "link:UOM",
"fieldname": "uom",
"fieldtype": "Select",
"permlevel": 1
},
{
"doctype": "DocField",
"width": "50%",
"fieldname": "column_break1",
"fieldname": "cb0",
"fieldtype": "Column Break",
"permlevel": 0
},
{
"permlevel": 0,
"no_copy": 1,
"oldfieldtype": "Select",
"allow_on_submit": 1,
"doctype": "DocField",
"label": "Is Active",
"oldfieldname": "is_active",
"default": "Yes",
"fieldname": "is_active",
"fieldtype": "Select",
"reqd": 1,
"hidden": 0,
"options": "\nYes\nNo"
},
{
"no_copy": 1,
"oldfieldtype": "Check",
"allow_on_submit": 1,
"doctype": "DocField",
"label": "Is Default",
"oldfieldname": "is_default",
"fieldname": "is_default",
"label": "Track Operations",
"fieldname": "track_operations",
"fieldtype": "Check",
"permlevel": 0
},
@ -123,12 +75,13 @@
"oldfieldtype": "Section Break",
"doctype": "DocField",
"label": "Operations",
"options": "Specify the operations, operating cost and give a unique Operation no to your operations.",
"fieldname": "operations",
"fieldtype": "Section Break",
"depends_on": "track_operations",
"permlevel": 0
},
{
"description": "Specify the operations, operating cost and give a unique Operation no to your operations.",
"oldfieldtype": "Table",
"doctype": "DocField",
"label": "BOM Operations",
@ -146,14 +99,6 @@
"fieldtype": "Section Break",
"permlevel": 0
},
{
"doctype": "DocField",
"label": "Consider Raw Material Cost As Per",
"options": "Valuation Rate\nLast Purchase Rate\nStandard Rate",
"fieldname": "rm_cost_as_per",
"fieldtype": "Select",
"permlevel": 0
},
{
"description": "Enter the raw materials required to manufacture the BOM item. Specify the operation no as entered in the previous tab which will be performed on the raw materials entered.",
"oldfieldtype": "Table",
@ -173,6 +118,27 @@
"fieldtype": "Section Break",
"permlevel": 0
},
{
"doctype": "DocField",
"label": "Consider Raw Material Cost As Per",
"options": "Valuation Rate\nLast Purchase Rate",
"fieldname": "rm_cost_as_per",
"fieldtype": "Select",
"permlevel": 0
},
{
"doctype": "DocField",
"label": "Total Cost",
"fieldname": "total_cost",
"fieldtype": "Float",
"permlevel": 1
},
{
"doctype": "DocField",
"fieldname": "cb1",
"fieldtype": "Column Break",
"permlevel": 0
},
{
"doctype": "DocField",
"label": "Raw Material Cost",
@ -189,16 +155,35 @@
},
{
"doctype": "DocField",
"label": "Total Cost",
"fieldname": "total_cost",
"fieldtype": "Float",
"label": "More Info",
"fieldname": "more_info_section",
"fieldtype": "Section Break",
"permlevel": 0
},
{
"description": "Total quantity of items for which raw materials required and operations done will be defined",
"default": "1",
"oldfieldtype": "Currency",
"doctype": "DocField",
"label": "Quantity",
"oldfieldname": "quantity",
"fieldname": "quantity",
"fieldtype": "Currency",
"reqd": 1,
"permlevel": 0
},
{
"doctype": "DocField",
"label": "Item UOM",
"options": "link:UOM",
"fieldname": "uom",
"fieldtype": "Select",
"permlevel": 1
},
{
"doctype": "DocField",
"label": "More Info",
"fieldname": "more_info_section",
"fieldtype": "Section Break",
"fieldname": "col_break23",
"fieldtype": "Column Break",
"permlevel": 0
},
{
@ -214,18 +199,28 @@
"in_filter": 1
},
{
"oldfieldtype": "Data",
"no_copy": 1,
"oldfieldtype": "Select",
"allow_on_submit": 1,
"doctype": "DocField",
"label": "Maintained By",
"oldfieldname": "maintained_by",
"fieldname": "maintained_by",
"fieldtype": "Data",
"label": "Is Active",
"oldfieldname": "is_active",
"default": "1",
"fieldname": "is_active",
"fieldtype": "Check",
"reqd": 1,
"hidden": 0,
"permlevel": 0
},
{
"no_copy": 1,
"oldfieldtype": "Check",
"allow_on_submit": 1,
"doctype": "DocField",
"fieldname": "col_break23",
"fieldtype": "Column Break",
"label": "Is Default",
"oldfieldname": "is_default",
"fieldname": "is_default",
"fieldtype": "Check",
"permlevel": 0
},
{
@ -238,27 +233,6 @@
"fieldtype": "Link",
"permlevel": 1
},
{
"print_hide": 1,
"description": "The date at which current entry is corrected in the system.",
"no_copy": 1,
"depends_on": "eval:doc.amended_from",
"doctype": "DocField",
"label": "Amendment Date",
"fieldname": "amendment_date",
"fieldtype": "Date",
"permlevel": 0
},
{
"no_copy": 1,
"oldfieldtype": "Text",
"doctype": "DocField",
"label": "Remarks",
"oldfieldname": "remarks",
"fieldname": "remarks",
"fieldtype": "Small Text",
"permlevel": 0
},
{
"print_hide": 0,
"depends_on": "eval:!doc.__islocal",
@ -284,6 +258,17 @@
"hidden": 0,
"options": "BOM Explosion Item"
},
{
"print_hide": 1,
"description": "The date at which current entry is corrected in the system.",
"no_copy": 1,
"depends_on": "eval:doc.amended_from",
"doctype": "DocField",
"label": "Amendment Date",
"fieldname": "amendment_date",
"fieldtype": "Date",
"permlevel": 0
},
{
"create": 1,
"doctype": "DocPerm",

View File

@ -17,7 +17,7 @@ wn.doclistviews['BOM'] = wn.views.ListView.extend({
prepare_data: function(data) {
this._super(data);
data.costing_date = wn.datetime.str_to_user(data.costing_date);
data.description = (data.is_active === 'Yes' ? '' : '[Inactive] ') + data.description;
data.description = (data.is_active ? '' : '[Inactive] ') + data.description;
},
columns: [

View File

@ -2,20 +2,15 @@
{
"owner": "Administrator",
"docstatus": 0,
"creation": "2012-03-27 14:36:02",
"creation": "2012-12-14 10:15:16",
"modified_by": "Administrator",
"modified": "2012-12-10 18:30:00"
"modified": "2012-12-14 13:11:49"
},
{
"section_style": "Simple",
"istable": 1,
"name": "__common__",
"colour": "White:FFF",
"module": "Manufacturing",
"show_in_menu": 0,
"version": 27,
"server_code_error": " ",
"doctype": "DocType"
"doctype": "DocType",
"module": "Manufacturing"
},
{
"name": "__common__",
@ -37,36 +32,26 @@
"name": "BOM Item",
"doctype": "DocType"
},
{
"write": 1,
"permlevel": 0,
"doctype": "DocPerm"
},
{
"permlevel": 1,
"doctype": "DocPerm"
},
{
"oldfieldtype": "Data",
"doctype": "DocField",
"label": "Operation No",
"oldfieldname": "operation_no",
"fieldname": "operation_no",
"fieldtype": "Data",
"reqd": 1,
"fieldtype": "Select",
"reqd": 0,
"permlevel": 0
},
{
"search_index": 1,
"oldfieldtype": "Link",
"doctype": "DocField",
"label": "Item Code",
"oldfieldname": "item_code",
"trigger": "Client",
"options": "Item",
"fieldname": "item_code",
"fieldtype": "Link",
"oldfieldtype": "Link",
"search_index": 1,
"reqd": 1,
"options": "Item",
"permlevel": 0,
"in_filter": 1
},
@ -77,7 +62,6 @@
"label": "BOM No",
"oldfieldname": "bom_no",
"width": "150px",
"trigger": "Client",
"fieldname": "bom_no",
"fieldtype": "Link",
"search_index": 1,
@ -90,7 +74,6 @@
"doctype": "DocField",
"label": "Qty",
"oldfieldname": "qty",
"trigger": "Client",
"fieldname": "qty",
"fieldtype": "Float",
"reqd": 1,
@ -154,5 +137,14 @@
"fieldtype": "Float",
"hidden": 1,
"permlevel": 1
},
{
"write": 1,
"doctype": "DocPerm",
"permlevel": 0
},
{
"doctype": "DocPerm",
"permlevel": 1
}
]

View File

@ -102,8 +102,7 @@ cur_frm.cscript['Update Finished Goods'] = function() {
}
cur_frm.cscript.make_se = function(doc, process) {
var se = LocalDB.create('Stock Entry');
se = locals['Stock Entry'][se];
var se = wn.model.get_new_doc("Stock Entry");
se.purpose = 'Production Order';
se.process = process;
se.production_order = doc.name;

View File

@ -173,7 +173,7 @@ class DocType:
(d.item_code, d.idx), raise_exception=1)
else:
bom = sql("""select name from `tabBOM` where name = %s and item = %s
and docstatus = 1 and ifnull(is_active, 'No') = 'Yes'""",
and docstatus = 1 and is_active = 1""",
(d.bom_no, d.item_code), as_dict = 1)
if not bom:
msgprint("""Incorrect BOM No: %s entered for item: %s at row no: %s

View File

@ -2,9 +2,9 @@
{
"owner": "jai@webnotestech.com",
"docstatus": 0,
"creation": "2012-12-11 15:15:06",
"creation": "2012-12-14 10:15:16",
"modified_by": "Administrator",
"modified": "2012-12-11 16:13:59"
"modified": "2012-12-14 11:37:40"
},
{
"read_only": 1,
@ -148,15 +148,6 @@
"fieldtype": "Button",
"options": "clear_item_table"
},
{
"description": "If checked, BOM for sub-assembly items will be considered for getting raw materials. Otherwise, all sub-assembly items will be treated as a raw material.",
"default": "1",
"doctype": "DocField",
"label": "Use Multi-Level BOM",
"fieldname": "use_multi_level_bom",
"fieldtype": "Check",
"reqd": 0
},
{
"doctype": "DocField",
"fieldname": "section_break3",
@ -183,6 +174,15 @@
"fieldname": "column_break6",
"fieldtype": "Column Break"
},
{
"description": "If checked, BOM for sub-assembly items will be considered for getting raw materials. Otherwise, all sub-assembly items will be treated as a raw material.",
"default": "1",
"doctype": "DocField",
"label": "Use Multi-Level BOM",
"fieldname": "use_multi_level_bom",
"fieldtype": "Check",
"reqd": 0
},
{
"description": "Download a report containing all raw materials with their latest inventory status",
"doctype": "DocField",

View File

@ -4,12 +4,14 @@ def execute():
delete_doctypes()
rename_module()
rebuilt_exploded_bom()
cleanup_bom()
def delete_doctypes():
from webnotes.model import delete_doc
delete_doc("DocType", "Production Control")
delete_doc("DocType", "BOM Control")
def rename_module():
webnotes.reload_doc("core", "doctype", "role")
webnotes.reload_doc("core", "doctype", "page")
@ -38,3 +40,8 @@ def rebuilt_exploded_bom():
from webnotes.model.code import get_obj
for bom in webnotes.conn.sql("""select name from `tabBOM` where docstatus < 2"""):
get_obj("BOM", bom[0], with_children=1).on_update()
def cleanup_bom():
webnotes.conn.sql("""UPDATE `tabBOM` SET is_active = if(is_active='Yes', 1, 0),
track_operations = 1""")

View File

@ -5,7 +5,7 @@ def execute():
where docstatus = 2""")
for bom in cancelled_boms:
webnotes.conn.sql("""update `tabBOM` set is_default=0, is_active='No'
webnotes.conn.sql("""update `tabBOM` set is_default=0, is_active=0
where name=%s""", (bom[0],))
webnotes.conn.sql("""update `tabItem` set default_bom=null

View File

@ -119,7 +119,7 @@ erpnext.queries.bom = function(opts) {
return 'SELECT tabBOM.name, tabBOM.item \
FROM tabBOM \
WHERE tabBOM.docstatus=1 \
AND tabBOM.is_active="Yes" \
AND tabBOM.is_active=1 \
AND tabBOM.%(key)s LIKE "%s" ' + (conditions.length
? (" AND " + conditions.join(" AND "))
: "")

View File

@ -52,7 +52,7 @@ cur_frm.cscript.show_in_website = function(doc, dt, dn) {
cur_frm.fields_dict['default_bom'].get_query = function(doc) {
//var d = locals[this.doctype][this.docname];
return 'SELECT DISTINCT `tabBOM`.`name` FROM `tabBOM` WHERE `tabBOM`.`item` = "' + doc.item_code + '" AND `tabBOM`.`is_active` = "No" and `tabBOM`.docstatus != 2 AND `tabBOM`.%(key)s LIKE "%s" ORDER BY `tabBOM`.`name` LIMIT 50'
return 'SELECT DISTINCT `tabBOM`.`name` FROM `tabBOM` WHERE `tabBOM`.`item` = "' + doc.item_code + '" AND ifnull(`tabBOM`.`is_active`, 0) = 0 and `tabBOM`.docstatus != 2 AND `tabBOM`.%(key)s LIKE "%s" ORDER BY `tabBOM`.`name` LIMIT 50'
}

View File

@ -375,7 +375,11 @@ class DocType(TransactionBase):
def add_bom(self, d):
#----- fetching default bom from Bill of Materials instead of Item Master --
bom_det = sql("select t1.item, t2.item_code, t2.qty_consumed_per_unit, t2.moving_avg_rate, t2.value_as_per_mar, t2.stock_uom, t2.name, t2.description from `tabBOM` t1, `tabBOM Item` t2 where t2.parent = t1.name and t1.item = '%s' and ifnull(t1.is_default,0) = 1 and t1.docstatus = 1 and t2.docstatus =1" % d.item_code)
bom_det = sql("""select t1.item, t2.item_code, t2.qty_consumed_per_unit,
t2.moving_avg_rate, t2.value_as_per_mar, t2.stock_uom, t2.name, t2.description
from `tabBOM` t1, `tabBOM Item` t2
where t2.parent = t1.name and t1.item = %s and t1.is_default = 1
and t1.docstatus = 1 and t2.docstatus =1 and t1.is_active = 1""", d.item_code)
if not bom_det:
msgprint("No default BOM exists for item: %s" % d.item_code)
raise Exception

View File

@ -214,7 +214,7 @@ class DocType(TransactionBase):
def validate_bom_no(self):
if self.doc.bom_no:
if not webnotes.conn.sql("""select name from tabBOM where name = %s and docstatus = 1
and ifnull(is_active, 'No') = 'Yes'""", self.doc.bom_no):
and is_active = 1""", self.doc.bom_no):
msgprint("""BOM: %s not found, may be it has been cancelled or inactivated""" %
self.doc.bom_no, raise_exception=1)
if not self.doc.fg_completed_qty: