From ce13ee7a1233505e60ab79098b1153842d82cc29 Mon Sep 17 00:00:00 2001
From: "CGSCOP\\hsilvant" <hsilvant@scop.coop>
Date: Fri, 13 Oct 2023 09:37:53 +0200
Subject: [PATCH] =?UTF-8?q?Ajout=20d'une=20impression=20Fdt=20tri=C3=A9e?=
 =?UTF-8?q?=20par=20code=20activit=C3=A9?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 __init__.py                              |   1 +
 __manifest__.py                          |   2 +
 report/report_hr_timesheet.xml           |   1 -
 report/report_hr_timesheet_act.xml       | 129 +++++++++++++++++++++++
 security/ir.model.access.csv             |   1 +
 views/cgscop_timesheet_sheet.xml         |   5 +-
 wizard/__init__.py                       |   6 ++
 wizard/cgscop_timesheet_print_wizard.py  |  40 +++++++
 wizard/cgscop_timesheet_print_wizard.xml |  38 +++++++
 9 files changed, 220 insertions(+), 3 deletions(-)
 create mode 100644 report/report_hr_timesheet_act.xml
 create mode 100644 wizard/__init__.py
 create mode 100644 wizard/cgscop_timesheet_print_wizard.py
 create mode 100644 wizard/cgscop_timesheet_print_wizard.xml

diff --git a/__init__.py b/__init__.py
index d997a09..bf853b2 100644
--- a/__init__.py
+++ b/__init__.py
@@ -2,3 +2,4 @@
 # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
 
 from . import models
+from . import wizard
diff --git a/__manifest__.py b/__manifest__.py
index 4a1b813..67b7824 100644
--- a/__manifest__.py
+++ b/__manifest__.py
@@ -18,6 +18,7 @@
     "data": [
         "security/ir.model.access.csv",
         "security/security_rules.xml",
+        "wizard/cgscop_timesheet_print_wizard.xml",
         "views/assets.xml",
         "views/cgscop_timesheet_code.xml",
         "views/cgscop_timesheet_sheet.xml",
@@ -29,6 +30,7 @@
         "views/ur_month_timesheet.xml",
         "views/ur_regional_convention.xml",
         "report/report_hr_timesheet.xml",
+        "report/report_hr_timesheet_act.xml",
         "datas/cgscop_timesheet_code_data.xml",
     ],
     "qweb": [
diff --git a/report/report_hr_timesheet.xml b/report/report_hr_timesheet.xml
index 8df120f..7c5f1fb 100644
--- a/report/report_hr_timesheet.xml
+++ b/report/report_hr_timesheet.xml
@@ -140,6 +140,5 @@
             <field name="report_file">cgscop_timesheet.report_timesheet_sheet</field>
             <field name="paperformat_id" ref="cgscop_paperformat_a4_landscape" />
         </record>
-
     </data>
 </odoo>
diff --git a/report/report_hr_timesheet_act.xml b/report/report_hr_timesheet_act.xml
new file mode 100644
index 0000000..cf4dc70
--- /dev/null
+++ b/report/report_hr_timesheet_act.xml
@@ -0,0 +1,129 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<odoo>
+    <data>
+        <template id="report_timesheet_document_act">
+            <t t-call="web.external_layout">
+                <div class="page">
+                    <h2>
+                        Feuille de Temps par activité <t t-if="o.state == 'draft'"> - Brouillon</t>
+                    </h2>
+                    <h3>
+                        <t t-esc="o.name" />
+                    </h3>
+
+                    <div id="informations" class="row mt32 mb32">
+                        <div class="col-auto mw-100 mb-2" name="employee">
+                            <strong>Employé</strong>
+                            <p class="m-0" t-field="o.employee_id.name" />
+                        </div>
+                        <div class="col-auto mw-100 mb-2">
+                            <strong>Soumis le</strong>
+                            <p class="m-0" t-field="o.submit_date" />
+                        </div>
+                        <div class="col-auto mw-100 mb-2" name="date_end">
+                            <strong>Validé le</strong>
+                            <p class="m-0" t-field="o.validation_date" />
+                        </div>
+                        <div class="col-auto mw-100 mb-2" name="date_end">
+                            <strong>Total</strong>
+                            <p
+                                class="m-0"
+                                t-field="o.total_hour"
+                                t-options="{'widget': 'duration', 'digital': True, 'unit': 'hour', 'round': 'minute'}"
+                            />
+                        </div>
+                    </div>
+
+                    <table
+                        class="table table-sm o_main_table"
+                        name="invoice_line_table"
+                    >
+                        <thead>
+                            <tr>
+                                <th class="text-left"><span>Code activité UR</span></th>
+                                <th class="text-left"><span>Date</span></th>
+                                <th class="text-left"><span>Contact</span></th>
+                                <th class="text-left"><span>Description</span></th>
+                                <th class="text-left"><span
+                                    >Dispositif Financier</span></th>
+                                <th class="text-left"><span>Durée</span></th>
+                            </tr>
+                        </thead>
+                        <tbody class="invoice_tbody">
+                            <t
+                                t-foreach="o.timesheet_line_ids.sorted(key=lambda b: (b.project_id,b.date))"
+                                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>
+                                </tr>
+                            </t>
+                            <tr>
+                                <td />
+                                <td />
+                                <td />
+                                <td />
+                                <td class="text-right"><strong>Total</strong></td>
+                                <td class="text-right"><strong
+                                        t-esc="o.total_hour"
+                                        t-options="{'widget': 'duration', 'digital': True, 'unit': 'hour', 'round': 'minute'}"
+                                    /></td>
+                            </tr>
+                        </tbody>
+                    </table>
+                    <div
+                        t-if="o.state == 'draft'"
+                    >Cette feuille de temps a été éditée en brouillon.</div>
+                    <div t-else="">
+                        <table style="float: right;">
+                            <tr>
+                                <td
+                                    style="width: 300px; border-bottom: 1px solid #495057; text-align: center;"
+                                >
+                                    Visa salarié
+                                </td>
+                                <td
+                                    style="width: 300px; border-bottom: 1px solid #495057; text-align: center;"
+                                >
+                                    Visa direction
+                                </td>
+                            </tr>
+                            <tr>
+                                <td><br /><br /><br /></td>
+                                <td><br /><br /><br /></td>
+                            </tr>
+                        </table>
+                    </div>
+                </div>
+            </t>
+        </template>
+
+        <template id="report_timesheet_sheet_act">
+            <t t-call="web.html_container">
+                <t t-foreach="docs" t-as="o">
+                    <t t-call="cgscop_timesheet.report_timesheet_document_act" />
+                </t>
+            </t>
+        </template>
+
+        <record id="cgscop_timesheet_sheet_report_act" model="ir.actions.report">
+            <field name="name">CG Scop - Feuille de Temps par activité</field>
+            <field name="model">cgscop.timesheet.sheet</field>
+            <field name="report_type">qweb-pdf</field>
+            <field name="report_name">cgscop_timesheet.report_timesheet_sheet_act</field>
+            <field name="report_file">cgscop_timesheet.report_timesheet_sheet_act</field>
+            <field name="paperformat_id" ref="cgscop_paperformat_a4_landscape" />
+        </record>
+
+    </data>
+</odoo>
diff --git a/security/ir.model.access.csv b/security/ir.model.access.csv
index a00e653..1de5fb9 100644
--- a/security/ir.model.access.csv
+++ b/security/ir.model.access.csv
@@ -15,3 +15,4 @@ access_ur_regional_convention_cg_manager,access_ur_regional_convention_cg,model_
 access_ur_month_timesheet,access_ur_month_timesheet,model_ur_month_timesheet,base.group_user,1,0,0,0
 access_ur_month_timesheet_ur_manager,access_ur_month_timesheet_ur,model_ur_month_timesheet,cgscop_partner.group_ur_list_modif,1,1,1,1
 access_ur_month_timesheet_cg_manager,access_ur_month_timesheet_cg,model_ur_month_timesheet,cgscop_partner.group_cg_administrator,1,1,1,1
+access_cgscop_timesheet_print_wizard,access_cgscop_timesheet_print_wizard,model_cgscop_timesheet_print_wizard,base.group_user,1,1,1,1
diff --git a/views/cgscop_timesheet_sheet.xml b/views/cgscop_timesheet_sheet.xml
index df3eb19..92fde3d 100644
--- a/views/cgscop_timesheet_sheet.xml
+++ b/views/cgscop_timesheet_sheet.xml
@@ -46,9 +46,10 @@
                             class="oe_highlight"
                         />
                         <button
-                            name="print_timesheet"
                             string="Imprimer"
-                            type="object"
+                            type="action"
+                            name="%(cgscop_timesheet_print_act)d"
+                            class="oe_read_only"
                         />
                         <button
                             name="reset_timesheet_sheets"
diff --git a/wizard/__init__.py b/wizard/__init__.py
new file mode 100644
index 0000000..0cfc1de
--- /dev/null
+++ b/wizard/__init__.py
@@ -0,0 +1,6 @@
+# © 2020 Le Filament (<https://www.le-filament.com>)
+# © 2020 Confédération Générale des Scop (<https://www.les-scop.coop>)
+# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
+
+from . import cgscop_timesheet_print_wizard
+
diff --git a/wizard/cgscop_timesheet_print_wizard.py b/wizard/cgscop_timesheet_print_wizard.py
new file mode 100644
index 0000000..90c2160
--- /dev/null
+++ b/wizard/cgscop_timesheet_print_wizard.py
@@ -0,0 +1,40 @@
+# © 2020 Le Filament (<https://www.le-filament.com>)
+# © 2020 Confédération Générale des Scop (<https://www.les-scop.coop>)
+# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
+
+from odoo import _, api, exceptions, fields, models
+
+
+class CgscopTimesheetPrintWizard(models.TransientModel):
+    _name = "cgscop_timesheet.print.wizard"
+    _description = "Wizard de sélection de l'impression"
+
+    @api.model
+    def _default_timesheet_id(self):
+        return self.env.context.get("active_id")
+
+    timesheet_id = fields.Many2one(
+        comodel_name="cgscop.timesheet.sheet",
+        string="Fdt",
+        default=_default_timesheet_id,
+    )
+
+    print_type = fields.Selection(
+        string="Type de sortie",
+        selection=[("0", "Tri par date"), ("1", "Tri par code activité")],
+        required=True,
+        default="0",
+    )
+
+    # ------------------------------------------------------
+    # Validation du wizard
+    # ------------------------------------------------------
+    def valid_wizard(self):
+
+        report_name = "cgscop_timesheet.cgscop_timesheet_sheet_report"
+        if self.print_type == '0':
+            report_name = "cgscop_timesheet.cgscop_timesheet_sheet_report"
+        elif self.print_type == '1':
+            report_name = "cgscop_timesheet.cgscop_timesheet_sheet_report_act"
+
+        return self.env.ref(report_name).report_action(self.timesheet_id)
diff --git a/wizard/cgscop_timesheet_print_wizard.xml b/wizard/cgscop_timesheet_print_wizard.xml
new file mode 100644
index 0000000..a3437c9
--- /dev/null
+++ b/wizard/cgscop_timesheet_print_wizard.xml
@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<odoo>
+    <!-- WIZARD FORM -->
+    <record model="ir.ui.view" id="cgscop_timesheet_print_wizard">
+        <field name="name">cgscop_timesheet_print_wizard</field>
+        <field name="model">cgscop_timesheet.print.wizard</field>
+        <field name="arch" type="xml">
+            <form string="Sélection du format de sortie">
+                <group>
+                    <field name="print_type" widget="radio" />
+                </group>
+                <footer>
+                    <button
+                        class="btn btn-sm btn-primary"
+                        name="valid_wizard"
+                        string="Impression"
+                        type="object"
+                    />
+                    <button
+                        class="btn btn-sm btn-default"
+                        special="cancel"
+                        string="Retour"
+                    />
+                </footer>
+            </form>
+        </field>
+    </record>
+
+    <record model="ir.actions.act_window" id="cgscop_timesheet_print_act">
+        <field name="name">Sélection du format de sortie</field>
+        <field name="type">ir.actions.act_window</field>
+        <field name="res_model">cgscop_timesheet.print.wizard</field>
+        <field name="view_mode">form</field>
+        <field name="view_id" ref="cgscop_timesheet_print_wizard" />
+        <field name="target">new</field>
+    </record>
+
+</odoo>
-- 
GitLab