Product Unit Price field

This commit is contained in:
resteve 2012-11-27 19:01:56 +01:00
parent 16bd152339
commit 6e51721087
2 changed files with 20 additions and 0 deletions

18
sale.py
View File

@ -45,6 +45,11 @@ class SaleLine:
'invisible': Not(Equal(Eval('type'), 'line')),
}, on_change=['discount', 'product', 'quantity', 'type', 'unit_price'],
depends=['type', 'unit_price', 'quantity', 'amount'])
product_unit_price = fields.Function(fields.Numeric('Product Unit Price',
digits=(16, 4), states={
'invisible': Eval('type') != 'line',
}, on_change_with=['type', '_parent_sale.currency'],
depends=['type']), 'get_product_unit_price')
@staticmethod
def default_discount():
@ -61,9 +66,22 @@ class SaleLine:
def on_change_product(self):
res = super(SaleLine, self).on_change_product()
res['discount'] = Decimal(0.0)
res['product_unit_price'] = self.on_change_with_product_unit_price()
return res
def on_change_quantity(self):
res = super(SaleLine, self).on_change_quantity()
res['discount'] = Decimal(0.0)
return res
def on_change_with_product_unit_price(self):
if self.type == 'line' and self.product:
Product = Pool().get('product.product')
return Product.get_sale_price([self.product], 1)[self.product.id]
return Decimal('0.0')
def get_product_unit_price(self, name):
if self.type == 'line' and self.product:
Product = Pool().get('product.product')
return Product.get_sale_price([self.product], 1)[self.product.id]
return Decimal('0.0')

View File

@ -44,6 +44,8 @@ The COPYRIGHT file at the top level of this repository contains the full copyrig
position="before">
<label name="discount"/>
<field name="discount"/>
<label name="product_unit_price"/>
<field name="product_unit_price"/>
</xpath>
</data>
]]>