From e5aa1f1d1073f584908bb17115ec0ddf2060a845 Mon Sep 17 00:00:00 2001
From: Juliana <juliana@le-filament.com>
Date: Tue, 17 Aug 2021 11:13:37 +0200
Subject: [PATCH] [MIG] Migration 14.0

---
 __manifest__.py                    |  2 +-
 models/training_training.py        | 32 +++++++++++++++++++-----------
 report/report_agreement.xml        | 17 ++++++++--------
 report/report_attendance_sheet.xml | 17 ++++++++--------
 report/report_attestation.xml      | 17 ++++++++--------
 report/report_program.xml          | 17 ++++++++--------
 6 files changed, 57 insertions(+), 45 deletions(-)

diff --git a/__manifest__.py b/__manifest__.py
index 933aba2..2190e2c 100644
--- a/__manifest__.py
+++ b/__manifest__.py
@@ -2,7 +2,7 @@
 
 {
     'name': 'Le Filament - Training',
-    'version': '13.0.1.0.0',
+    'version': '14.0.1.0.0',
     'summary': 'Training sessions managment',
     'license': 'AGPL-3',
     'author': 'LE FILAMENT',
diff --git a/models/training_training.py b/models/training_training.py
index c862e86..1667878 100644
--- a/models/training_training.py
+++ b/models/training_training.py
@@ -66,7 +66,8 @@ class Training(models.Model):
         store=True)
     rate = fields.Integer(
         string="Taux horaire",
-        compute='_compute_costs')
+        compute='_compute_costs',
+        default=0)
     students_count = fields.Integer(
         string='Nombre de stagiaires',
         compute='_compute_students_count',
@@ -141,23 +142,29 @@ class Training(models.Model):
     # ------------------------------------------------------
     @api.depends('student_ids')
     def _compute_students_count(self):
-        self.students_count = len(self.student_ids)
+        for record in self:
+            record.students_count = len(record.student_ids)
 
-    @api.depends('student_ids', 'cost')
+    @api.depends('students_count', 'cost', 'hours_total')
     def _compute_costs(self):
-        if self.students_count > 0:
-            self.student_cost = self.cost / self.students_count
-        if self.hours_total > 0:
-            self.rate = self.cost / self.hours_total
+        for record in self:
+            record.student_cost = 0
+            record.rate = 0
+            if record.students_count > 0:
+                record.student_cost = record.cost / record.students_count
+            if record.hours_total > 0:
+                record.rate = record.cost / record.hours_total
 
     @api.depends('session_ids')
     def _compute_sessions(self):
-        self.session_count = len(self.session_ids)
-        self.hours = sum(self.session_ids.mapped('date_delay'))
+        for record in self:
+            record.session_count = len(record.session_ids)
+            record.hours = sum(record.session_ids.mapped('date_delay'))
 
-    @api.depends('session_ids', 'student_ids')
+    @api.depends('students_count', 'hours')
     def _compute_hours_total(self):
-        self.hours_total = self.students_count * self.hours
+        for record in self:
+            record.hours_total = record.students_count * record.hours
 
     @api.depends('order_ids')
     def _compute_amount(self):
@@ -165,7 +172,8 @@ class Training(models.Model):
 
     @api.depends('invoice_ids')
     def _compute_invoiced(self):
-        self.invoiced = sum(self.invoice_ids.mapped('amount_untaxed_signed'))
+        for record in self:
+            record.invoiced = sum(record.invoice_ids.mapped('amount_untaxed_signed'))
 
     # ------------------------------------------------------
     # Buttons
diff --git a/report/report_agreement.xml b/report/report_agreement.xml
index d31562c..eb091ef 100644
--- a/report/report_agreement.xml
+++ b/report/report_agreement.xml
@@ -150,14 +150,15 @@
             <field name="dpi">90</field>
         </record>
 
-	    <report id="report_agreement_pdf"
-            name="lefilament_training.qweb_agreement_pdf"
-            model="training.training"
-            string="Formation - Convention"
-            report_type="qweb-pdf"
-            attachment_use="False"
-            paperformat="paperformat_a4_training"
-	    />
+        <record id="report_agreement_pdf" model="ir.actions.report">
+            <field name="name">Formation - Convention</field>
+            <field name="model">training.training</field>
+            <field name="report_type">qweb-pdf</field>
+            <field name="report_name">lefilament_training.qweb_agreement_pdf</field>
+            <field name="binding_model_id" ref="model_training_training"/>
+            <field name="binding_type">report</field>
+            <field name="paperformat_id" ref="paperformat_a4_training"/>
+        </record>
 
     </data>
 </odoo>
\ No newline at end of file
diff --git a/report/report_attendance_sheet.xml b/report/report_attendance_sheet.xml
index 702d4a9..b8719f6 100644
--- a/report/report_attendance_sheet.xml
+++ b/report/report_attendance_sheet.xml
@@ -109,14 +109,15 @@
             <field name="dpi">90</field>
         </record>
 
-	    <report id="report_attendance_sheet_pdf"
-            name="lefilament_training.qweb_attendance_sheet_pdf"
-            model="training.training"
-            string="Formation - Feuille d'émargement"
-            report_type="qweb-pdf"
-            paperformat="paperformat_a4_training"
-            attachment_use="False"
-	    />
+        <record id="report_attendance_sheet_pdf" model="ir.actions.report">
+            <field name="name">Formation - Feuille d'émargement</field>
+            <field name="model">training.training</field>
+            <field name="report_type">qweb-pdf</field>
+            <field name="report_name">lefilament_training.qweb_attendance_sheet_pdf</field>
+            <field name="binding_model_id" ref="model_training_training"/>
+            <field name="binding_type">report</field>
+            <field name="paperformat_id" ref="paperformat_a4_training"/>
+        </record>
 
     </data>
 </odoo>
\ No newline at end of file
diff --git a/report/report_attestation.xml b/report/report_attestation.xml
index 5419358..e69a4c3 100644
--- a/report/report_attestation.xml
+++ b/report/report_attestation.xml
@@ -65,14 +65,15 @@
             </t>
         </template>
 
-	    <report id="report_attestation_pdf"
-            name="lefilament_training.qweb_attestation_pdf"
-            model="training.training"
-            string="Formation - Attestations"
-            report_type="qweb-pdf"
-            attachment_use="False"
-            paperformat="paperformat_a4_training"
-	    />
+        <record id="report_attestation_pdf" model="ir.actions.report">
+            <field name="name">Formation - Attestations</field>
+            <field name="model">training.training</field>
+            <field name="report_type">qweb-pdf</field>
+            <field name="report_name">lefilament_training.qweb_attestation_pdf</field>
+            <field name="binding_model_id" ref="model_training_training"/>
+            <field name="binding_type">report</field>
+            <field name="paperformat_id" ref="paperformat_a4_training"/>
+        </record>
 
     </data>
 </odoo>
\ No newline at end of file
diff --git a/report/report_program.xml b/report/report_program.xml
index 116e86b..3af3f0c 100644
--- a/report/report_program.xml
+++ b/report/report_program.xml
@@ -78,14 +78,15 @@
             </t>
         </template>
 
-	    <report id="report_program_pdf"
-            name="lefilament_training.qweb_program_pdf"
-            model="training.training"
-            string="Formation - Programme"
-            report_type="qweb-pdf"
-            attachment_use="False"
-            paperformat="paperformat_a4_training"
-	    />
+        <record id="report_program_pdf" model="ir.actions.report">
+            <field name="name">Formation - Programme</field>
+            <field name="model">training.training</field>
+            <field name="report_type">qweb-pdf</field>
+            <field name="report_name">lefilament_training.qweb_program_pdf</field>
+            <field name="binding_model_id" ref="model_training_training"/>
+            <field name="binding_type">report</field>
+            <field name="paperformat_id" ref="paperformat_a4_training"/>
+        </record>
 
     </data>
 </odoo>
-- 
GitLab