Skip to content
Extraits de code Groupes Projets
Sélectionner une révision Git
  • 1090607d8c8501b4a4d518ec26335c8e5447f9f3
  • 12.0 par défaut protégée
  • 12-RV-Quantity-default_value
3 résultats

__manifest__.py

Blame
  • Bifurcation depuis Le Filament / Confédération Générale des SCOP / cgscop_expense
    Le projet source a une visibilité limitée.
    account_invoice.py 2,89 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)
        subcontracting_amount = fields.Monetary(
            "Montant sous-traitance (HT)",
            track_visibility=True,
        )
        expense_amount = fields.Monetary(
            "Montant frais (HT)",
            track_visibility=True,
        )
        production_amount = fields.Monetary(
            string="CA production",
            compute="_compute_production_amount",
            store=True,
        )
        employee_allocation_ids = fields.One2many(
            comodel_name="account.invoice.employee.assign",
            inverse_name="invoice_id",
            string="Ventilation facture",
            tracking=True,
        )
        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,
        )
        suspicious_client = fields.Boolean(
            "Client douteux",
            default=False,
            tracking=True,
        )
    
        # ------------------------------------------------------
        # 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
    
        @api.depends("amount_untaxed_signed", "subcontracting_amount", "expense_amount")
        @api.multi
        def _compute_production_amount(self):
            for invoice in self:
                invoice.production_amount = (
                    invoice.amount_untaxed_signed
                    - invoice.subcontracting_amount
                    - invoice.expense_amount
                )
    
        # ------------------------------------------------------
        # Business function
        # ------------------------------------------------------
        def get_employee_allocation(self, partner_id):
            self.ensure_one()
            emp_values = self.employee_allocation_ids.filtered(
                lambda e: e.partner_id == partner_id
            )
            return sum(emp_values.mapped("percentage"))
    
        def create_employee_lines(self, vals):
            self.ensure_one()
            self.employee_allocation_ids.unlink()
            self.update(vals)