Skip to content
Extraits de code Groupes Projets
sale_order_line.py 2,31 ko
Newer Older
  • Learn to ignore specific revisions
  • Rémi - Le Filament's avatar
    Rémi - Le Filament a validé
    # Copyright 2019- Le Filament (<https://le-filament.com>)
    # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
    
    from odoo import models
    
    
    class SaleOrderLine(models.Model):
        _inherit = "sale.order.line"
    
        def _convert_qty_company_hours(self, dest_company):
            """
            Reprise de la fonction native pour changer le mode de calcul des heures
            planifiées dans timesheet
            """
            company_time_uom_id = dest_company.project_time_mode_id
            taux_horaire = self.order_id.taux_horaire
            if (
                self.product_uom.id != company_time_uom_id.id
                and self.product_uom.category_id.id == company_time_uom_id.category_id.id
            ):
                planned_hours = super()._convert_qty_company_hours(dest_company)
            else:
                planned_hours = (self.product_uom_qty * self.price_unit) / taux_horaire
            return planned_hours
    
    
        def _timesheet_create_project(self):
            """
            Reprise de la fonction native pour changer le mode de calcul des heures
            planifiées dans timesheet
            """
            project = super()._timesheet_create_project()
    
            project_uom = self.company_id.project_time_mode_id
            uom_hour = self.env.ref("uom.product_uom_hour")
            unit_factor = project_uom.factor * uom_hour.factor_inv
    
            uom_unit = self.env.ref("uom.product_uom_unit")
    
            allocated_hours = project.allocated_hours
            # for sale_order_line in sale_order for the same project
            # we deduce default allocation of units (Odoo considers that 1 unit = 1 hour)
            # and we recalculate hours depending on taux_horaire
            for line in self.order_id.order_line:
                if (
                    line.is_service
                    and line.product_id.service_tracking
                    in ["task_in_project", "project_only"]
                    and line.product_id.project_template_id
                    == self.product_id.project_template_id
                    and line.product_uom == uom_unit
                ):
                    allocated_hours -= line.product_uom_qty * unit_factor
                    allocated_hours += (
                        line.product_uom_qty * line.price_unit
                    ) / self.order_id.taux_horaire
    
            project.write(
                {
                    "allocated_hours": allocated_hours,
                }
            )
            return project