Compute cost types for operations
This commit is contained in:
parent
b2aebb34a6
commit
16042c0ea1
|
@ -40,7 +40,7 @@ msgstr "Quantitat"
|
|||
|
||||
msgctxt "field:product.cost.plan.operation_line,rec_name:"
|
||||
msgid "Name"
|
||||
msgstr "Nom del camp"
|
||||
msgstr "Nom"
|
||||
|
||||
msgctxt "field:product.cost.plan.operation_line,route_operation:"
|
||||
msgid "Route Operation"
|
||||
|
@ -78,6 +78,10 @@ msgctxt "model:ir.action,name:act_product_cost_plan_operation_line"
|
|||
msgid "Product Cost Plan Operation"
|
||||
msgstr "Operació del Pla de costos del producte"
|
||||
|
||||
msgctxt "model:product.cost.plan.cost.type,name:operations"
|
||||
msgid "Operations"
|
||||
msgstr "Operacions"
|
||||
|
||||
msgctxt "model:product.cost.plan.operation_line,name:"
|
||||
msgid "Product Cost Plan Operation Line"
|
||||
msgstr "Operació del Pla de costos del producte"
|
||||
|
|
|
@ -40,7 +40,7 @@ msgstr "Cantidad"
|
|||
|
||||
msgctxt "field:product.cost.plan.operation_line,rec_name:"
|
||||
msgid "Name"
|
||||
msgstr "Nom del camp"
|
||||
msgstr "Nombre"
|
||||
|
||||
msgctxt "field:product.cost.plan.operation_line,route_operation:"
|
||||
msgid "Route Operation"
|
||||
|
@ -78,6 +78,10 @@ msgctxt "model:ir.action,name:act_product_cost_plan_operation_line"
|
|||
msgid "Product Cost Plan Operation"
|
||||
msgstr "Operación de Plan de coste del producto"
|
||||
|
||||
msgctxt "model:product.cost.plan.cost.type,name:operations"
|
||||
msgid "Operations"
|
||||
msgstr "Operaciones"
|
||||
|
||||
msgctxt "model:product.cost.plan.operation_line,name:"
|
||||
msgid "Product Cost Plan Operation Line"
|
||||
msgstr "Operación de Plan de coste del producto"
|
||||
|
|
31
plan.py
31
plan.py
|
@ -86,7 +86,7 @@ class Plan:
|
|||
},
|
||||
depends=['state'])
|
||||
operations = fields.One2Many('product.cost.plan.operation_line', 'plan',
|
||||
'Operation Lines')
|
||||
'Operation Lines', on_change=['costs', 'operations'])
|
||||
operation_cost = fields.Function(fields.Numeric('Operation Cost',
|
||||
on_change_with=['operations']), 'on_change_with_operation_cost')
|
||||
|
||||
|
@ -138,12 +138,33 @@ class Plan:
|
|||
def on_change_quantity(self):
|
||||
return self.update_operations()
|
||||
|
||||
def on_change_with_total_cost(self, name=None):
|
||||
cost = super(Plan, self).on_change_with_total_cost(name)
|
||||
return cost + self.operation_cost
|
||||
|
||||
def on_change_with_operation_cost(self, name=None):
|
||||
cost = Decimal('0.0')
|
||||
for operation in self.operations:
|
||||
cost += operation.cost or Decimal('0.0')
|
||||
return cost
|
||||
|
||||
def on_change_operations(self):
|
||||
pool = Pool()
|
||||
CostType = pool.get('product.cost.plan.cost.type')
|
||||
ModelData = pool.get('ir.model.data')
|
||||
|
||||
type_ = CostType(ModelData.get_id('product_cost_plan_operation',
|
||||
'operations'))
|
||||
self.operation_cost = sum(o.cost for o in self.operations)
|
||||
return self.update_cost_type(type_, self.operation_cost)
|
||||
|
||||
@classmethod
|
||||
def get_cost_types(cls):
|
||||
"""
|
||||
Returns a list of values with the cost types and the field to get
|
||||
their cost.
|
||||
"""
|
||||
pool = Pool()
|
||||
CostType = pool.get('product.cost.plan.cost.type')
|
||||
ModelData = pool.get('ir.model.data')
|
||||
ret = super(Plan, cls).get_cost_types()
|
||||
type_ = CostType(ModelData.get_id('product_cost_plan_operation',
|
||||
'operations'))
|
||||
ret.append((type_, 'operation_cost'))
|
||||
return ret
|
||||
|
|
3
plan.xml
3
plan.xml
|
@ -66,5 +66,8 @@
|
|||
<field name="perm_create" eval="True"/>
|
||||
<field name="perm_delete" eval="True"/>
|
||||
</record>
|
||||
<record model="product.cost.plan.cost.type" id="operations">
|
||||
<field name="name">Operations</field>
|
||||
</record>
|
||||
</data>
|
||||
</tryton>
|
||||
|
|
|
@ -225,6 +225,11 @@ Create a cost plan for product::
|
|||
u'computed'
|
||||
>>> len(plan.products) == 2
|
||||
True
|
||||
>>> product_cost, operation_cost = plan.costs
|
||||
>>> product_cost.cost == plan.product_cost
|
||||
True
|
||||
>>> operation_cost.cost == plan.operation_cost
|
||||
True
|
||||
>>> plan.operation_cost == Decimal('175.0')
|
||||
True
|
||||
>>> plan.total_cost == plan.product_cost + plan.operation_cost
|
||||
|
|
Loading…
Reference in New Issue