[FIX] account: correct price_subtotal_signed computation

When computing default values, `self.company_id` may not be set. Use
explictly `self.invoice_id.company_id` to compute the signed subtotal.
Also, only do it when there is an invoice.
This commit is contained in:
Christophe Simonis
2015-04-17 17:33:13 +02:00
parent cfb47fc012
commit 8846dcb179
+18 -10
View File
@@ -1211,20 +1211,28 @@ class account_invoice_line(models.Model):
_order = "invoice_id,sequence,id"
@api.one
@api.depends('price_unit', 'discount', 'invoice_line_tax_id', 'quantity',
'product_id', 'invoice_id.partner_id', 'invoice_id.currency_id', 'invoice_id.company_id')
@api.depends('price_unit', 'discount', 'invoice_line_tax_id', 'quantity', 'product_id',
'invoice_id.partner_id', 'invoice_id.currency_id', 'invoice_id.company_id')
def _compute_price(self):
price = self.price_unit * (1 - (self.discount or 0.0) / 100.0)
taxes = self.invoice_line_tax_id.compute_all(price, self.quantity, product=self.product_id, partner=self.invoice_id.partner_id)
taxes = self.invoice_line_tax_id.compute_all(price, self.quantity,
product=self.product_id,
partner=self.invoice_id.partner_id)
self.price_subtotal = price_subtotal_signed = taxes['total']
if self.invoice_id.currency_id != self.invoice_id.company_id.currency_id:
price_subtotal_signed = self.invoice_id.currency_id.with_context(date=self.invoice_id.date_invoice).compute(price_subtotal_signed, self.company_id.currency_id)
sign = self.invoice_id.type in ['in_invoice', 'out_refund'] and -1 or 1
self.price_subtotal_signed = price_subtotal_signed * sign
if self.invoice_id:
self.price_subtotal = self.invoice_id.currency_id.round(self.price_subtotal)
self.price_subtotal_signed = self.invoice_id.currency_id.round(self.price_subtotal_signed)
if not self.invoice_id:
self.price_subtotal_signed = price_subtotal_signed
else:
inv_cur = self.invoice_id.currency_id
comp_cur = self.invoice_id.company_id.currency_id
if inv_cur != comp_cur:
inv_cur = inv_cur.with_context(date=self.invoice_id.date_invoice)
price_subtotal_signed = inv_cur.compute(price_subtotal_signed, comp_cur)
sign = -1 if self.invoice_id.type in ['in_invoice', 'out_refund'] else 1
self.price_subtotal = inv_cur.round(self.price_subtotal)
self.price_subtotal_signed = inv_cur.round(self.price_subtotal_signed * sign)
@api.model
def _default_price_unit(self):