diff --git a/__manifest__.py b/__manifest__.py index fa07e414d5472c68a9efe7468d4b319eb7812862..3fdf794c3dc55993d93cf39f8b73ab57853cc6ee 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 9bd897d04175f9936ce1c3f657bc4081d2e9fb4f..7b239a92d78a6874f6190be875b64fe5310ddc6c 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 347999316b38eb5ac8664e0f8938f04018a29ea5..04d8ad5a2ad39a5981bb755a41c5b7f3ca421cb3 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 0000000000000000000000000000000000000000..16ef1f34f702586282f13074bc2ced8ed2495f72 --- /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 93583fa1abb74aa3629909a51efd5d3c60bb36a2..d732a7e5cd4ff59b2bb9f9258198238a18d5e279 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 0000000000000000000000000000000000000000..b109827d4870b4a6f05dd3a1acc00ebc033e804d --- /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