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
cur_frm.cscript.refresh = function(doc,dt,dn){
if(!doc.__islocal) {
set_field_permlevel('item',1);
unhide_field('update_cost_as_on_today');
} else {
hide_field('update_cost_as_on_today');
}
cur_frm.toggle_enable("item", doc.__islocal);
}
@ -137,9 +132,6 @@ var calculate_total = function(doc) {
}
// Get Query
//-----------------------------------------------------------------------------------------------------
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';
}

View File

@ -152,7 +152,6 @@ class DocType:
sql("update `tabItem` set default_bom = %s where name = %s", (self.doc.name, self.doc.item))
else:
sql("update `tabItem` set default_bom = '' where name = %s and default_bom = %s", (self.doc.item, self.doc.name))
def manage_active_bom(self):
@ -193,24 +192,22 @@ class DocType:
total_op_cost = 0
for d in getlist(self.doclist, 'bom_operations'):
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.operating_cost = flt(d.hour_rate) * flt(d.time_in_mins) / 60
d.hour_rate = hour_rate and flt(hour_rate[0][0]) or d.hour_rate or 0
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()
total_op_cost += d.operating_cost
self.doc.operating_cost = total_op_cost
def calculate_rm_cost(self):
"""Fetch RM rate as per today's valuation rate and calculate totals"""
total_rm_cost = 0
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}
ret = self.get_bom_material_detail(cstr(arg))
for k in ret:
d.fields[k] = ret[k]
d.amount = flt(d.rate) * flt(d.qty)
d.save()
total_rm_cost += d.amount
@ -286,15 +283,11 @@ class DocType:
check_list.append([cstr(item), cstr(op)])
#----- Document on Save function------
def validate(self):
self.validate_main_item()
self.validate_operations()
self.validate_materials()
def check_recursion(self):
""" 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',
'docstatus': 0,
'modified': '2012-03-27 14:45:46',
'modified_by': u'Administrator',
'owner': u'Administrator'
},
# These values are common for all DocType
{
'_last_update': u'1326963484',
'allow_attach': 0,
'allow_copy': 0,
'allow_email': 0,
'allow_print': 0,
'allow_rename': 0,
'allow_trash': 1,
'colour': u'White:FFF',
'default_print_format': u'Standard',
'doctype': 'DocType',
'document_type': u'Master',
'hide_heading': 0,
'hide_toolbar': 0,
'in_create': 0,
'is_submittable': 1,
'issingle': 0,
'istable': 0,
'module': u'Production',
'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__',
'parent': u'BOM',
'parentfield': u'fields',
'parenttype': u'DocType'
},
# These values are common for all DocPerm
{
'doctype': u'DocPerm',
'name': '__common__',
'parent': u'BOM',
'parentfield': u'permissions',
'parenttype': u'DocType',
'read': 1
},
# DocType, BOM
{
'doctype': 'DocType',
'name': u'BOM'
},
# DocPerm
{
'cancel': 1,
'create': 1,
'doctype': u'DocPerm',
'permlevel': 0,
'role': u'System Manager',
'submit': 1,
'write': 1
},
# DocPerm
{
'doctype': u'DocPerm',
'permlevel': 1,
'role': u'System Manager'
},
# DocPerm
{
'cancel': 1,
'create': 1,
'doctype': u'DocPerm',
'permlevel': 0,
'role': u'Production Manager',
'submit': 1,
'write': 1
},
# DocPerm
{
'doctype': u'DocPerm',
'permlevel': 1,
'role': u'Production Manager'
},
# DocPerm
{
'cancel': 1,
'create': 1,
'doctype': u'DocPerm',
'permlevel': 0,
'role': u'Production User',
'submit': 1,
'write': 1
},
# DocPerm
{
'doctype': u'DocPerm',
'permlevel': 1,
'role': u'Production User'
},
# DocField
{
'doctype': u'DocField',
'fieldname': u'column_break0',
'fieldtype': u'Column Break',
'oldfieldtype': u'Column Break',
'permlevel': 0,
'width': u'50%'
},
# DocField
{
'colour': u'White:FFF',
'description': u'Select the item code for which Bill of Material is being created',
'doctype': u'DocField',
'fieldname': u'item',
'fieldtype': u'Link',
'in_filter': 1,
'label': u'Item',
'oldfieldname': u'item',
'oldfieldtype': u'Link',
'options': u'Item',
'permlevel': 0,
'reqd': 1,
'search_index': 1,
'trigger': u'Client'
},
# DocField
{
'colour': u'White:FFF',
'description': u'Total quantity of items for which raw materials required and operations done will be defined',
'doctype': u'DocField',
'fieldname': u'quantity',
'fieldtype': u'Currency',
'label': u'Quantity',
'oldfieldname': u'quantity',
'oldfieldtype': u'Currency',
'permlevel': 0,
'reqd': 1
},
# DocField
{
'doctype': u'DocField',
'fieldname': u'uom',
'fieldtype': u'Select',
'label': u'UOM',
'options': u'link:UOM',
'permlevel': 1
},
# DocField
{
'doctype': u'DocField',
'fieldname': u'description',
'fieldtype': u'Text',
'label': u'Description',
'oldfieldname': u'description',
'oldfieldtype': u'Text',
'permlevel': 0,
'width': u'300px'
},
# DocField
{
'doctype': u'DocField',
'fieldname': u'column_break1',
'fieldtype': u'Column Break',
'permlevel': 0,
'width': u'50%'
},
# DocField
{
'description': u'Select name of the project if BOM need to be created against any project',
'doctype': u'DocField',
'fieldname': u'project_name',
'fieldtype': u'Link',
'in_filter': 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,
'colour': u'White:FFF',
'doctype': u'DocField',
'fieldname': u'is_active',
'fieldtype': u'Select',
'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,
'colour': u'White:FFF',
'doctype': u'DocField',
'fieldname': u'is_default',
'fieldtype': u'Check',
'label': u'Is Default',
'no_copy': 1,
'oldfieldname': u'is_default',
'oldfieldtype': u'Check',
'permlevel': 0
},
# DocField
{
'doctype': u'DocField',
'fieldname': u'maintained_by',
'fieldtype': u'Data',
'label': u'Maintained By',
'oldfieldname': u'maintained_by',
'oldfieldtype': u'Data',
'permlevel': 0
},
# DocField
{
'colour': u'White:FFF',
'doctype': u'DocField',
'fieldname': u'remarks',
'fieldtype': u'Text',
'label': u'Remarks',
'no_copy': 1,
'oldfieldname': u'remarks',
'oldfieldtype': u'Text',
'permlevel': 0
},
# DocField
{
'doctype': u'DocField',
'fieldname': u'operations',
'fieldtype': u'Section Break',
'label': u'Operations',
'oldfieldtype': u'Section Break',
'permlevel': 0
},
# DocField
{
'colour': u'White:FFF',
'description': u'Specify the operations, operating cost and give a unique Operation no to your operations.',
'doctype': u'DocField',
'fieldname': u'bom_operations',
'fieldtype': u'Table',
'label': u'BOM Operations',
'oldfieldname': u'bom_operations',
'oldfieldtype': u'Table',
'options': u'BOM Operation',
'permlevel': 0
},
# DocField
{
'doctype': u'DocField',
'fieldname': u'materials',
'fieldtype': u'Section Break',
'label': u'Materials',
'oldfieldtype': u'Section Break',
'permlevel': 0
},
# DocField
{
'colour': u'White:FFF',
'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': u'DocField',
'fieldname': u'bom_materials',
'fieldtype': u'Table',
'label': u'BOM Item',
'oldfieldname': u'bom_materials',
'oldfieldtype': u'Table',
'options': u'BOM Item',
'permlevel': 0
},
# DocField
{
'doctype': u'DocField',
'fieldname': u'costing',
'fieldtype': u'Section Break',
'label': u'Costing',
'oldfieldtype': u'Section Break',
'permlevel': 0
},
# DocField
{
'doctype': u'DocField',
'fieldname': u'column_break2',
'fieldtype': u'Column Break',
'permlevel': 0,
'width': u'50%'
},
# DocField
{
'doctype': u'DocField',
'fieldname': u'rm_cost_as_per',
'fieldtype': u'Select',
'label': u'Consider Raw Material Cost As Per',
'options': u'Valuation Rate\nLast Purchase Rate\nStandard Rate',
'permlevel': 0
},
# DocField
{
'doctype': u'DocField',
'fieldname': u'costing_date',
'fieldtype': u'Date',
'label': u'Costing Date',
'permlevel': 1
},
# DocField
{
'allow_on_submit': 1,
'doctype': u'DocField',
'fieldname': u'update_cost_as_on_today',
'fieldtype': u'Button',
'label': u'Update Cost as on today',
'options': u'calculate_cost',
'permlevel': 0
},
# DocField
{
'doctype': u'DocField',
'fieldname': u'column_break3',
'fieldtype': u'Column Break',
'permlevel': 0,
'width': u'50%'
},
# DocField
{
'doctype': u'DocField',
'fieldname': u'raw_material_cost',
'fieldtype': u'Float',
'label': u'Raw Material Cost',
'permlevel': 1
},
# DocField
{
'doctype': u'DocField',
'fieldname': u'operating_cost',
'fieldtype': u'Float',
'label': u'Operating Cost',
'permlevel': 1
},
# DocField
{
'doctype': u'DocField',
'fieldname': u'total_cost',
'fieldtype': u'Float',
'label': u'Total Cost',
'permlevel': 1
},
# DocField
{
'doctype': u'DocField',
'fieldname': u'section_break0',
'fieldtype': u'Section Break',
'hidden': 1,
'options': u'Simple',
'permlevel': 0,
'print_hide': 0
},
# DocField
{
'colour': u'White:FFF',
'default': u'No Toolbar',
'doctype': u'DocField',
'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
}
{
"owner": "Administrator",
"docstatus": 0,
"creation": "2012-07-03 13:30:03",
"modified_by": "Administrator",
"modified": "2012-12-03 13:29:26"
},
{
"istable": 0,
"in_create": 0,
"allow_print": 0,
"search_fields": "item",
"module": "Production",
"document_type": "Master",
"allow_attach": 0,
"read_only": 0,
"allow_email": 0,
"hide_heading": 0,
"issingle": 0,
"name": "__common__",
"default_print_format": "Standard",
"allow_rename": 0,
"doctype": "DocType",
"is_submittable": 1,
"hide_toolbar": 0,
"allow_copy": 0
},
{
"name": "__common__",
"parent": "BOM",
"doctype": "DocField",
"parenttype": "DocType",
"parentfield": "fields"
},
{
"name": "__common__",
"parent": "BOM",
"read": 1,
"doctype": "DocPerm",
"parenttype": "DocType",
"parentfield": "permissions"
},
{
"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",
"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"
},
{
"description": "Total quantity of items for which raw materials required and operations done will be defined",
"oldfieldtype": "Currency",
"colour": "White:FFF",
"doctype": "DocField",
"label": "Quantity",
"oldfieldname": "quantity",
"fieldname": "quantity",
"fieldtype": "Currency",
"reqd": 1,
"permlevel": 0
},
{
"doctype": "DocField",
"width": "50%",
"fieldname": "column_break1",
"fieldtype": "Column Break",
"permlevel": 0
},
{
"no_copy": 1,
"oldfieldtype": "Select",
"colour": "White:FFF",
"allow_on_submit": 1,
"doctype": "DocField",
"label": "Is Active",
"oldfieldname": "is_active",
"permlevel": 0,
"fieldname": "is_active",
"fieldtype": "Select",
"reqd": 1,
"hidden": 0,
"options": "\nYes\nNo"
},
{
"allow_on_submit": 1,
"no_copy": 1,
"oldfieldtype": "Check",
"colour": "White:FFF",
"doctype": "DocField",
"label": "Is Default",
"oldfieldname": "is_default",
"fieldname": "is_default",
"fieldtype": "Check",
"permlevel": 0
},
{
"oldfieldtype": "Section Break",
"doctype": "DocField",
"label": "Operations",
"fieldname": "operations",
"fieldtype": "Section Break",
"permlevel": 0
},
{
"description": "Specify the operations, operating cost and give a unique Operation no to your operations.",
"oldfieldtype": "Table",
"colour": "White:FFF",
"doctype": "DocField",
"label": "BOM Operations",
"oldfieldname": "bom_operations",
"options": "BOM Operation",
"fieldname": "bom_operations",
"fieldtype": "Table",
"permlevel": 0
},
{
"oldfieldtype": "Section Break",
"doctype": "DocField",
"label": "Materials",
"fieldname": "materials",
"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",
"colour": "White:FFF",
"doctype": "DocField",
"label": "BOM Item",
"oldfieldname": "bom_materials",
"options": "BOM Item",
"fieldname": "bom_materials",
"fieldtype": "Table",
"permlevel": 0
},
{
"oldfieldtype": "Section Break",
"doctype": "DocField",
"label": "Costing",
"fieldname": "costing",
"fieldtype": "Section Break",
"permlevel": 0
},
{
"doctype": "DocField",
"label": "Raw Material Cost",
"fieldname": "raw_material_cost",
"fieldtype": "Float",
"permlevel": 1
},
{
"doctype": "DocField",
"label": "Operating Cost",
"fieldname": "operating_cost",
"fieldtype": "Float",
"permlevel": 1
},
{
"doctype": "DocField",
"label": "Total Cost",
"fieldname": "total_cost",
"fieldtype": "Float",
"permlevel": 1
},
{
"doctype": "DocField",
"label": "More Info",
"fieldname": "more_info_section",
"fieldtype": "Section Break",
"permlevel": 0
},
{
"description": "Select name of the project if BOM need to be created against any project",
"oldfieldtype": "Link",
"label": "Project Name",
"oldfieldname": "project_name",
"trigger": "Client",
"fieldname": "project_name",
"fieldtype": "Link",
"doctype": "DocField",
"options": "Project",
"permlevel": 0,
"in_filter": 1
},
{
"doctype": "DocField",
"label": "Item UOM",
"options": "link:UOM",
"fieldname": "uom",
"fieldtype": "Select",
"permlevel": 1
},
{
"oldfieldtype": "Text",
"doctype": "DocField",
"label": "Item Description",
"oldfieldname": "description",
"width": "300px",
"fieldname": "description",
"fieldtype": "Small Text",
"permlevel": 0
},
{
"doctype": "DocField",
"fieldname": "col_break23",
"fieldtype": "Column Break",
"permlevel": 0
},
{
"oldfieldtype": "Data",
"doctype": "DocField",
"label": "Maintained By",
"oldfieldname": "maintained_by",
"fieldname": "maintained_by",
"fieldtype": "Data",
"permlevel": 0
},
{
"print_hide": 1,
"no_copy": 1,
"doctype": "DocField",
"label": "Amended From",
"options": "Sales Invoice",
"fieldname": "amended_from",
"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",
"colour": "White:FFF",
"doctype": "DocField",
"label": "Remarks",
"oldfieldname": "remarks",
"fieldname": "remarks",
"fieldtype": "Small Text",
"permlevel": 0
},
{
"print_hide": 0,
"doctype": "DocField",
"label": "BOM Explosion Items",
"options": "Simple",
"fieldname": "section_break0",
"fieldtype": "Section Break",
"hidden": 0,
"permlevel": 0
},
{
"print_hide": 1,
"permlevel": 1,
"no_copy": 1,
"oldfieldtype": "Table",
"colour": "White:FFF",
"doctype": "DocField",
"label": "BOM Explosion Item",
"oldfieldname": "flat_bom_details",
"default": "No Toolbar",
"fieldname": "flat_bom_details",
"fieldtype": "Table",
"hidden": 0,
"options": "BOM Explosion Item"
},
{
"create": 1,
"doctype": "DocPerm",
"submit": 1,
"write": 1,
"role": "System Manager",
"cancel": 1,
"permlevel": 0
},
{
"doctype": "DocPerm",
"role": "System Manager",
"permlevel": 1
},
{
"create": 1,
"doctype": "DocPerm",
"submit": 1,
"write": 1,
"role": "Production Manager",
"cancel": 1,
"permlevel": 0
},
{
"doctype": "DocPerm",
"role": "Production Manager",
"permlevel": 1
},
{
"create": 1,
"doctype": "DocPerm",
"submit": 1,
"write": 1,
"role": "Production User",
"cancel": 1,
"permlevel": 0
},
{
"doctype": "DocPerm",
"role": "Production User",
"permlevel": 1
}
]

View File

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

View File

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