Add components cost and total cost on BOM

Add standard price in BOM lines
This commit is contained in:
Alexis de Lattre
2016-03-22 17:57:13 +01:00
parent 753333521f
commit cc1efeafdb
2 changed files with 41 additions and 12 deletions

View File

@@ -36,7 +36,7 @@ class MrpBomLabourLine(orm.Model):
'bom_id': fields.many2one( 'bom_id': fields.many2one(
'mrp.bom', 'Labour Lines', ondelete='cascade'), 'mrp.bom', 'Labour Lines', ondelete='cascade'),
'labour_time': fields.float( 'labour_time': fields.float(
'Labour Time', 'Labour Time', required=True,
digits_compute=dp.get_precision('Labour Hours'), digits_compute=dp.get_precision('Labour Hours'),
help="Average labour time for the production of " help="Average labour time for the production of "
"items of the BOM, in hours."), "items of the BOM, in hours."),
@@ -74,16 +74,28 @@ class MrpBom(orm.Model):
return self.pool['mrp.bom'].search( return self.pool['mrp.bom'].search(
cr, uid, [('labour_line_ids', 'in', labour_line_ids)], context=context) cr, uid, [('labour_line_ids', 'in', labour_line_ids)], context=context)
def _compute_total_cost(
self, cr, uid, ids, name, arg, context=None):
res = {}
puo = self.pool['product.uom']
for bom in self.browse(cr, uid, ids, context=context):
component_cost = 0.0
for line in bom.bom_lines:
component_price = line.product_id.standard_price
component_qty_product_uom = puo._compute_qty_obj(
cr, uid, line.product_uom, line.product_qty,
line.product_id.uom_id, context=context)
component_cost += component_price * component_qty_product_uom
total_cost = component_cost + bom.extra_cost + bom.total_labour_cost
res[bom.id] = {
'total_components_cost': component_cost,
'total_cost': total_cost,
}
return res
_columns = { _columns = {
# TODO: delete this field once migration is done 'labour_line_ids': fields.one2many(
'labour_time': fields.float( 'mrp.bom.labour.line', 'bom_id', 'Labour Lines'),
'Labour Time',
digits_compute=dp.get_precision('Labour Hours'),
help="Average labour time for the production of the quantity of "
"items of the BOM, in hours."),
# TODO: delete this field once migration is done
'labour_cost_profile_id': fields.many2one(
'labour.cost.profile', 'Labour Cost Profile'),
'total_labour_cost': fields.function( 'total_labour_cost': fields.function(
_compute_total_labour_cost, type='float', readonly=True, _compute_total_labour_cost, type='float', readonly=True,
string="Total Labour Cost", store={ string="Total Labour Cost", store={
@@ -92,8 +104,6 @@ class MrpBom(orm.Model):
'mrp.bom.labour.line': (_get_bom_from_labour_lines, [ 'mrp.bom.labour.line': (_get_bom_from_labour_lines, [
'bom_id', 'labour_time', 'labour_cost_profile_id'], 20), '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', track_visibility='onchange', 'Extra Cost', track_visibility='onchange',
digits_compute=dp.get_precision('Product Price'), digits_compute=dp.get_precision('Product Price'),
@@ -102,9 +112,21 @@ class MrpBom(orm.Model):
"You can use this field to enter the cost of the consumables " "You can use this field to enter the cost of the consumables "
"that are used to produce the product but are not listed in " "that are used to produce the product but are not listed in "
"the BOM"), "the BOM"),
'total_components_cost': fields.function(
_compute_total_cost, type='float', readonly=True,
multi='total-cost', string='Total Components Cost'),
'total_cost': fields.function(
_compute_total_cost, type='float', readonly=True,
multi='total-cost', string='Total Cost',
help="Total Cost = Total Components Cost + "
"Total Labour Cost + Extra Cost"),
'company_currency_id': fields.related( 'company_currency_id': fields.related(
'company_id', 'currency_id', readonly=True, type='many2one', 'company_id', 'currency_id', readonly=True, type='many2one',
relation='res.currency', string='Company Currency'), relation='res.currency', string='Company Currency'),
# to display in bom lines
'standard_price': fields.related(
'product_id', 'standard_price', readonly=True,
type='float', string='Standard Price')
} }

View File

@@ -14,10 +14,14 @@
<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_components_cost" widget="monetary"
options="{'currency_field': 'company_currency_id'}"/>
<field name="total_labour_cost" widget="monetary" <field name="total_labour_cost" widget="monetary"
options="{'currency_field': 'company_currency_id'}"/> 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="total_cost" widget="monetary"
options="{'currency_field': 'company_currency_id'}"/>
<field name="company_currency_id" invisible="1"/> <field name="company_currency_id" invisible="1"/>
</xpath> </xpath>
<page string="Components" position="after"> <page string="Components" position="after">
@@ -27,6 +31,9 @@
</group> </group>
</page> </page>
</page> </page>
<xpath expr="//field[@name='bom_lines']/tree/field[@name='product_uom']" position="after">
<field name="standard_price"/>
</xpath>
</field> </field>
</record> </record>