From d28865fba427bb19421bd63182575c00fb14576c Mon Sep 17 00:00:00 2001 From: Nicolas Martinelli Date: Thu, 19 Nov 2015 13:54:50 +0100 Subject: [PATCH] [FIX] purchase: convert to invoice currency When a PO is imported, convert the prices in the currency of the invoice. Moreover, an onchange on the currency will recalculate the prices if necessary. opw-656762 --- addons/purchase/invoice.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/addons/purchase/invoice.py b/addons/purchase/invoice.py index 0317e5d79c7..6b8d5908d27 100644 --- a/addons/purchase/invoice.py +++ b/addons/purchase/invoice.py @@ -74,7 +74,7 @@ class AccountInvoice(models.Model): 'uom_id': line.product_uom.id, 'product_id': line.product_id.id, 'account_id': self.env['account.invoice.line'].with_context({'journal_id': self.journal_id.id, 'type': 'in_invoice'})._default_account(), - 'price_unit': line.price_unit, + 'price_unit': line.order_id.currency_id.compute(line.price_unit, self.currency_id), 'quantity': qty, 'discount': 0.0, 'account_analytic_id': line.account_analytic_id.id, @@ -90,6 +90,12 @@ class AccountInvoice(models.Model): self.purchase_id = False return {} + @api.onchange('currency_id') + def _onchange_currency_id(self): + if self.currency_id: + for line in self.invoice_line_ids.filtered(lambda r: r.purchase_line_id): + line.price_unit = line.purchase_id.currency_id.compute(line.purchase_line_id.price_unit, self.currency_id) + @api.model def invoice_line_move_line_get(self): res = super(AccountInvoice, self).invoice_line_move_line_get()