# 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: if company.bank_ids: self.partner_bank_id = company.bank_ids[0] 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: if company.bank_ids: self.partner_bank_id = company.bank_ids[0] return res