Add Unit Cost Price field.

This commit is contained in:
Albert Cervera i Areny 2014-01-19 20:49:59 +01:00
parent 19a54b4866
commit 50fcb5eb74
2 changed files with 11 additions and 1 deletions

10
plan.py
View file

@ -20,7 +20,7 @@ class Plan(Workflow, ModelSQL, ModelView):
}, depends=['state', 'product'], }, depends=['state', 'product'],
domain=[ domain=[
('output_products', '=', Eval('product', 0)), ('output_products', '=', Eval('product', 0)),
],) ])
boms = fields.One2Many('product.cost.plan.bom_line', 'plan', 'BOMs', boms = fields.One2Many('product.cost.plan.bom_line', 'plan', 'BOMs',
states={ states={
'readonly': Eval('state') != 'draft', 'readonly': Eval('state') != 'draft',
@ -37,6 +37,8 @@ class Plan(Workflow, ModelSQL, ModelView):
total_cost = fields.Function(fields.Numeric('Total Cost', total_cost = fields.Function(fields.Numeric('Total Cost',
on_change_with=['product_cost']), on_change_with=['product_cost']),
'on_change_with_total_cost') 'on_change_with_total_cost')
unit_cost_price = fields.Function(fields.Numeric('Unit Cost Price'),
'get_unit_cost_price')
state = fields.Selection([ state = fields.Selection([
('draft', 'Draft'), ('draft', 'Draft'),
('computed', 'Computed'), ('computed', 'Computed'),
@ -113,6 +115,12 @@ class Plan(Workflow, ModelSQL, ModelView):
def on_change_with_total_cost(self, name=None): def on_change_with_total_cost(self, name=None):
return self.product_cost return self.product_cost
def get_unit_cost_price(self, name):
total_cost = self.total_cost
if self.quantity and total_cost:
return total_cost / Decimal(str(self.quantity))
return Decimal('0.0')
@classmethod @classmethod
@ModelView.button @ModelView.button
@Workflow.transition('draft') @Workflow.transition('draft')

View file

@ -20,6 +20,8 @@
</notebook> </notebook>
<label name="total_cost"/> <label name="total_cost"/>
<field name="total_cost"/> <field name="total_cost"/>
<label name="unit_cost_price"/>
<field name="unit_cost_price"/>
<newline/> <newline/>
<group id="state" colspan="6"> <group id="state" colspan="6">
<label name="state"/> <label name="state"/>