From 14ca304aed3742b359c9c4d393d1946dfdd0daa2 Mon Sep 17 00:00:00 2001 From: Goffin Simon Date: Tue, 31 Mar 2020 12:28:16 +0000 Subject: [PATCH] [FIX] purchase: Supplier currency in Vendor bill MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Steps to reproduce the bug: - Let's consider a vendor V with a supplier currency € - Let's consider the current company's user C in $ - Let's consider two vendor bills journals J1 in € and J2 in $ from C - Create a vendor bill for V Bug: The default currency was $ instead of € and the default journal was J2 instead of J1. This fix keeps the same behavior as implemented in 82794c8662e23e837e239ebcc6d589f063fab524 opw:2226115 closes odoo/odoo#48857 X-original-commit: 801182f6222521c2961560b3b67743a143a22eff Signed-off-by: Simon Goffin (sig) --- addons/purchase/models/account_invoice.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/addons/purchase/models/account_invoice.py b/addons/purchase/models/account_invoice.py index 0d8d9ec9bf1..99d51b28b7d 100644 --- a/addons/purchase/models/account_invoice.py +++ b/addons/purchase/models/account_invoice.py @@ -67,6 +67,27 @@ class AccountMove(models.Model): self._onchange_currency() self.invoice_partner_bank_id = self.bank_partner_id.bank_ids and self.bank_partner_id.bank_ids[0] + @api.onchange('partner_id', 'company_id') + def _onchange_partner_id(self): + res = super(AccountMove, self)._onchange_partner_id() + if not self.env.context.get('default_journal_id') and self.partner_id and\ + self.move_type in ['in_invoice', 'in_refund'] and\ + self.currency_id != self.partner_id.property_purchase_currency_id and\ + self.partner_id.property_purchase_currency_id.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 + if self.env.context.get('default_currency_id'): + self.currency_id = self.env.context['default_currency_id'] + if self.partner_id.property_purchase_currency_id: + self.currency_id = self.partner_id.property_purchase_currency_id + return res + @api.model_create_multi def create(self, vals_list): # OVERRIDE