Newer
Older
# 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
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
54
55
56
57
58
59
60
61
62
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