diff options
| author | Christophe Simonis <chs@odoo.com> | 2015-04-17 17:33:13 +0200 |
|---|---|---|
| committer | Christophe Simonis <chs@odoo.com> | 2015-04-17 17:33:13 +0200 |
| commit | 8846dcb179bd5a3f2451a69f9e1eac5073799788 (patch) | |
| tree | 0a4bb1936a23009b8a52bafeacd7bc4a928e276e | |
| parent | cfb47fc0123ca7374365cb7e6500dfc400e10fb0 (diff) | |
[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.
| -rw-r--r-- | addons/account/account_invoice.py | 30 |
1 files changed, 19 insertions, 11 deletions
diff --git a/addons/account/account_invoice.py b/addons/account/account_invoice.py index a450506c55b..2f9edf23196 100644 --- a/addons/account/account_invoice.py +++ b/addons/account/account_invoice.py @@ -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): |
