Operation quantity should vary depending on the quantity of products of the plan
This commit is contained in:
parent
c09c4c5bf0
commit
baac145db2
24
plan.py
24
plan.py
|
@ -80,14 +80,25 @@ class Plan:
|
|||
__name__ = 'product.cost.plan'
|
||||
|
||||
route = fields.Many2One('production.route', 'Route',
|
||||
on_change=['route', 'operations'], states={
|
||||
on_change=['route', 'operations', 'bom', 'product', 'quantity'],
|
||||
states={
|
||||
'readonly': Eval('state') != 'draft',
|
||||
}, depends=['state'])
|
||||
},
|
||||
depends=['state'])
|
||||
operations = fields.One2Many('product.cost.plan.operation_line', 'plan',
|
||||
'Operation Lines')
|
||||
operation_cost = fields.Function(fields.Numeric('Operation Cost',
|
||||
on_change_with=['operations']), 'on_change_with_operation_cost')
|
||||
|
||||
@classmethod
|
||||
def __setup__(cls):
|
||||
super(Plan, cls).__setup__()
|
||||
if not cls.quantity.on_change:
|
||||
cls.quantity.on_change = []
|
||||
for name in cls.route.on_change:
|
||||
if not name in cls.quantity.on_change:
|
||||
cls.quantity.on_change.append(name)
|
||||
|
||||
def update_operations(self):
|
||||
if not self.route:
|
||||
return {}
|
||||
|
@ -98,6 +109,10 @@ class Plan:
|
|||
changes = {
|
||||
'operations': operations,
|
||||
}
|
||||
factor = 1.0
|
||||
if self.bom and self.bom.route and self.bom.route == self.route:
|
||||
factor = self.bom.compute_factor(self.product, self.quantity or 0,
|
||||
self.product.default_uom)
|
||||
for operation in self.route.operations:
|
||||
work_center = None
|
||||
work_center_category = None
|
||||
|
@ -113,13 +128,16 @@ class Plan:
|
|||
work_center_category.id or None,
|
||||
'route_operation': operation.id,
|
||||
'uom': wc.uom.id,
|
||||
'quantity': operation.quantity,
|
||||
'quantity': operation.quantity * factor,
|
||||
})
|
||||
return changes
|
||||
|
||||
def on_change_route(self):
|
||||
return self.update_operations()
|
||||
|
||||
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
|
||||
|
|
|
@ -165,7 +165,7 @@ Create Bill of Material::
|
|||
>>> BOM = Model.get('production.bom')
|
||||
>>> BOMInput = Model.get('production.bom.input')
|
||||
>>> BOMOutput = Model.get('production.bom.output')
|
||||
>>> bom = BOM(name='product')
|
||||
>>> bom = BOM(name='product', route=route)
|
||||
>>> input1 = BOMInput()
|
||||
>>> bom.inputs.append(input1)
|
||||
>>> input1.product = component1
|
||||
|
@ -215,7 +215,7 @@ Create a cost plan for product::
|
|||
>>> plan.route = route
|
||||
>>> len(plan.operations) == 2
|
||||
True
|
||||
>>> plan.quantity = 10
|
||||
>>> plan.quantity = 1
|
||||
>>> plan.save()
|
||||
>>> plan.state
|
||||
u'draft'
|
||||
|
@ -229,3 +229,26 @@ Create a cost plan for product::
|
|||
True
|
||||
>>> plan.total_cost == plan.product_cost + plan.operation_cost
|
||||
True
|
||||
|
||||
Create a cost plan for 10 units::
|
||||
|
||||
>>> CostPlan = Model.get('product.cost.plan')
|
||||
>>> plan = CostPlan()
|
||||
>>> plan.product = product
|
||||
>>> plan.route = route
|
||||
>>> len(plan.operations) == 2
|
||||
True
|
||||
>>> plan.quantity = 10
|
||||
>>> plan.save()
|
||||
>>> plan.state
|
||||
u'draft'
|
||||
>>> CostPlan.compute([plan.id], config.context)
|
||||
>>> plan.reload()
|
||||
>>> plan.state
|
||||
u'computed'
|
||||
>>> len(plan.products) == 2
|
||||
True
|
||||
>>> plan.operation_cost == Decimal('1750')
|
||||
True
|
||||
>>> plan.total_cost == plan.product_cost + plan.operation_cost
|
||||
True
|
||||
|
|
Loading…
Reference in New Issue