From 82794c8662e23e837e239ebcc6d589f063fab524 Mon Sep 17 00:00:00 2001 From: Nicolas Martinelli Date: Thu, 4 Aug 2016 14:47:57 +0200 Subject: [PATCH] [FIX] purchase: vendor currency When defined, the vendor currency should be the default on vendor bills. Fixes #13017 Closes #13016 opw-685016 --- addons/purchase/invoice.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/addons/purchase/invoice.py b/addons/purchase/invoice.py index 15f4d3ac9d3..c8f9eeb98fd 100644 --- a/addons/purchase/invoice.py +++ b/addons/purchase/invoice.py @@ -87,6 +87,22 @@ class AccountInvoice(models.Model): if purchase_ids: self.origin = ', '.join(purchase_ids.mapped('name')) + @api.onchange('partner_id', 'company_id') + def _onchange_partner_id(self): + res = super(AccountInvoice, self)._onchange_partner_id() + if not self.env.context.get('default_journal_id') and self.partner_id and self.currency_id and\ + self.type in ['in_invoice', 'in_refund'] and\ + self.currency_id != self.partner_id.property_purchase_currency_id: + journal_domain = [ + ('type', '=', 'purchase'), + ('company_id', '=', self.company_id.id), + ('currency_id', '=', self.partner_id.property_purchase_currency_id.id), + ] + default_journal_id = self.env['account.journal'].search(journal_domain, limit=1) + if default_journal_id: + self.journal_id = default_journal_id + return res + @api.model def invoice_line_move_line_get(self): res = super(AccountInvoice, self).invoice_line_move_line_get()