diff --git a/models/res_partner.py b/models/res_partner.py index 4fc3f33784ab621c32adcec6bcbcda19791ced8b..4688e1502e71a14436bedc200509e40a8f0b9d13 100644 --- a/models/res_partner.py +++ b/models/res_partner.py @@ -66,6 +66,27 @@ class ScopPartner(models.Model): comodel_name="scop.liasse.fiscale", string="Liasse fiscale adhésion" ) + # Temps estimé/Réalisé + estimated_time = fields.Float("Durée estimée") + invoiced_creation = fields.Float("Durée facturée (création)") + invoiced_followup = fields.Float("Durée facturée (suivi)") + realized_time = fields.Float( + string="Durée réelle", + compute="_compute_real_time", + ) + realized_creation = fields.Float( + string="Durée réelle (création)", + compute="_compute_real_time", + ) + realized_followup = fields.Float( + string="Durée réelle (suivi)", + compute="_compute_real_time", + ) + is_estimated_time_ok = fields.Boolean( + string="Estimation ok", + compute="_compute_real_time", + ) + # Changement de statuts list_logs = fields.Text("Liste des erreurs") @@ -78,6 +99,39 @@ class ScopPartner(models.Model): if partner.date_first_rdv: partner.year_project = str(partner.date_first_rdv.year) + @api.depends("estimated_time") + def _compute_real_time(self): + """ + Champs calculés temps réels + """ + for rec in self: + # Liste des lignes de temps pour ce partner + ldts = self.env["account.analytic.line"].sudo().search( + [ + ("partner_id", "=", rec.id), + ] + ) + rec.realized_time = 0 + rec.realized_creation = 0 + rec.realized_followup = 0 + for ldt in ldts: + # On totalise les heures de développement + if (ldt.project_id.cgscop_timesheet_code_id != False and + ldt.project_id.cgscop_timesheet_code_id.domain == 'D'): + rec.realized_time = rec.realized_time + ldt.unit_amount + # On totalise les heures facturés + if ldt.project_id.creation_invoiced == True: + if (ldt.project_id.cgscop_timesheet_code_id != False and + ldt.project_id.cgscop_timesheet_code_id.domain == 'A'): + rec.realized_followup = rec.realized_followup + ldt.unit_amount + if (ldt.project_id.cgscop_timesheet_code_id != False and + ldt.project_id.cgscop_timesheet_code_id.domain == 'D'): + rec.realized_creation = rec.realized_creation + ldt.unit_amount + + # On ajoute les heures de suivi facturées au titre du dev + rec.realized_time = rec.realized_time + rec.realized_followup + rec.is_estimated_time_ok = rec.realized_time <= rec.estimated_time + # ------------------------------------------------------ # Onchange function # ------------------------------------------------------ diff --git a/views/res_partner.xml b/views/res_partner.xml index beefbe8e60679777c07f09f96dde3b4ea7dddd54..d6a1a87e8b5f1acf1bce92089930531e5f8e9a55 100644 --- a/views/res_partner.xml +++ b/views/res_partner.xml @@ -28,6 +28,38 @@ readonly="1" /> </div> + <field name="estimated_time" invisible="1"/> + <field name="is_estimated_time_ok" invisible="1"/> + <field name="project_status" invisible="1"/> + <div + class="alert alert-danger" + role="alert" + attrs="{'invisible':['|', '|', + ('estimated_time','<=',0), + ('is_estimated_time_ok','!=',False), + ('project_status','in',('1_information','2_pre-diagnostic'))]}" + > + Heures passées : + <field + name="realized_time" + readonly="1" + /> + </div> + <div + class="alert alert-success" + role="alert" + attrs="{'invisible':[ '|','|', + ('estimated_time','<=',0), + ('is_estimated_time_ok','=',False), + ('project_status','in',('1_information','2_pre-diagnostic'))]}" + > + Heures passées : + <field + name="realized_time" + readonly="1" + /> + </div> + </xpath> </field> </record> @@ -215,6 +247,57 @@ <field name="date_convention" /> <field name="amount_convention" widget="monetary" /> </group> + <group + string="Estimation des temps" + attrs="{'invisible':[('project_status','in',('1_information','2_pre-diagnostic'))]}" + + > + <table class="table table-bordered"> + <thead> + <tr> + <th /> + <th>(heures) </th> + <th>Réel</th> + </tr> + </thead> + <tbody> + <tr> + <th> + <label for="estimated_time"/> + </th> + <td> + <field name="estimated_time" /> + </td> + <td> + <field name="realized_time" /> + </td> + </tr> + <tr attrs="{'invisible':[('ur_id','!=',%(cgscop_partner.riga_14353)d)]}"> + <th> + <label for="invoiced_creation"/> + </th> + <td> + <field name="invoiced_creation" /> + </td> + <td> + <field name="realized_creation" /> + </td> + </tr> + <tr attrs="{'invisible':[('ur_id','!=',%(cgscop_partner.riga_14353)d)]}"> + <th> + <label for="invoiced_followup"/> + </th> + <td> + <field name="invoiced_followup" /> + </td> + <td> + <field name="realized_followup" /> + </td> + </tr> + + </tbody> + </table> + </group> </group> </page> @@ -329,6 +412,58 @@ <field name="date_convention" /> <field name="amount_convention" widget="monetary" /> </group> + <group + string="Estimation des temps" + attrs="{'invisible':[('project_status','in',('1_information','2_pre-diagnostic'))]}" + + > + <table class="table table-bordered"> + <thead> + <tr> + <th /> + <th>(heures) </th> + <th>Réel</th> + </tr> + </thead> + <tbody> + <tr> + <th> + <label for="estimated_time"/> + </th> + <td> + <field name="estimated_time" /> + </td> + <td> + <field name="realized_time" /> + </td> + </tr> + <tr attrs="{'invisible':[('ur_id','!=',%(cgscop_partner.riga_14353)d)]}"> + <th> + <label for="invoiced_creation"/> + </th> + <td> + <field name="invoiced_creation" /> + </td> + <td> + <field name="realized_creation" /> + </td> + </tr> + <tr attrs="{'invisible':[('ur_id','!=',%(cgscop_partner.riga_14353)d)]}"> + <th> + <label for="invoiced_followup"/> + </th> + <td> + <field name="invoiced_followup" /> + </td> + <td> + <field name="realized_followup" /> + </td> + </tr> + + </tbody> + </table> + </group> + </group> </page> </page> @@ -370,6 +505,12 @@ <field name="date_prediag" optional="hide" /> <field name="date_convention" optional="hide" /> <field name="date_transmission_cg" optional="hide" /> + <field name="estimated_time" optional="hide" /> + <field name="realized_time" optional="hide" /> + <field name="invoiced_creation" optional="hide" /> + <field name="realized_creation" optional="hide" /> + <field name="invoiced_followup" optional="hide" /> + <field name="realized_followup" optional="hide" /> </field> </field> </record>