From 869c3ec78201e68106f99e20dd6e305486c55594 Mon Sep 17 00:00:00 2001 From: "CGSCOP\\hsilvant" <hsilvant@scop.coop> Date: Wed, 17 Jan 2024 17:25:54 +0100 Subject: [PATCH] =?UTF-8?q?Ajout=20d'un=20total=20par=20activit=C3=A9=20su?= =?UTF-8?q?r=20l'impression=20de=20la=20feuille=20de=20temps?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- models/cgscop_timesheet_sheet.py | 51 ++++++++++++++++++++++++++++++ report/report_hr_timesheet_act.xml | 30 +++++++++++------- 2 files changed, 69 insertions(+), 12 deletions(-) diff --git a/models/cgscop_timesheet_sheet.py b/models/cgscop_timesheet_sheet.py index e6c87c2..1dfc781 100644 --- a/models/cgscop_timesheet_sheet.py +++ b/models/cgscop_timesheet_sheet.py @@ -123,3 +123,54 @@ class ScopHrTimesheetSheet(models.Model): return self.env.ref( "cgscop_timesheet.cgscop_timesheet_sheet_report" ).report_action(self) + + # ------------------------------------------------------ + # Retourne les lignes de la Fdt avec les totaux par projet + # ------------------------------------------------------ + def _to_duration(self, infloat): + return '{0:02.0f}:{1:02.0f}'.format(*divmod(infloat * 60, 60)) + def _get_timesheet_line_act(self): + for sheet in self: + lines = sheet.timesheet_line_ids.sorted(key=lambda b: (b.project_id.name, b.date)) + rows = [] + last_project = False + tot_project = 0 + for line in lines: + # On insère un total intermédiaire + if last_project != line.project_id.name and tot_project != 0: + rows.append({ + 'total': 1, + 'name': False, + 'partner': False, + 'project': False, + 'date': False, + 'ur_financial_system': 'Total ' + last_project + ' : ' + self._to_duration(tot_project), + 'unit_amount': False, + }) + tot_project = 0 + + # On insère la ligne lue + rows.append({ + 'total': 0, + 'name': line.name, + 'partner': line.partner_id.name, + 'project': line.project_id.name, + 'date': line.date, + 'ur_financial_system': line.ur_financial_system_id.name, + 'unit_amount': self._to_duration(line.unit_amount), + }) + last_project = line.project_id.name + tot_project = tot_project + line.unit_amount + + # On insère le dernier total + rows.append({ + 'total': 1, + 'name': False, + 'partner': False, + 'project': False, + 'date': False, + 'ur_financial_system': 'Total ' + last_project + ' : ' + self._to_duration(tot_project), + 'unit_amount': False, + }) + + return rows diff --git a/report/report_hr_timesheet_act.xml b/report/report_hr_timesheet_act.xml index c556302..19ab3da 100644 --- a/report/report_hr_timesheet_act.xml +++ b/report/report_hr_timesheet_act.xml @@ -51,21 +51,27 @@ </thead> <tbody class="invoice_tbody"> <t - t-foreach="o.timesheet_line_ids.sorted(key=lambda b: (b.project_id.name,b.date))" + t-foreach="o._get_timesheet_line_act()" t-as="line" > <tr> - <td><span t-field="line.project_id" /></td> - <td><span t-field="line.date" /></td> - <td><span t-field="line.partner_id" /></td> - <td><span t-field="line.name" /></td> - <td><span - t-field="line.ur_financial_system_id" - /></td> - <td class="text-right"><span - t-field="line.unit_amount" - t-options="{'widget': 'duration', 'digital': True, 'unit': 'hour', 'round': 'minute'}" - /></td> + <td><span><t t-esc="line['project']"/></span></td> + <td><span><t t-esc="line['date']"/></span></td> + <td><span><t t-esc="line['partner']"/></span></td> + <td><span><t t-esc="line['name']"/></span></td> + <td><span> + <t t-if="line['total']==1"> + <strong> + <t t-esc="line['ur_financial_system']"/> + </strong> + </t> + <t t-if="line['total']==0"> + <t t-esc="line['ur_financial_system']"/> + </t> + </span></td> + <td class="text-right"><span> + <t t-esc="line['unit_amount']"/> + </span></td> </tr> </t> <tr> -- GitLab