From 41471bb0ab0b9f1a5942e1e4b093742cffd47128 Mon Sep 17 00:00:00 2001 From: IEL Date: Mon, 28 Sep 2020 15:28:08 +0000 Subject: [PATCH] [FIX] purchase: always switch to vendor's currency on creating a bill Before this commit vendor's currency wasn't used on creating an invoice if there is default journal in context. As I understand, the idea was to let onchange("journal_id") handler to update the currency. It works well, if journal has the same currency as specified in vendor record (res.partner). But it confuse users in following scenario: * there is just one vendor journal * vendor is configured to invoice in another currency * then, if you create invoice via "Accounting >> Overview >> Vendor Bills", it would have journal's currency * while, if you create invoice via "Accounting >> Vendor >> Bills", it would have vendor's currency This commit force to switch to vendor's currency on changing vendor field, even if it differs from journal's currency. If after changing vendor, you set another journal, then journal's currency is used (thanks to onchange("journal_id") handler) opw-2339966 closes odoo/odoo#59162 X-original-commit: 513cc1abe121cd05623be1a6519239f8f4b3fb48 Signed-off-by: agr-odoo Signed-off-by: Nicolas Martinelli (nim) --- addons/purchase/models/account_invoice.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/addons/purchase/models/account_invoice.py b/addons/purchase/models/account_invoice.py index 103cb20a888..d0c30016944 100644 --- a/addons/purchase/models/account_invoice.py +++ b/addons/purchase/models/account_invoice.py @@ -77,18 +77,19 @@ class AccountMove(models.Model): @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\ + if 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 not self.env.context.get('default_journal_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: