bank-payment/account_payment_partner_default_bank/models/account_invoice.py

39 lines
1.3 KiB
Python
Raw Permalink Normal View History

# Copyright 2014-16 Akretion - Alexis de Lattre <alexis.delattre@akretion.com>
# 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