fixes in bom costing

This commit is contained in:
Nabin Hait 2012-12-03 15:54:45 +05:30
parent 4bbaddd57d
commit d61e4fd317
5 changed files with 353 additions and 483 deletions

View File

@ -16,12 +16,7 @@
// On REFRESH // On REFRESH
cur_frm.cscript.refresh = function(doc,dt,dn){ cur_frm.cscript.refresh = function(doc,dt,dn){
if(!doc.__islocal) { cur_frm.toggle_enable("item", doc.__islocal);
set_field_permlevel('item',1);
unhide_field('update_cost_as_on_today');
} else {
hide_field('update_cost_as_on_today');
}
} }
@ -137,9 +132,6 @@ var calculate_total = function(doc) {
} }
// Get Query
//-----------------------------------------------------------------------------------------------------
cur_frm.fields_dict['item'].get_query = function(doc) { cur_frm.fields_dict['item'].get_query = function(doc) {
return 'SELECT DISTINCT `tabItem`.`name`, `tabItem`.description FROM `tabItem` WHERE is_manufactured_item = "Yes" and (IFNULL(`tabItem`.`end_of_life`,"") = "" OR `tabItem`.`end_of_life` = "0000-00-00" OR `tabItem`.`end_of_life` > NOW()) AND `tabItem`.`%(key)s` like "%s" ORDER BY `tabItem`.`name` LIMIT 50'; return 'SELECT DISTINCT `tabItem`.`name`, `tabItem`.description FROM `tabItem` WHERE is_manufactured_item = "Yes" and (IFNULL(`tabItem`.`end_of_life`,"") = "" OR `tabItem`.`end_of_life` = "0000-00-00" OR `tabItem`.`end_of_life` > NOW()) AND `tabItem`.`%(key)s` like "%s" ORDER BY `tabItem`.`name` LIMIT 50';
} }

View File

@ -154,7 +154,6 @@ class DocType:
sql("update `tabItem` set default_bom = '' where name = %s and default_bom = %s", (self.doc.item, self.doc.name)) sql("update `tabItem` set default_bom = '' where name = %s and default_bom = %s", (self.doc.item, self.doc.name))
def manage_active_bom(self): def manage_active_bom(self):
""" Manage active/inactive """ """ Manage active/inactive """
if self.doc.is_active == 'Yes': if self.doc.is_active == 'Yes':
@ -193,24 +192,22 @@ class DocType:
total_op_cost = 0 total_op_cost = 0
for d in getlist(self.doclist, 'bom_operations'): for d in getlist(self.doclist, 'bom_operations'):
hour_rate = sql("select hour_rate from `tabWorkstation` where name = %s", cstr(d.workstation)) hour_rate = sql("select hour_rate from `tabWorkstation` where name = %s", cstr(d.workstation))
d.hour_rate = hour_rate and flt(hour_rate[0][0]) or 0 d.hour_rate = hour_rate and flt(hour_rate[0][0]) or d.hour_rate or 0
d.operating_cost = flt(d.hour_rate) * flt(d.time_in_mins) / 60 d.operating_cost = d.hour_rate and d.time_in_mins and \
flt(d.hour_rate) * flt(d.time_in_mins) / 60 or d.operating_cost
d.save() d.save()
total_op_cost += d.operating_cost total_op_cost += d.operating_cost
self.doc.operating_cost = total_op_cost self.doc.operating_cost = total_op_cost
def calculate_rm_cost(self): def calculate_rm_cost(self):
"""Fetch RM rate as per today's valuation rate and calculate totals""" """Fetch RM rate as per today's valuation rate and calculate totals"""
total_rm_cost = 0 total_rm_cost = 0
for d in getlist(self.doclist, 'bom_materials'): for d in getlist(self.doclist, 'bom_materials'):
#if self.doc.rm_cost_as_per == 'Valuation Rate':
arg = {'item_code': d.item_code, 'qty': d.qty, 'bom_no': d.bom_no} arg = {'item_code': d.item_code, 'qty': d.qty, 'bom_no': d.bom_no}
ret = self.get_bom_material_detail(cstr(arg)) ret = self.get_bom_material_detail(cstr(arg))
for k in ret: for k in ret:
d.fields[k] = ret[k] d.fields[k] = ret[k]
d.amount = flt(d.rate) * flt(d.qty) d.amount = flt(d.rate) * flt(d.qty)
d.save() d.save()
total_rm_cost += d.amount total_rm_cost += d.amount
@ -286,15 +283,11 @@ class DocType:
check_list.append([cstr(item), cstr(op)]) check_list.append([cstr(item), cstr(op)])
#----- Document on Save function------
def validate(self): def validate(self):
self.validate_main_item() self.validate_main_item()
self.validate_operations() self.validate_operations()
self.validate_materials() self.validate_materials()
def check_recursion(self): def check_recursion(self):
""" Check whether reqursion occurs in any bom""" """ Check whether reqursion occurs in any bom"""

View File

@ -1,462 +1,347 @@
# DocType, BOM
[ [
# These values are common in all dictionaries
{ {
'creation': '2012-03-27 14:36:02', "owner": "Administrator",
'docstatus': 0, "docstatus": 0,
'modified': '2012-03-27 14:45:46', "creation": "2012-07-03 13:30:03",
'modified_by': u'Administrator', "modified_by": "Administrator",
'owner': u'Administrator' "modified": "2012-12-03 13:29:26"
}, },
# These values are common for all DocType
{ {
'_last_update': u'1326963484', "istable": 0,
'allow_attach': 0, "in_create": 0,
'allow_copy': 0, "allow_print": 0,
'allow_email': 0, "search_fields": "item",
'allow_print': 0, "module": "Production",
'allow_rename': 0, "document_type": "Master",
'allow_trash': 1, "allow_attach": 0,
'colour': u'White:FFF', "read_only": 0,
'default_print_format': u'Standard', "allow_email": 0,
'doctype': 'DocType', "hide_heading": 0,
'document_type': u'Master', "issingle": 0,
'hide_heading': 0, "name": "__common__",
'hide_toolbar': 0, "default_print_format": "Standard",
'in_create': 0, "allow_rename": 0,
'is_submittable': 1, "doctype": "DocType",
'issingle': 0, "is_submittable": 1,
'istable': 0, "hide_toolbar": 0,
'module': u'Production', "allow_copy": 0
'name': '__common__',
'read_only': 0,
'search_fields': u'item',
'section_style': u'Simple',
'server_code_error': u' ',
'show_in_menu': 0,
'subject': u'%(item)s',
'version': 196
}, },
# These values are common for all DocField
{ {
'doctype': u'DocField', "name": "__common__",
'name': '__common__', "parent": "BOM",
'parent': u'BOM', "doctype": "DocField",
'parentfield': u'fields', "parenttype": "DocType",
'parenttype': u'DocType' "parentfield": "fields"
}, },
# These values are common for all DocPerm
{ {
'doctype': u'DocPerm', "name": "__common__",
'name': '__common__', "parent": "BOM",
'parent': u'BOM', "read": 1,
'parentfield': u'permissions', "doctype": "DocPerm",
'parenttype': u'DocType', "parenttype": "DocType",
'read': 1 "parentfield": "permissions"
}, },
# DocType, BOM
{ {
'doctype': 'DocType', "name": "BOM",
'name': u'BOM' "doctype": "DocType"
}, },
# DocPerm
{ {
'cancel': 1, "oldfieldtype": "Column Break",
'create': 1, "doctype": "DocField",
'doctype': u'DocPerm', "width": "50%",
'permlevel': 0, "fieldname": "column_break0",
'role': u'System Manager', "fieldtype": "Column Break",
'submit': 1, "permlevel": 0
'write': 1
}, },
# DocPerm
{ {
'doctype': u'DocPerm', "description": "Select the item code for which Bill of Material is being created",
'permlevel': 1, "oldfieldtype": "Link",
'role': u'System Manager' "colour": "White:FFF",
"doctype": "DocField",
"label": "Item",
"oldfieldname": "item",
"permlevel": 0,
"trigger": "Client",
"fieldname": "item",
"fieldtype": "Link",
"search_index": 1,
"reqd": 1,
"in_filter": 1,
"options": "Item"
}, },
# DocPerm
{ {
'cancel': 1, "description": "Total quantity of items for which raw materials required and operations done will be defined",
'create': 1, "oldfieldtype": "Currency",
'doctype': u'DocPerm', "colour": "White:FFF",
'permlevel': 0, "doctype": "DocField",
'role': u'Production Manager', "label": "Quantity",
'submit': 1, "oldfieldname": "quantity",
'write': 1 "fieldname": "quantity",
"fieldtype": "Currency",
"reqd": 1,
"permlevel": 0
}, },
# DocPerm
{ {
'doctype': u'DocPerm', "doctype": "DocField",
'permlevel': 1, "width": "50%",
'role': u'Production Manager' "fieldname": "column_break1",
"fieldtype": "Column Break",
"permlevel": 0
}, },
# DocPerm
{ {
'cancel': 1, "no_copy": 1,
'create': 1, "oldfieldtype": "Select",
'doctype': u'DocPerm', "colour": "White:FFF",
'permlevel': 0, "allow_on_submit": 1,
'role': u'Production User', "doctype": "DocField",
'submit': 1, "label": "Is Active",
'write': 1 "oldfieldname": "is_active",
"permlevel": 0,
"fieldname": "is_active",
"fieldtype": "Select",
"reqd": 1,
"hidden": 0,
"options": "\nYes\nNo"
}, },
# DocPerm
{ {
'doctype': u'DocPerm', "allow_on_submit": 1,
'permlevel': 1, "no_copy": 1,
'role': u'Production User' "oldfieldtype": "Check",
"colour": "White:FFF",
"doctype": "DocField",
"label": "Is Default",
"oldfieldname": "is_default",
"fieldname": "is_default",
"fieldtype": "Check",
"permlevel": 0
}, },
# DocField
{ {
'doctype': u'DocField', "oldfieldtype": "Section Break",
'fieldname': u'column_break0', "doctype": "DocField",
'fieldtype': u'Column Break', "label": "Operations",
'oldfieldtype': u'Column Break', "fieldname": "operations",
'permlevel': 0, "fieldtype": "Section Break",
'width': u'50%' "permlevel": 0
}, },
# DocField
{ {
'colour': u'White:FFF', "description": "Specify the operations, operating cost and give a unique Operation no to your operations.",
'description': u'Select the item code for which Bill of Material is being created', "oldfieldtype": "Table",
'doctype': u'DocField', "colour": "White:FFF",
'fieldname': u'item', "doctype": "DocField",
'fieldtype': u'Link', "label": "BOM Operations",
'in_filter': 1, "oldfieldname": "bom_operations",
'label': u'Item', "options": "BOM Operation",
'oldfieldname': u'item', "fieldname": "bom_operations",
'oldfieldtype': u'Link', "fieldtype": "Table",
'options': u'Item', "permlevel": 0
'permlevel': 0,
'reqd': 1,
'search_index': 1,
'trigger': u'Client'
}, },
# DocField
{ {
'colour': u'White:FFF', "oldfieldtype": "Section Break",
'description': u'Total quantity of items for which raw materials required and operations done will be defined', "doctype": "DocField",
'doctype': u'DocField', "label": "Materials",
'fieldname': u'quantity', "fieldname": "materials",
'fieldtype': u'Currency', "fieldtype": "Section Break",
'label': u'Quantity', "permlevel": 0
'oldfieldname': u'quantity',
'oldfieldtype': u'Currency',
'permlevel': 0,
'reqd': 1
}, },
# DocField
{ {
'doctype': u'DocField', "doctype": "DocField",
'fieldname': u'uom', "label": "Consider Raw Material Cost As Per",
'fieldtype': u'Select', "options": "Valuation Rate\nLast Purchase Rate\nStandard Rate",
'label': u'UOM', "fieldname": "rm_cost_as_per",
'options': u'link:UOM', "fieldtype": "Select",
'permlevel': 1 "permlevel": 0
}, },
# DocField
{ {
'doctype': u'DocField', "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.",
'fieldname': u'description', "oldfieldtype": "Table",
'fieldtype': u'Text', "colour": "White:FFF",
'label': u'Description', "doctype": "DocField",
'oldfieldname': u'description', "label": "BOM Item",
'oldfieldtype': u'Text', "oldfieldname": "bom_materials",
'permlevel': 0, "options": "BOM Item",
'width': u'300px' "fieldname": "bom_materials",
"fieldtype": "Table",
"permlevel": 0
}, },
# DocField
{ {
'doctype': u'DocField', "oldfieldtype": "Section Break",
'fieldname': u'column_break1', "doctype": "DocField",
'fieldtype': u'Column Break', "label": "Costing",
'permlevel': 0, "fieldname": "costing",
'width': u'50%' "fieldtype": "Section Break",
"permlevel": 0
}, },
# DocField
{ {
'description': u'Select name of the project if BOM need to be created against any project', "doctype": "DocField",
'doctype': u'DocField', "label": "Raw Material Cost",
'fieldname': u'project_name', "fieldname": "raw_material_cost",
'fieldtype': u'Link', "fieldtype": "Float",
'in_filter': 1, "permlevel": 1
'label': u'Project Name',
'oldfieldname': u'project_name',
'oldfieldtype': u'Link',
'options': u'Project',
'permlevel': 0,
'trigger': u'Client'
}, },
# DocField
{ {
'allow_on_submit': 1, "doctype": "DocField",
'colour': u'White:FFF', "label": "Operating Cost",
'doctype': u'DocField', "fieldname": "operating_cost",
'fieldname': u'is_active', "fieldtype": "Float",
'fieldtype': u'Select', "permlevel": 1
'hidden': 0,
'label': u'Is Active',
'no_copy': 1,
'oldfieldname': u'is_active',
'oldfieldtype': u'Select',
'options': u'\nYes\nNo',
'permlevel': 0,
'reqd': 1
}, },
# DocField
{ {
'allow_on_submit': 1, "doctype": "DocField",
'colour': u'White:FFF', "label": "Total Cost",
'doctype': u'DocField', "fieldname": "total_cost",
'fieldname': u'is_default', "fieldtype": "Float",
'fieldtype': u'Check', "permlevel": 1
'label': u'Is Default',
'no_copy': 1,
'oldfieldname': u'is_default',
'oldfieldtype': u'Check',
'permlevel': 0
}, },
# DocField
{ {
'doctype': u'DocField', "doctype": "DocField",
'fieldname': u'maintained_by', "label": "More Info",
'fieldtype': u'Data', "fieldname": "more_info_section",
'label': u'Maintained By', "fieldtype": "Section Break",
'oldfieldname': u'maintained_by', "permlevel": 0
'oldfieldtype': u'Data',
'permlevel': 0
}, },
# DocField
{ {
'colour': u'White:FFF', "description": "Select name of the project if BOM need to be created against any project",
'doctype': u'DocField', "oldfieldtype": "Link",
'fieldname': u'remarks', "label": "Project Name",
'fieldtype': u'Text', "oldfieldname": "project_name",
'label': u'Remarks', "trigger": "Client",
'no_copy': 1, "fieldname": "project_name",
'oldfieldname': u'remarks', "fieldtype": "Link",
'oldfieldtype': u'Text', "doctype": "DocField",
'permlevel': 0 "options": "Project",
"permlevel": 0,
"in_filter": 1
}, },
# DocField
{ {
'doctype': u'DocField', "doctype": "DocField",
'fieldname': u'operations', "label": "Item UOM",
'fieldtype': u'Section Break', "options": "link:UOM",
'label': u'Operations', "fieldname": "uom",
'oldfieldtype': u'Section Break', "fieldtype": "Select",
'permlevel': 0 "permlevel": 1
}, },
# DocField
{ {
'colour': u'White:FFF', "oldfieldtype": "Text",
'description': u'Specify the operations, operating cost and give a unique Operation no to your operations.', "doctype": "DocField",
'doctype': u'DocField', "label": "Item Description",
'fieldname': u'bom_operations', "oldfieldname": "description",
'fieldtype': u'Table', "width": "300px",
'label': u'BOM Operations', "fieldname": "description",
'oldfieldname': u'bom_operations', "fieldtype": "Small Text",
'oldfieldtype': u'Table', "permlevel": 0
'options': u'BOM Operation',
'permlevel': 0
}, },
# DocField
{ {
'doctype': u'DocField', "doctype": "DocField",
'fieldname': u'materials', "fieldname": "col_break23",
'fieldtype': u'Section Break', "fieldtype": "Column Break",
'label': u'Materials', "permlevel": 0
'oldfieldtype': u'Section Break',
'permlevel': 0
}, },
# DocField
{ {
'colour': u'White:FFF', "oldfieldtype": "Data",
'description': u'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.', "doctype": "DocField",
'doctype': u'DocField', "label": "Maintained By",
'fieldname': u'bom_materials', "oldfieldname": "maintained_by",
'fieldtype': u'Table', "fieldname": "maintained_by",
'label': u'BOM Item', "fieldtype": "Data",
'oldfieldname': u'bom_materials', "permlevel": 0
'oldfieldtype': u'Table',
'options': u'BOM Item',
'permlevel': 0
}, },
# DocField
{ {
'doctype': u'DocField', "print_hide": 1,
'fieldname': u'costing', "no_copy": 1,
'fieldtype': u'Section Break', "doctype": "DocField",
'label': u'Costing', "label": "Amended From",
'oldfieldtype': u'Section Break', "options": "Sales Invoice",
'permlevel': 0 "fieldname": "amended_from",
"fieldtype": "Link",
"permlevel": 1
}, },
# DocField
{ {
'doctype': u'DocField', "print_hide": 1,
'fieldname': u'column_break2', "description": "The date at which current entry is corrected in the system.",
'fieldtype': u'Column Break', "no_copy": 1,
'permlevel': 0, "depends_on": "eval:doc.amended_from",
'width': u'50%' "doctype": "DocField",
"label": "Amendment Date",
"fieldname": "amendment_date",
"fieldtype": "Date",
"permlevel": 0
}, },
# DocField
{ {
'doctype': u'DocField', "no_copy": 1,
'fieldname': u'rm_cost_as_per', "oldfieldtype": "Text",
'fieldtype': u'Select', "colour": "White:FFF",
'label': u'Consider Raw Material Cost As Per', "doctype": "DocField",
'options': u'Valuation Rate\nLast Purchase Rate\nStandard Rate', "label": "Remarks",
'permlevel': 0 "oldfieldname": "remarks",
"fieldname": "remarks",
"fieldtype": "Small Text",
"permlevel": 0
}, },
# DocField
{ {
'doctype': u'DocField', "print_hide": 0,
'fieldname': u'costing_date', "doctype": "DocField",
'fieldtype': u'Date', "label": "BOM Explosion Items",
'label': u'Costing Date', "options": "Simple",
'permlevel': 1 "fieldname": "section_break0",
"fieldtype": "Section Break",
"hidden": 0,
"permlevel": 0
}, },
# DocField
{ {
'allow_on_submit': 1, "print_hide": 1,
'doctype': u'DocField', "permlevel": 1,
'fieldname': u'update_cost_as_on_today', "no_copy": 1,
'fieldtype': u'Button', "oldfieldtype": "Table",
'label': u'Update Cost as on today', "colour": "White:FFF",
'options': u'calculate_cost', "doctype": "DocField",
'permlevel': 0 "label": "BOM Explosion Item",
"oldfieldname": "flat_bom_details",
"default": "No Toolbar",
"fieldname": "flat_bom_details",
"fieldtype": "Table",
"hidden": 0,
"options": "BOM Explosion Item"
}, },
# DocField
{ {
'doctype': u'DocField', "create": 1,
'fieldname': u'column_break3', "doctype": "DocPerm",
'fieldtype': u'Column Break', "submit": 1,
'permlevel': 0, "write": 1,
'width': u'50%' "role": "System Manager",
"cancel": 1,
"permlevel": 0
}, },
# DocField
{ {
'doctype': u'DocField', "doctype": "DocPerm",
'fieldname': u'raw_material_cost', "role": "System Manager",
'fieldtype': u'Float', "permlevel": 1
'label': u'Raw Material Cost',
'permlevel': 1
}, },
# DocField
{ {
'doctype': u'DocField', "create": 1,
'fieldname': u'operating_cost', "doctype": "DocPerm",
'fieldtype': u'Float', "submit": 1,
'label': u'Operating Cost', "write": 1,
'permlevel': 1 "role": "Production Manager",
"cancel": 1,
"permlevel": 0
}, },
# DocField
{ {
'doctype': u'DocField', "doctype": "DocPerm",
'fieldname': u'total_cost', "role": "Production Manager",
'fieldtype': u'Float', "permlevel": 1
'label': u'Total Cost',
'permlevel': 1
}, },
# DocField
{ {
'doctype': u'DocField', "create": 1,
'fieldname': u'section_break0', "doctype": "DocPerm",
'fieldtype': u'Section Break', "submit": 1,
'hidden': 1, "write": 1,
'options': u'Simple', "role": "Production User",
'permlevel': 0, "cancel": 1,
'print_hide': 0 "permlevel": 0
}, },
# DocField
{ {
'colour': u'White:FFF', "doctype": "DocPerm",
'default': u'No Toolbar', "role": "Production User",
'doctype': u'DocField', "permlevel": 1
'fieldname': u'flat_bom_details',
'fieldtype': u'Table',
'hidden': 1,
'label': u'BOM Explosion Item',
'no_copy': 1,
'oldfieldname': u'flat_bom_details',
'oldfieldtype': u'Table',
'options': u'BOM Explosion Item',
'permlevel': 0,
'print_hide': 1
},
# DocField
{
'doctype': u'DocField',
'fieldname': u'trash_reason',
'fieldtype': u'Small Text',
'hidden': 1,
'label': u'Trash Reason',
'oldfieldname': u'trash_reason',
'oldfieldtype': u'Small Text',
'permlevel': 1
},
# DocField
{
'depends_on': u'eval:doc.amended_from',
'description': u'The date at which current entry is corrected in the system.',
'doctype': u'DocField',
'fieldname': u'amendment_date',
'fieldtype': u'Date',
'label': u'Amendment Date',
'no_copy': 1,
'permlevel': 0,
'print_hide': 1
},
# DocField
{
'doctype': u'DocField',
'fieldname': u'amended_from',
'fieldtype': u'Link',
'label': u'Amended From',
'no_copy': 1,
'options': u'Sales Invoice',
'permlevel': 1,
'print_hide': 1
} }
] ]

View File

@ -4,7 +4,7 @@
"docstatus": 0, "docstatus": 0,
"creation": "2012-07-03 13:30:03", "creation": "2012-07-03 13:30:03",
"modified_by": "Administrator", "modified_by": "Administrator",
"modified": "2012-11-30 14:28:03" "modified": "2012-12-03 15:38:54"
}, },
{ {
"is_submittable": 1, "is_submittable": 1,
@ -139,7 +139,7 @@
"oldfieldname": "consider_sa_items", "oldfieldname": "consider_sa_items",
"fieldname": "use_multi_level_bom", "fieldname": "use_multi_level_bom",
"fieldtype": "Check", "fieldtype": "Check",
"reqd": 1, "reqd": 0,
"in_filter": 1, "in_filter": 1,
"permlevel": 0 "permlevel": 0
}, },

View File

@ -4,7 +4,7 @@
"docstatus": 0, "docstatus": 0,
"creation": "2012-07-03 13:30:03", "creation": "2012-07-03 13:30:03",
"modified_by": "Administrator", "modified_by": "Administrator",
"modified": "2012-11-30 14:08:55" "modified": "2012-12-03 15:39:44"
}, },
{ {
"read_only": 1, "read_only": 1,
@ -164,7 +164,7 @@
"colour": "White:FFF", "colour": "White:FFF",
"doctype": "DocField", "doctype": "DocField",
"label": "Use Multi-Level BOM", "label": "Use Multi-Level BOM",
"reqd": 1, "reqd": 0,
"fieldname": "use_multi_level_bom", "fieldname": "use_multi_level_bom",
"fieldtype": "Check" "fieldtype": "Check"
}, },