Skip to content
Extraits de code Groupes Projets
Valider 48c00e4a rédigé par Rémi - Le Filament's avatar Rémi - Le Filament
Parcourir les fichiers

[UPD] allocation of hours on projects

parent 1b1dafab
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -8,7 +8,8 @@ LE FILAMENT - LIEN COMMANDES PROJET ...@@ -8,7 +8,8 @@ LE FILAMENT - LIEN COMMANDES PROJET
==================================== ====================================
Modifie le module Sale: Modifie le module Sale:
- Fais le lien entre les commandes et les projets - Ajoute le taux horaire sur la société et sur les bons de commande
- Convertit les prix vendu en heures (en divisant par le taux horaire) lors de la création des tâches
Credits Credits
======= =======
......
...@@ -7,4 +7,6 @@ from odoo import fields, models ...@@ -7,4 +7,6 @@ from odoo import fields, models
class Company(models.Model): class Company(models.Model):
_inherit = "res.company" _inherit = "res.company"
taux_horaire = fields.Integer(required=True, default=100) taux_horaire = fields.Integer(
string="Taux horaire (€/h)", required=True, default=100
)
...@@ -8,5 +8,5 @@ class ResConfigSettings(models.TransientModel): ...@@ -8,5 +8,5 @@ class ResConfigSettings(models.TransientModel):
_inherit = "res.config.settings" _inherit = "res.config.settings"
taux_horaire = fields.Integer( taux_horaire = fields.Integer(
"Taux horaire", related="company_id.taux_horaire", readonly=False "Taux horaire (€/h)", related="company_id.taux_horaire", readonly=False
) )
...@@ -8,5 +8,5 @@ class SaleOrder(models.Model): ...@@ -8,5 +8,5 @@ class SaleOrder(models.Model):
_inherit = "sale.order" _inherit = "sale.order"
taux_horaire = fields.Integer( taux_horaire = fields.Integer(
"Taux horaire", default=lambda self: self.env.company.taux_horaire "Taux horaire (€/h)", default=lambda self: self.env.company.taux_horaire
) )
...@@ -22,3 +22,41 @@ class SaleOrderLine(models.Model): ...@@ -22,3 +22,41 @@ class SaleOrderLine(models.Model):
else: else:
planned_hours = (self.product_uom_qty * self.price_unit) / taux_horaire planned_hours = (self.product_uom_qty * self.price_unit) / taux_horaire
return planned_hours 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
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
name="name" name="name"
>res.config.settings.view.form.inherit.link.sale.project</field> >res.config.settings.view.form.inherit.link.sale.project</field>
<field name="model">res.config.settings</field> <field name="model">res.config.settings</field>
<field name="inherit_id" ref="project.res_config_settings_view_form" /> <field name="inherit_id" ref="sale.res_config_settings_view_form" />
<field name="arch" type="xml"> <field name="arch" type="xml">
<div class="app_settings_block" data-string="Sales" position="inside"> <div class="app_settings_block" data-string="Sales" position="inside">
<h2>Configuration devis-projet</h2> <h2>Configuration devis-projet</h2>
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter