Newer
Older
# Copyright 2021 Le Filament (<http://www.le-filament.com>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo import fields, models, api
class AccountMove(models.Model):
_inherit = 'account.move'
third_account_journal_ids = fields.Many2many(related='journal_id.third_account_ids')
third_account_id = fields.Many2one(
comodel_name='account.account',
string='Compte de tiers',
)
display_siret = fields.Boolean(
string="Afficher le SIRET", default=False,
help="Affiche le n° SIRET sur la facture client"
)
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# ------------------------------------------------------
# Override Parent
# ------------------------------------------------------
@api.onchange('journal_id')
def _onchange_journal_id(self):
"""
Affecte le compte de tiers défini sur le journal
"""
if self.journal_id.third_account_ids:
self.third_account_id = self.journal_id.third_account_ids[0].id
@api.onchange('third_account_id')
def _onchange_third_account_id(self):
"""
Affecte le compte de tiers défini sur le journal
"""
if self.third_account_id:
for line in self.line_ids:
if line.account_id.user_type_id.type in ('receivable', 'payable'):
line.account_id = self.third_account_id
# ------------------------------------------------------
# Override Parent
# ------------------------------------------------------
@api.onchange('partner_id')
def _onchange_partner_id(self):
"""
Affecte le compte de tiers défini sur le journal
"""
super(AccountMove, self)._onchange_partner_id()
if self.third_account_id:
for line in self.line_ids:
if line.account_id.user_type_id.type in ('receivable', 'payable'):
line.account_id = self.third_account_id