diff --git a/models/cgscop_timesheet_sheet.py b/models/cgscop_timesheet_sheet.py index e6c87c2b080c891cddfec021a303ea117ce2cdfe..1dfc7811577dee2c473e32c059750ac1b1b08a62 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 c5563020713be3e355a448bd8acabf7e10fe1af6..19ab3dad516e3abcf6c28ab4ab6713ccdfae6dd1 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>