Refactorize on change product

This commit is contained in:
resteve 2014-09-25 16:22:02 +02:00
parent a70c85adf7
commit be1278b8d4
1 changed files with 4 additions and 11 deletions

View File

@ -95,25 +95,18 @@ class SaleCart(ModelSQL, ModelView):
@fields.depends('product', 'unit', 'quantity', 'party', 'currency')
def on_change_product(self):
SaleLine = Pool().get('sale.line')
Product = Pool().get('product.product')
res = {}
context = {}
if self.party:
context['customer'] = self.party.id
if self.party and self.party.sale_price_list:
context['price_list'] = self.party.sale_price_list.id
with Transaction().set_context(context):
line = SaleLine()
line.sale = None
line.party = self.party or None
line.product = self.product
line.unit = self.product and self.product.sale_uom.id or None
line.quantity = self.quantity or 0
line.description = None
res = super(SaleLine, line).on_change_product()
if self.product:
if self.product:
with Transaction().set_context(context):
res['unit_price'] = Product.get_sale_price([self.product],
self.quantity or 0)[self.product.id]
return res