Add mrp.bom.labour.line, to be able to have several labor cost profile on a single BOM
This commit is contained in:
@@ -28,19 +28,74 @@ import logging
|
|||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
class MrpBomLabourLine(orm.Model):
|
||||||
|
_name = 'mrp.bom.labour.line'
|
||||||
|
_description = 'Labour lines on BOM'
|
||||||
|
|
||||||
|
_columns = {
|
||||||
|
'bom_id': fields.many2one(
|
||||||
|
'mrp.bom', 'Labour Lines', ondelete='cascade'),
|
||||||
|
'labour_time': fields.float(
|
||||||
|
'Labour Time',
|
||||||
|
digits_compute=dp.get_precision('Labour Hours'),
|
||||||
|
help="Average labour time for the production of "
|
||||||
|
"items of the BOM, in hours."),
|
||||||
|
'labour_cost_profile_id': fields.many2one(
|
||||||
|
'labour.cost.profile', 'Labour Cost Profile', required=True),
|
||||||
|
'note': fields.text('Note'),
|
||||||
|
}
|
||||||
|
|
||||||
|
_sql_constraints = [(
|
||||||
|
'labour_time_positive',
|
||||||
|
'CHECK (labour_time >= 0)',
|
||||||
|
"The value of the field 'Labour Time' must be positive or 0.")]
|
||||||
|
|
||||||
|
|
||||||
class MrpBom(orm.Model):
|
class MrpBom(orm.Model):
|
||||||
_inherit = 'mrp.bom'
|
_inherit = 'mrp.bom'
|
||||||
|
|
||||||
|
def _compute_total_labour_cost(
|
||||||
|
self, cr, uid, ids, name, arg, context=None):
|
||||||
|
res = {}
|
||||||
|
for bom in self.browse(cr, uid, ids, context=context):
|
||||||
|
cost = 0.0
|
||||||
|
for lline in bom.labour_line_ids:
|
||||||
|
cost += lline.labour_time * lline.labour_cost_profile_id.hour_cost
|
||||||
|
res[bom.id] = cost
|
||||||
|
return res
|
||||||
|
|
||||||
|
def _get_bom_from_labour_lines(self, cr, uid, ids, context=None):
|
||||||
|
return self.pool['mrp.bom'].search(
|
||||||
|
cr, uid, [('labour_line_ids', 'in', ids)], context=context)
|
||||||
|
|
||||||
|
def _get_bom_from_cost_profile(self, cr, uid, ids, context=None):
|
||||||
|
labour_line_ids = self.pool['mrp.bom.labour.line'].search(
|
||||||
|
cr, uid, [('labour_cost_profile_id', 'in', ids)], context=context)
|
||||||
|
return self.pool['mrp.bom'].search(
|
||||||
|
cr, uid, [('labour_line_ids', 'in', labour_line_ids)], context=context)
|
||||||
|
|
||||||
_columns = {
|
_columns = {
|
||||||
|
# TODO: delete this field once migration is done
|
||||||
'labour_time': fields.float(
|
'labour_time': fields.float(
|
||||||
'Labour Time',
|
'Labour Time',
|
||||||
digits_compute=dp.get_precision('Labour Hours'),
|
digits_compute=dp.get_precision('Labour Hours'),
|
||||||
help="Average labour time for the production of the quantity of "
|
help="Average labour time for the production of the quantity of "
|
||||||
"items of the BOM, in hours."),
|
"items of the BOM, in hours."),
|
||||||
|
# TODO: delete this field once migration is done
|
||||||
'labour_cost_profile_id': fields.many2one(
|
'labour_cost_profile_id': fields.many2one(
|
||||||
'labour.cost.profile', 'Labour Cost Profile'),
|
'labour.cost.profile', 'Labour Cost Profile'),
|
||||||
|
'total_labour_cost': fields.function(
|
||||||
|
_compute_total_labour_cost, type='float', readonly=True,
|
||||||
|
string="Total Labour Cost", store={
|
||||||
|
'labour.cost.profile': (_get_bom_from_cost_profile, [
|
||||||
|
'hour_cost', 'company_id'], 10),
|
||||||
|
'mrp.bom.labour.line': (_get_bom_from_labour_lines, [
|
||||||
|
'bom_id', 'labour_time', 'labour_cost_profile_id'], 20),
|
||||||
|
}),
|
||||||
|
'labour_line_ids': fields.one2many(
|
||||||
|
'mrp.bom.labour.line', 'bom_id', 'Labour Lines'),
|
||||||
'extra_cost': fields.float(
|
'extra_cost': fields.float(
|
||||||
'Extra Cost',
|
'Extra Cost', track_visibility='onchange',
|
||||||
digits_compute=dp.get_precision('Product Price'),
|
digits_compute=dp.get_precision('Product Price'),
|
||||||
help="Extra cost for the production of the quantity of "
|
help="Extra cost for the production of the quantity of "
|
||||||
"items of the BOM, in company currency. "
|
"items of the BOM, in company currency. "
|
||||||
@@ -131,15 +186,10 @@ class MrpProduction(orm.Model):
|
|||||||
mo_total_price += raw_material_cost
|
mo_total_price += raw_material_cost
|
||||||
if order.bom_id:
|
if order.bom_id:
|
||||||
bom = order.bom_id
|
bom = order.bom_id
|
||||||
if not bom.labour_cost_profile_id:
|
if not bom.total_labour_cost:
|
||||||
raise orm.except_orm(
|
raise orm.except_orm(
|
||||||
_('Error:'),
|
_('Error:'),
|
||||||
_("Labor Cost Profile is not set on bill of "
|
_("Total Labor Cost is 0 on bill of material '%s'.")
|
||||||
"material '%s'.") % bom.name)
|
|
||||||
if not bom.labour_time:
|
|
||||||
raise orm.except_orm(
|
|
||||||
_('Error:'),
|
|
||||||
_("Labour Time is not set on bill of material '%s'.")
|
|
||||||
% bom.name)
|
% bom.name)
|
||||||
if not bom.product_qty:
|
if not bom.product_qty:
|
||||||
raise orm.except_orm(
|
raise orm.except_orm(
|
||||||
@@ -150,9 +200,7 @@ class MrpProduction(orm.Model):
|
|||||||
cr, uid, bom.product_uom, bom.product_qty,
|
cr, uid, bom.product_uom, bom.product_qty,
|
||||||
bom.product_id.uom_id, context=context)
|
bom.product_id.uom_id, context=context)
|
||||||
assert bom_qty_product_uom > 0, 'BoM qty should be positive'
|
assert bom_qty_product_uom > 0, 'BoM qty should be positive'
|
||||||
labor_cost_per_unit = (
|
labor_cost_per_unit = bom.total_labour_cost / bom_qty_product_uom
|
||||||
bom.labour_time * bom.labour_cost_profile_id.hour_cost) /\
|
|
||||||
bom_qty_product_uom
|
|
||||||
extra_cost_per_unit = bom.extra_cost / bom_qty_product_uom
|
extra_cost_per_unit = bom.extra_cost / bom_qty_product_uom
|
||||||
# mo_standard_price and labor_cost_per_unit are
|
# mo_standard_price and labor_cost_per_unit are
|
||||||
# in the UoM of the product (not of the MO/BOM)
|
# in the UoM of the product (not of the MO/BOM)
|
||||||
|
|||||||
@@ -14,19 +14,56 @@
|
|||||||
<field name="inherit_id" ref="mrp.mrp_bom_form_view"/>
|
<field name="inherit_id" ref="mrp.mrp_bom_form_view"/>
|
||||||
<field name="arch" type="xml">
|
<field name="arch" type="xml">
|
||||||
<xpath expr="//div[@groups='mrp.group_mrp_routings']" position="after">
|
<xpath expr="//div[@groups='mrp.group_mrp_routings']" position="after">
|
||||||
|
<field name="total_labour_cost" widget="monetary"
|
||||||
|
options="{'currency_field': 'company_currency_id'}"/>
|
||||||
<field name="extra_cost" widget="monetary"
|
<field name="extra_cost" widget="monetary"
|
||||||
options="{'currency_field': 'company_currency_id'}"/>
|
options="{'currency_field': 'company_currency_id'}"/>
|
||||||
<field name="company_currency_id" invisible="1"/>
|
<field name="company_currency_id" invisible="1"/>
|
||||||
<label for="labour_time"/>
|
|
||||||
<div name="labour_time">
|
|
||||||
<field name="labour_time" class="oe_inline"/>
|
|
||||||
<label string="hours"/>
|
|
||||||
</div>
|
|
||||||
<field name="labour_cost_profile_id"/>
|
|
||||||
</xpath>
|
</xpath>
|
||||||
|
<page string="Components" position="after">
|
||||||
|
<page string="Labour" name="labour_lines">
|
||||||
|
<group name="labour_lines_grp">
|
||||||
|
<field name="labour_line_ids" nolabel="1"/>
|
||||||
|
</group>
|
||||||
|
</page>
|
||||||
|
</page>
|
||||||
</field>
|
</field>
|
||||||
</record>
|
</record>
|
||||||
|
|
||||||
|
<record id="mrp_bom_labour_line_tree" model="ir.ui.view">
|
||||||
|
<field name="name">mrp_bom_labour_line.tree</field>
|
||||||
|
<field name="model">mrp.bom.labour.line</field>
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<tree string="Labour Lines" editable="bottom">
|
||||||
|
<field name="bom_id" invisible="not context.get('mrp_bom_labour_line_main_view')"/>
|
||||||
|
<field name="labour_time" string="Labour Time (hours)"/>
|
||||||
|
<field name="labour_cost_profile_id"/>
|
||||||
|
<field name="note"/>
|
||||||
|
</tree>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
|
||||||
|
<record id="mrp_bom_labour_line_form" model="ir.ui.view">
|
||||||
|
<field name="name">mrp_bom_labour_line.form</field>
|
||||||
|
<field name="model">mrp.bom.labour.line</field>
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<form string="Labour Line" version="7.0">
|
||||||
|
<group name="main">
|
||||||
|
<field name="bom_id" invisible="not context.get('mrp_bom_labour_line_main_view')"/>
|
||||||
|
<label for="labour_time"/>
|
||||||
|
<div name="labour_time">
|
||||||
|
<field name="labour_time" class="oe_inline"/>
|
||||||
|
<label string="hours"/>
|
||||||
|
</div>
|
||||||
|
<field name="labour_cost_profile_id"/>
|
||||||
|
<field name="note"/>
|
||||||
|
</group>
|
||||||
|
</form>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<record id="labour_cost_profile_form" model="ir.ui.view">
|
<record id="labour_cost_profile_form" model="ir.ui.view">
|
||||||
<field name="name">labour_cost_profile_form</field>
|
<field name="name">labour_cost_profile_form</field>
|
||||||
<field name="model">labour.cost.profile</field>
|
<field name="model">labour.cost.profile</field>
|
||||||
|
|||||||
@@ -1,3 +1,9 @@
|
|||||||
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
|
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
|
||||||
access_labour_cost_profile_read,Read access on labour.cost.profile to MRP user,model_labour_cost_profile,mrp.group_mrp_user,1,0,0,0
|
access_labour_cost_profile_read,Read access on labour.cost.profile to MRP user,model_labour_cost_profile,mrp.group_mrp_user,1,0,0,0
|
||||||
|
access_labour_cost_profile_read_sale,Read access on labour.cost.profile to Sale user,model_labour_cost_profile,base.group_sale_salesman,1,0,0,0
|
||||||
|
access_labour_cost_profile_read_stock,Read access on labour.cost.profile to Stock user,model_labour_cost_profile,stock.group_stock_user,1,0,0,0
|
||||||
access_labour_cost_profile_full,Full access on labour.cost.profile to MRP manager,model_labour_cost_profile,mrp.group_mrp_manager,1,1,1,1
|
access_labour_cost_profile_full,Full access on labour.cost.profile to MRP manager,model_labour_cost_profile,mrp.group_mrp_manager,1,1,1,1
|
||||||
|
access_mrp_bom_labour_line_read,Read access on mrp.bom.labour.line to MRP user,model_mrp_bom_labour_line,mrp.group_mrp_user,1,0,0,0
|
||||||
|
access_mrp_bom_labour_line_read_sale,Read access on mrp.bom.labour.line to Sale user,model_mrp_bom_labour_line,base.group_sale_salesman,1,0,0,0
|
||||||
|
access_mrp_bom_labour_line_read_stock,Read access on mrp.bom.labour.line to Stock user,model_mrp_bom_labour_line,stock.group_stock_user,1,0,0,0
|
||||||
|
access_mrp_bom_labour_line_full,Full access on mrp.bom.labour.line to MRP manager,model_mrp_bom_labour_line,mrp.group_mrp_manager,1,1,1,1
|
||||||
|
|||||||
|
Reference in New Issue
Block a user