# Copyright 2014-16 Akretion - Alexis de Lattre # Copyright 2014 Serv. Tecnol. Avanzados - Pedro M. Baeza # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). from flectra import api, fields, models, _ from flectra.exceptions import ValidationError class AccountInvoice(models.Model): _inherit = 'account.invoice' @api.onchange('partner_id', 'company_id') def _onchange_partner_id(self): if self.company_id: company = self.company_id else: company = self.env.user.company_id res = super(AccountInvoice, self)._onchange_partner_id() if self.type == 'out_invoice' and not self.partner_bank_id: bank_id = self._get_partner_bank_id(company.id) if bank_id: self.partner_bank_id = bank_id return res @api.onchange('payment_mode_id') def _onchange_payment_mode_id(self): if self.company_id: company = self.company_id else: company = self.env.user.company_id res = super(AccountInvoice, self)._onchange_payment_mode_id() if self.type == 'out_invoice' and not self.partner_bank_id: bank_id = self._get_partner_bank_id(company.id) if bank_id: self.partner_bank_id = bank_id return res