diff --git a/__manifest__.py b/__manifest__.py index 9063489719fa86ed4b9fa2abbf121156f31302e6..d026b4ce57142c0fd29bc8c581fba604473cf6ab 100755 --- a/__manifest__.py +++ b/__manifest__.py @@ -21,6 +21,7 @@ "views/account_payment_term.xml", "views/account_payment_order.xml", "views/res_config_settings.xml", + "views/res_partner.xml", "views/scop_cotisation_task.xml", ], 'post_init_hook': '_configure_journals', diff --git a/models/scop_contribution.py b/models/scop_contribution.py index f1cae59be5dff3c40a6c62bae7c520d260ebdf1c..1755bc8fcddc73b35f8b9f51e7f680058b06159a 100644 --- a/models/scop_contribution.py +++ b/models/scop_contribution.py @@ -15,6 +15,11 @@ class ScopContributions(models.Model): compute='_compute_amount_paid', store=True) amount_remaining = fields.Float( compute='_compute_amount_remaining_previous', store=True) + is_exempt = fields.Boolean( + string='Exonération', + compute='_compute_is_exempt', + default=False + ) @api.depends('amount_remaining') @api.multi @@ -27,3 +32,36 @@ class ScopContributions(models.Model): def _compute_amount_remaining_previous(self): for r in self: r.amount_remaining = r.invoice_id.residual + + @api.multi + def _compute_is_exempt(self): + for contrib in self: + if contrib.invoice_id: + is_refund = contrib.invoice_id.search([ + ('refund_invoice_id', '=', contrib.invoice_id.id), + ('state', 'in', ['open', 'paid'])]) + if is_refund: + contrib.is_exempt = True + else: + contrib.is_exempt = False + else: + contrib.is_exempt = False + + def view_refund(self): + tree_id = self.env.ref( + 'cgscop_cotisation.invoice_scop_contribution_refund_tree').id + refund_ids = self.invoice_id.search([ + ('refund_invoice_id', '=', self.invoice_id.id), + ('state', 'in', ['open', 'paid']) + ]) + print(refund_ids) + print(tree_id) + return { + 'type': 'ir.actions.act_window', + 'name': 'Exonérations', + 'res_model': 'account.invoice', + 'views': [[tree_id, 'tree']], + 'target': 'new', + 'domain': [['id', 'in', refund_ids.ids]], + 'flags': {'action_buttons': False} + } diff --git a/views/account_invoice.xml b/views/account_invoice.xml index 73a5f56a413297381ae9facd8706b0c142ca2c5d..d1b466ad9bf0350801ac27bac1c123abdb1d7dc9 100644 --- a/views/account_invoice.xml +++ b/views/account_invoice.xml @@ -70,6 +70,20 @@ </field> </record> + <record id="invoice_scop_contribution_refund_tree" model="ir.ui.view"> + <field name="name">account.invoice.tree.scop.contribution</field> + <field name="model">account.invoice</field> + <field name="arch" type="xml"> + <tree create="0" edit="0" delete="0"> + <field name="name"/> + <field name="date_invoice" string="Date d'émission"/> + <field name="number"/> + <field name="amount_total_signed" widget="monetary"/> + <field name="state" invisible="1"/> + </tree> + </field> + </record> + <!-- Search --> <record id="invoice_search_scop_inherited" model="ir.ui.view"> <field name="name">account.invoice.search.scop.inherited</field> diff --git a/views/res_partner.xml b/views/res_partner.xml new file mode 100644 index 0000000000000000000000000000000000000000..3a9946327458e17d45390276491290a35f8cc686 --- /dev/null +++ b/views/res_partner.xml @@ -0,0 +1,19 @@ +<?xml version="1.0" encoding="utf-8"?> +<odoo> + <!-- Copyright 2020 Le Filament + License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). --> + <data> + + <record id="scop_contact_view_form" model="ir.ui.view"> + <field name="name">res.partner.scop.view.form</field> + <field name="model">res.partner</field> + <field name="inherit_id" ref="cgscop_partner.scop_contact_view_form"/> + <field name="arch" type="xml"> + <xpath expr="//field[@name='contribution_ids']/tree/field[@name='spreading']" position="before"> + <field name="is_exempt" style="text-align: center;"/> + <button name="view_refund" type="object" icon="fa-eye" attrs="{'invisible': [('is_exempt', '=', False)]}" style="pointer-events: visible;"/> + </xpath> + </field> + </record> + </data> +</odoo> \ No newline at end of file