[FIX] purchase: Supplier currency in Vendor bill

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 82794c8662

opw:2226115

closes odoo/odoo#48857

X-original-commit: 801182f6222521c2961560b3b67743a143a22eff
Signed-off-by: Simon Goffin (sig) <sig@openerp.com>
This commit is contained in:
Goffin Simon
2020-04-02 10:34:54 +00:00
parent fa896ff452
commit 14ca304aed
+21
View File
@@ -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