Skip to content
Extraits de code Groupes Projets
account_move.py 1,91 ko
Newer Older
  • Learn to ignore specific revisions
  • # 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"
        )
    
    
        # ------------------------------------------------------
        # 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