Skip to content
Snippets Groups Projects
Commit 0fb49576 authored by Rémi - Le Filament's avatar Rémi - Le Filament
Browse files

[UPD] allocation of hours on projects

parent 2b553d81
No related branches found
No related tags found
No related merge requests found
......@@ -8,7 +8,8 @@ LE FILAMENT - LIEN COMMANDES PROJET
====================================
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
=======
......
......@@ -7,4 +7,6 @@ from odoo import fields, models
class Company(models.Model):
_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):
_inherit = "res.config.settings"
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):
_inherit = "sale.order"
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):
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
......@@ -8,23 +8,15 @@
name="name"
>res.config.settings.view.form.inherit.link.sale.project</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">
<div class="app_settings_block" data-string="Sales" position="inside">
<h2>Configuration devis-projet</h2>
<div class="row mt16 o_settings_container">
<div class="col-12 col-lg-6 o_setting_box">
<div class="o_setting_right_pane">
<label
for="taux_horaire"
string="Taux horaire"
class="col-3 col-lg-3 o_light_label"
/>
<field name="taux_horaire" class="oe_inline" required="1" />
</div>
</div>
</div>
</div>
<app name="sale_management" position="inside">
<block title="Configuration devis-projet" id="sale_project_hourly_cost">
<setting id="hourly_cost">
<field name="taux_horaire" string="Taux horaire (€/h)" />
</setting>
</block>
</app>
</field>
</record>
......
......@@ -10,10 +10,7 @@
<field name="priority">100</field>
<field name="arch" type="xml">
<field name="payment_term_id" position="after">
<field
name="taux_horaire"
attrs="{'readonly':[('state','!=','draft')]}"
/>
<field name="taux_horaire" readonly="state != 'draft'" />
</field>
</field>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment