Add total_unit field to product lines.
This commit is contained in:
parent
f5c9ae47ed
commit
6b1e8272e7
13
plan.py
13
plan.py
|
@ -421,6 +421,10 @@ class PlanProductLine(ModelSQL, ModelView):
|
|||
total = fields.Function(fields.Numeric('Total Cost', on_change_with=[
|
||||
'quantity', 'cost_price', 'uom', 'product', 'children'],
|
||||
digits=DIGITS), 'on_change_with_total')
|
||||
total_unit = fields.Function(fields.Numeric('Total Unit Cost',
|
||||
on_change_with=['quantity', 'cost_price', 'uom', 'product',
|
||||
'children', '_parent_plan.quantity'],
|
||||
digits=DIGITS), 'on_change_with_total_unit')
|
||||
|
||||
@classmethod
|
||||
def __setup__(cls):
|
||||
|
@ -472,6 +476,15 @@ class PlanProductLine(ModelSQL, ModelView):
|
|||
digits = self.__class__.total.digits[1]
|
||||
return total.quantize(Decimal(str(10 ** -digits)))
|
||||
|
||||
def on_change_with_total_unit(self, name=None):
|
||||
total = self.on_change_with_total(name)
|
||||
if total and self.plan and self.plan.quantity:
|
||||
total /= Decimal(str(self.plan.quantity))
|
||||
else:
|
||||
total = Decimal('0.0')
|
||||
digits = self.__class__.total_unit.digits[1]
|
||||
return total.quantize(Decimal(str(10 ** -digits)))
|
||||
|
||||
def on_change_with_uom_digits(self, name=None):
|
||||
if self.uom:
|
||||
return self.uom.digits
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
<field name="product_cost_price"/>
|
||||
<field name="cost_price"/>
|
||||
<field name="total"/>
|
||||
<field name="total_unit"/>
|
||||
<field name="parent" tree_invisible="1"/>
|
||||
<field name="children" tree_invisible="1"/>
|
||||
</tree>
|
||||
|
|
Loading…
Reference in New Issue