From 6e24256e1cdf6bda26b0099fe8fd29cc33e73924 Mon Sep 17 00:00:00 2001
From: qdp-odoo <qdp@odoo.com>
Date: Fri, 11 Dec 2015 13:58:07 +0100
Subject: [PATCH] [FIX] account_voucher: company_id field of account.voucher
 has to be a related of the journal's company

---
 addons/account_voucher/account_voucher.py | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/addons/account_voucher/account_voucher.py b/addons/account_voucher/account_voucher.py
index 8475868e8d09..d9073b0c7375 100644
--- a/addons/account_voucher/account_voucher.py
+++ b/addons/account_voucher/account_voucher.py
@@ -4,7 +4,6 @@
 
 from openerp import fields, models, api, _
 import openerp.addons.decimal_precision as dp
-from openerp.tools import float_compare
 from openerp.exceptions import UserError
 
 
@@ -22,6 +21,10 @@ class AccountVoucher(models.Model):
             return journal.currency_id.id
         return self.env.user.company_id.currency_id.id
 
+    @api.model
+    def _get_company(self):
+        return self._context.get('company_id', self.env.user.company_id.id)
+
     @api.multi
     @api.depends('name', 'number')
     def name_get(self):
@@ -76,7 +79,7 @@ class AccountVoucher(models.Model):
                                    states={'draft': [('readonly', False)]})
     narration = fields.Text('Notes', readonly=True, states={'draft': [('readonly', False)]})
     currency_id = fields.Many2one('res.currency', compute='_get_journal_currency', string='Currency', readonly=True, required=True, default=lambda self: self._get_currency())
-    company_id = fields.Many2one('res.company', 'Company', required=True, readonly=True, states={'draft': [('readonly', False)]}, default=lambda self: self.env['res.company']._company_default_get('account.voucher'))
+    company_id = fields.Many2one('res.company', 'Company', required=True, readonly=True, states={'draft': [('readonly', False)]}, related='journal_id.company_id', default=lambda self: self._get_company())
     state = fields.Selection(
             [('draft', 'Draft'),
              ('cancel', 'Cancelled'),
@@ -104,7 +107,7 @@ class AccountVoucher(models.Model):
 
     @api.onchange('partner_id', 'pay_now')
     def onchange_partner_id(self):
-        if self.pay_now =='pay_now':
+        if self.pay_now == 'pay_now':
             liq_journal = self.env['account.journal'].search([('type', 'in', ('bank', 'cash'))], limit=1)
             self.account_id = liq_journal.default_debit_account_id \
                 if self.voucher_type == 'sale' else liq_journal.default_credit_account_id
-- 
GitLab