Skip to content
Extraits de code Groupes Projets
Valider 9eb4895b rédigé par Benjamin - Le Filament's avatar Benjamin - Le Filament
Parcourir les fichiers

[update] theoric timesheet hours

parent 738fe395
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
# © 2019 Le Filament (<http://www.le-filament.com>) # © 2019 Le Filament (<http://www.le-filament.com>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from datetime import date
from dateutil.relativedelta import relativedelta
from odoo import api, fields, models from odoo import api, fields, models
...@@ -30,7 +34,7 @@ MONTHS = [ ...@@ -30,7 +34,7 @@ MONTHS = [
class ScopMonthTimesheet(models.Model): class ScopMonthTimesheet(models.Model):
_name = "ur.month.timesheet" _name = "ur.month.timesheet"
_description = "Heures theoriques mensuelles" _description = "Heures theoriques mensuelles"
_order = "year, month" _order = "date_timesheet"
def _default_ur(self): def _default_ur(self):
return self.env["res.company"]._ur_default_get() return self.env["res.company"]._ur_default_get()
...@@ -39,6 +43,11 @@ class ScopMonthTimesheet(models.Model): ...@@ -39,6 +43,11 @@ class ScopMonthTimesheet(models.Model):
selection=get_years(), string="Année", default=fields.Date.today().year selection=get_years(), string="Année", default=fields.Date.today().year
) )
month = fields.Selection(selection=MONTHS, string="Mois") month = fields.Selection(selection=MONTHS, string="Mois")
date_timesheet = fields.Date(
string="Mois format date",
compute="_compute_date_timesheet",
store=True,
)
company_id = fields.Many2one( company_id = fields.Many2one(
comodel_name="res.company", comodel_name="res.company",
string="Société", string="Société",
...@@ -61,34 +70,33 @@ class ScopMonthTimesheet(models.Model): ...@@ -61,34 +70,33 @@ class ScopMonthTimesheet(models.Model):
) )
] ]
@api.depends("year", "month")
def _compute_date_timesheet(self):
for month in self:
date_timesheet = date(int(month.year), int(month.month), 1)
month.date_timesheet = date_timesheet
@api.model @api.model
def get_month_values(self): def get_month_values(self):
month_values = self.search( today = date.today()
first_date = today.replace(day=1) - relativedelta(months=6)
last_date = today.replace(day=1) + relativedelta(months=6)
values = self.search(
[ [
"&", ("date_timesheet", ">=", first_date),
"|", ("date_timesheet", "<=", last_date),
"&", ("ur_id", "=", self.env.company.ur_id.id),
("year", "<", fields.Date.today().year), ]
("month", ">", fields.Date.today().month), )
"&",
("year", "<", fields.Date.today().year + 1),
("month", "<=", fields.Date.today().month + 1),
("ur_id", "=", self.env.user.ur_id.id),
],
limit=12,
order="year desc, month desc",
).sorted(reverse=False)
return { return {
"month": month_values.mapped( "month_values": values.mapped(
lambda x: { lambda m: {
"year": x.year, "year": m.year,
"num_month": x.month, "month": self._fields["month"].selection[int(m.month) - 1][1],
"month": self._fields["month"].selection[int(x.month) - 1][1], "working_time": m.working_time,
"date_timesheet": m.date_timesheet,
} }
), ),
"values": month_values.mapped("working_time"), "today": today.replace(day=1),
"today": {
"year": fields.Date.today().year,
"month": fields.Date.today().month,
},
} }
...@@ -3,32 +3,34 @@ ...@@ -3,32 +3,34 @@
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). --> License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -->
<templates xml:space="preserve"> <templates xml:space="preserve">
<t t-name="ScopMonthTimesheet"> <t t-name="ScopMonthTimesheet">
<t t-if="widget.values.month_values">
<table class="table"> <table class="table">
<thead> <thead>
<tr> <tr>
<t t-foreach="widget.values.month" t-as="m"> <th t-foreach="widget.values.month_values" t-as="m">
<t <div
t-if="m.num_month == widget.values.today.month and m.year == widget.values.today.year" t-att-class="m.date_timesheet == widget.values.today ? 'text-success' : ''"
> >
<th class="text-success">
<t t-esc="m.month" /> <t t-esc="m.year" /> <t t-esc="m.month" /> <t t-esc="m.year" />
</div>
</th> </th>
</t>
<t t-else="">
<th>
<t t-esc="m.month" /> <t t-esc="m.year" />
</th>
</t>
</t>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<tr> <tr>
<t t-foreach="widget.values.values" t-as="v"> <td t-foreach="widget.values.month_values" t-as="m">
<td><t t-esc="v" /> h</td> <div
</t> t-att-class="m.date_timesheet == widget.values.today ? 'text-right text-success' : 'text-right'"
>
<t t-esc="m.working_time" /> h
</div>
</td>
</tr> </tr>
</tbody> </tbody>
</table> </table>
</t> </t>
<t t-else="">
<p>Aucun temps de travail théorique n'a été configuré.</p>
</t>
</t>
</templates> </templates>
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