From bb1c9194b37c159c6cf339048672007854ae31f1 Mon Sep 17 00:00:00 2001 From: benjamin <benjamin@le-filament.com> Date: Tue, 22 Feb 2022 17:38:17 +0100 Subject: [PATCH] [add] instances management --- __manifest__.py | 1 + models/__init__.py | 1 + models/scop_cotisation_cg_exo.py | 12 ++++++++ models/scop_instance.py | 44 ++++++++++++++++++++++++++++ views/scop_cotisation_cg_exo.xml | 3 +- views/scop_instance.xml | 50 ++++++++++++++++++++++++++++++++ 6 files changed, 110 insertions(+), 1 deletion(-) create mode 100644 models/scop_instance.py create mode 100644 views/scop_instance.xml diff --git a/__manifest__.py b/__manifest__.py index fa07e41..3fdf794 100755 --- a/__manifest__.py +++ b/__manifest__.py @@ -22,6 +22,7 @@ "views/scop_bordereau_cg.xml", "views/scop_cotisation_cg_exo.xml", "views/scop_cotisation_cg_exo_ur_notice.xml", + "views/scop_instance.xml", # templates "templates/report_scop_exo.xml" ] diff --git a/models/__init__.py b/models/__init__.py index 9bd897d..7b239a9 100755 --- a/models/__init__.py +++ b/models/__init__.py @@ -7,3 +7,4 @@ from . import scop_cotisation_cg from . import scop_cotisation_cg_exo_ur_notice from . import scop_cotisation_cg_exo from . import scop_cotisation_cg_exo_line +from . import scop_instance diff --git a/models/scop_cotisation_cg_exo.py b/models/scop_cotisation_cg_exo.py index 3479993..04d8ad5 100644 --- a/models/scop_cotisation_cg_exo.py +++ b/models/scop_cotisation_cg_exo.py @@ -310,6 +310,18 @@ class ScopCotisationExo(models.Model): else: raise UserError("Il est nécessaire de renseigner un avis final pour valider") + def set_favorable(self): + """ + Button function to set exo favorable on instance tree view + """ + self.final_notice = 'favorable' + + def set_unfavorable(self): + """ + Button function to set exo unfavorable on instance tree view + """ + self.final_notice = 'unfavorable' + # ------------------------------------------------------ # Override ORM # ------------------------------------------------------ diff --git a/models/scop_instance.py b/models/scop_instance.py new file mode 100644 index 0000000..16ef1f3 --- /dev/null +++ b/models/scop_instance.py @@ -0,0 +1,44 @@ +# © 2021 Le Filament (<http://www.le-filament.com>) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +import logging +from datetime import timedelta + +from odoo import models, fields, api +from odoo.exceptions import UserError, ValidationError + + +class ScopInstance(models.Model): + _inherit = "scop.instance" + + is_type_exo = fields.Boolean("Exonérations") + exo_ids = fields.One2many( + comodel_name="scop.cotisation.cg.exo", + inverse_name="instance_id", + string="Exonérations" + ) + all_exo_validated = fields.Boolean(compute="_compute_all_exo_validated", default=False) + + # ------------------------------------------------------ + # Computed fields / Search Fields + # ------------------------------------------------------ + @api.multi + def _compute_all_exo_validated(self): + for instance in self: + exo_states = instance.exo_ids.mapped('state') + if not list(set(exo_states) - set(['done', 'cancel'])): + instance.all_exo_validated = True + else: + instance.all_exo_validated = False + + # ------------------------------------------------------ + # Button + # ------------------------------------------------------ + def scop_valid_exo(self): + for exo in self.exo_ids: + if exo.state not in ['done', 'cancel']: + if not exo.date_exo_ok: + exo.date_exo_ok = fields.Date.to_date(self.date) + if not exo.final_notice: + exo.final_notice = 'favorable' + exo.validate_exo() diff --git a/views/scop_cotisation_cg_exo.xml b/views/scop_cotisation_cg_exo.xml index 93583fa..d732a7e 100644 --- a/views/scop_cotisation_cg_exo.xml +++ b/views/scop_cotisation_cg_exo.xml @@ -105,7 +105,8 @@ Le nombre saisi dans le champ ci-dessous correspond au <strong>pourcentage de réduction</strong> appliqué aux échéances. </div> <field name="percent_quarter" attrs="{'invisible': [('type_exo', '!=', 'percent')]}"/> - <button name="create_lines" type="object" class="btn btn-info" string="Créer/Mettre à jour les lignes" attrs="{'invisible': [('state', 'in', ('done', 'cancel'))]}"></button> + <button name="create_lines" type="object" class="btn btn-info" string="Créer/Mettre à jour les lignes" + attrs="{'invisible': ['|', '|', ('state', 'in', ('done', 'cancel')), '&', ('amount_quarter', '=', 0), ('type_exo', '=', 'amount'), '&', ('percent_quarter', '=', 0), ('type_exo', '=', 'percent')]}"></button> <div colspan="2"> <field name="exo_line_ids" attrs="{'readonly': [('state', 'in', ('done', 'cancel'))]}"> diff --git a/views/scop_instance.xml b/views/scop_instance.xml new file mode 100644 index 0000000..b109827 --- /dev/null +++ b/views/scop_instance.xml @@ -0,0 +1,50 @@ +<?xml version="1.0"?> +<!-- Copyright 2021 Le Filament + License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). --> + +<odoo> + <data> + + <record id="scop_instance_exo_form_view" model="ir.ui.view"> + <field name="name">scop.instance.exo.form</field> + <field name="model">scop.instance</field> + <field name="inherit_id" ref="cgscop_instance.scop_instance_form_view"/> + <field name="arch" type="xml"> + <xpath expr="//group[@name='instance_type']" position="inside"> + <field name="is_type_exo" widget="boolean_toggle"/> + </xpath> + <xpath expr="//page[@name='membership']" position="after"> + <page name="exo" string="Exonérations" attrs="{'invisible':[('is_type_exo','!=',True)]}"> + <field name="all_exo_validated" invisible="1"/> + <button name="scop_valid_exo" + type="object" + string="Valider toutes les exonérations" + confirm="Confirmez-vous la validation des exonérations ?" + class="btn-outline-info" + attrs="{'invisible': [('all_exo_validated', '=', True)]}" + /> + <field name="exo_ids" widget="many2many" domain="[('instance_id', '=', False)]" options="{'no_create': 1}"> + <tree decoration-danger="final_notice == 'unfavorable'" decoration-success="final_notice == 'favorable'"> + <field name="date_request"/> + <field name="partner_id"/> + <field name="source"/> + <field name="ur_notice"/> + <field name="date_exo_start"/> + <field name="date_exo_end"/> + <field name="nb_quarter"/> + <field name="amount_quarter" widget="monetary"/> + <field name="final_notice"/> + <field name="state"/> + <button name="set_favorable" type="object" icon="fa-check-circle-o" class="btn-outline-success" + attrs="{'invisible': ['|', ('final_notice', '=', 'favorable'), ('state', 'in', ['done', 'cancel'])]}"/> + <button name="set_unfavorable" type="object" icon="fa-times-circle-o" class="btn-outline-danger" + attrs="{'invisible': ['|', ('final_notice', '=', 'unfavorable'), ('state', 'in', ['done', 'cancel'])]}"/> + </tree> + </field> + </page> + </xpath> + </field> + </record> + + </data> +</odoo> \ No newline at end of file -- GitLab