summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGoffin Simon <sig@odoo.com>2020-03-31 12:28:16 +0000
committerGoffin Simon <sig@odoo.com>2020-04-02 10:34:54 +0000
commit14ca304aed3742b359c9c4d393d1946dfdd0daa2 (patch)
tree5e461816f381ed20f93d89a4208a6c3c1870f2a4
parentfa896ff452aee383ddfc289a8b87ccc3e61e2237 (diff)
[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 82794c8662e23e837e239ebcc6d589f063fab524 opw:2226115 closes odoo/odoo#48857 X-original-commit: 801182f6222521c2961560b3b67743a143a22eff Signed-off-by: Simon Goffin (sig) <sig@openerp.com>
-rw-r--r--addons/purchase/models/account_invoice.py21
1 files changed, 21 insertions, 0 deletions
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