Skip to content
Extraits de code Groupes Projets
Sélectionner une révision Git
  • d25ce504a06c19978bfbd2476e501485e6ccb482
  • 12.0 par défaut protégée
2 résultats

account_invoice.py

Blame
  • account_invoice.py 1,52 Kio
    # Copyright 2022 Le Filament (<http://www.le-filament.com>)
    # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
    
    from odoo import api, fields, models
    
    
    class AccountInvoice(models.Model):
        _inherit = "account.invoice"
    
        with_detail = fields.Boolean("Facture avec détail", default=False)
        employee_allocation_ids = fields.One2many(
            comodel_name="account.invoice.employee.assign",
            inverse_name="invoice_id",
            string="Ventilation facture",
        )
        is_allocated = fields.Boolean(
            string="Facture ventilée",
            compute="_compute_allocation",
            store=True,
            default=False,
        )
        is_allocation_error = fields.Boolean(
            string="Erreur de ventilation",
            compute="_compute_allocation",
            store=True,
            default=False,
        )
    
        # ------------------------------------------------------
        # Computed field
        # ------------------------------------------------------
        @api.depends("employee_allocation_ids", "employee_allocation_ids.percentage")
        @api.multi
        def _compute_allocation(self):
            for invoice in self:
                if invoice.employee_allocation_ids:
                    invoice.is_allocated = True
                    if sum(invoice.employee_allocation_ids.mapped("percentage")) != 100:
                        invoice.is_allocation_error = True
                    else:
                        invoice.is_allocation_error = False
                else:
                    invoice.is_allocated = False
                    invoice.is_allocation_error = False