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
Branches
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
# © 2019 Le Filament (<http://www.le-filament.com>)
# 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
......@@ -30,7 +34,7 @@ MONTHS = [
class ScopMonthTimesheet(models.Model):
_name = "ur.month.timesheet"
_description = "Heures theoriques mensuelles"
_order = "year, month"
_order = "date_timesheet"
def _default_ur(self):
return self.env["res.company"]._ur_default_get()
......@@ -39,6 +43,11 @@ class ScopMonthTimesheet(models.Model):
selection=get_years(), string="Année", default=fields.Date.today().year
)
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(
comodel_name="res.company",
string="Société",
......@@ -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
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(
[
"&",
"|",
"&",
("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)
("date_timesheet", ">=", first_date),
("date_timesheet", "<=", last_date),
("ur_id", "=", self.env.company.ur_id.id),
]
)
return {
"month": month_values.mapped(
lambda x: {
"year": x.year,
"num_month": x.month,
"month": self._fields["month"].selection[int(x.month) - 1][1],
"month_values": values.mapped(
lambda m: {
"year": m.year,
"month": self._fields["month"].selection[int(m.month) - 1][1],
"working_time": m.working_time,
"date_timesheet": m.date_timesheet,
}
),
"values": month_values.mapped("working_time"),
"today": {
"year": fields.Date.today().year,
"month": fields.Date.today().month,
},
"today": today.replace(day=1),
}
......@@ -3,32 +3,34 @@
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -->
<templates xml:space="preserve">
<t t-name="ScopMonthTimesheet">
<t t-if="widget.values.month_values">
<table class="table">
<thead>
<tr>
<t t-foreach="widget.values.month" t-as="m">
<t
t-if="m.num_month == widget.values.today.month and m.year == widget.values.today.year"
<th t-foreach="widget.values.month_values" t-as="m">
<div
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" />
</div>
</th>
</t>
<t t-else="">
<th>
<t t-esc="m.month" /> <t t-esc="m.year" />
</th>
</t>
</t>
</tr>
</thead>
<tbody>
<tr>
<t t-foreach="widget.values.values" t-as="v">
<td><t t-esc="v" /> h</td>
</t>
<td t-foreach="widget.values.month_values" t-as="m">
<div
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>
</tbody>
</table>
</t>
<t t-else="">
<p>Aucun temps de travail théorique n'a été configuré.</p>
</t>
</t>
</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