diff --git a/__manifest__.py b/__manifest__.py index 656c27c0fbf710e9e4bf5fb6c8c89e158b60591a..346c4ea1c5467b6033aec933d4b4bd2790972c3b 100755 --- a/__manifest__.py +++ b/__manifest__.py @@ -13,27 +13,34 @@ "cgscop_cotisation", ], "data": [ + # Security "security/security_rules.xml", "security/ir.model.access.csv", + # Datas "datas/cron.xml", "datas/mail_data.xml", "datas/mail_reminder_data.xml", "datas/ir_sequence_data.xml", - "wizard/scop_cotisation_cg_regul_wizard.xml", + # Reports "report/report_scop_bordereau.xml", "report/report_scop_bordereau_payments.xml", "report/report_scop_bordereau_refund.xml", + # Views "views/account_invoice.xml", "views/res_config_settings.xml", - "views/scop_bordereau_cg.xml", "views/scop_cotisation_cg.xml", "views/scop_cotisation_simulation.xml", "views/scop_liasse_fiscale.xml", + # Wizards "wizard/export_journal_wizard_view.xml", - "wizard/scop_bordereau_change_liasse_wizard.xml", - "wizard/scop_bordereau_change_payment_mode_wizard.xml", + "wizard/scop_cotisation_cg_regul_wizard.xml", + "wizard/scop_bordereau_update_liasse_wizard.xml", + "wizard/scop_bordereau_payment_mode_wizard.xml", + "wizard/scop_bordereau_refund_wizard.xml", "wizard/scop_cotisation_cg_wizard.xml", "wizard/scop_bordereau_update_confirm_view.xml", "wizard/scop_bordereau_validate_confirm_view.xml", + # Wizard dependency view + "views/scop_bordereau_cg.xml", ] } diff --git a/views/scop_bordereau_cg.xml b/views/scop_bordereau_cg.xml index 9c0c67dfa20c342c4de10100b7927a91e5397a94..1d312bf55e1db76fe954767f71defcfb17d6f950 100644 --- a/views/scop_bordereau_cg.xml +++ b/views/scop_bordereau_cg.xml @@ -24,6 +24,11 @@ string="Effectuer une Régularisation" type="action" states="validated,paid"/> + <button name="%(cgscop_cotisation_cg.scop_bordereau_refund_wizard_act_window)d" + class="btn-warning" + string="Ajouter un avoir" + type="action" + states="validated,paid"/> <button name="%(cgscop_bordereau_report_refund)d" class="btn-info" string="Imprimer l'avoir" diff --git a/wizard/__init__.py b/wizard/__init__.py index 1ae8c0204e25bc0d3c1ed027014de637ccc71c27..a23c4c181537020603c1172196a3bd075001c6b0 100644 --- a/wizard/__init__.py +++ b/wizard/__init__.py @@ -3,8 +3,9 @@ from . import account_invoice_refund from . import export_journal_wizard -from . import scop_bordereau_change_liasse_wizard -from . import scop_bordereau_change_payment_mode_wizard +from . import scop_bordereau_update_liasse_wizard +from . import scop_bordereau_payment_mode_wizard +from . import scop_bordereau_refund_wizard from . import scop_bordereau_update_confirm from . import scop_bordereau_validate_confirm from . import scop_cotisation_cg_regul diff --git a/wizard/scop_bordereau_change_payment_mode_wizard.py b/wizard/scop_bordereau_payment_mode_wizard.py similarity index 100% rename from wizard/scop_bordereau_change_payment_mode_wizard.py rename to wizard/scop_bordereau_payment_mode_wizard.py diff --git a/wizard/scop_bordereau_change_payment_mode_wizard.xml b/wizard/scop_bordereau_payment_mode_wizard.xml similarity index 100% rename from wizard/scop_bordereau_change_payment_mode_wizard.xml rename to wizard/scop_bordereau_payment_mode_wizard.xml diff --git a/wizard/scop_bordereau_refund_wizard.py b/wizard/scop_bordereau_refund_wizard.py new file mode 100644 index 0000000000000000000000000000000000000000..95b538101f7c00f764f5b7bfa964ba62b37ac784 --- /dev/null +++ b/wizard/scop_bordereau_refund_wizard.py @@ -0,0 +1,128 @@ +# Copyright 2021 Le Filament +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import fields, models, api + + +class ScopBordereauRefundWizard(models.TransientModel): + _name = 'scop.bordereau.refund.wizard' + _description = 'Avoir sur les bordereaux' + + bordereau_id = fields.Many2one( + comodel_name='scop.bordereau', + string='Bordereau', + readonly=True, + ) + date_refund = fields.Date( + string="Date de régularisation", + default=fields.Date.today()) + amount_refund = fields.Float('Montant') + comment = fields.Char('Motif de l\'avoir') + type_cotiz = fields.Selection( + string='Type de cotisation', + selection=lambda self: self._selection_type_cotiz()) + + # ------------------------------------------------------ + # Override ORM + # ------------------------------------------------------ + @api.model + def default_get(self, fields): + res = super(ScopBordereauRefundWizard, self).default_get(fields) + bordereau_id = self.env['scop.bordereau'].browse( + self.env.context.get('active_id') + ) + res.update({ + 'bordereau_id': bordereau_id.id, + }) + return res + + @api.model + def _selection_type_cotiz(self): + bordereau_id = self.env['scop.bordereau'].browse( + self.env.context.get('active_id') + ) + + contribs = bordereau_id.invoice_ids.read_group( + [('id', 'in', bordereau_id.invoice_ids.ids)], + ['type_contribution_id', 'amount_total_signed'], + ['type_contribution_id']) + + ur_hdf = self.env.ref('cgscop_partner.riga_14232').id + if bordereau_id.partner_id.ur_id.id == ur_hdf: + product_ur = self.env.user.company_id.contribution_hdf_id + else: # ur = ur_med + product_ur = self.env.user.company_id.contribution_med_id + + cotiz_type = { + self.env.ref('cgscop_partner.riga_14397').id: + self.env.user.company_id.contribution_cg_id, + self.env.ref('cgscop_partner.riga_14398').id: + self.env.user.company_id.contribution_fede_com_id, + self.env.ref('cgscop_partner.cotiz_fede_cae').id: + self.env.user.company_id.contribution_fede_cae_id, + self.env.ref('cgscop_partner.riga_14399').id: + product_ur, + } + + type_cotiz_select_i = list() + type_cotiz_select_list = list() + for contrib in contribs: + type_cotiz = contrib.get('type_contribution_id')[0] + if type_cotiz not in type_cotiz_select_i: + type_cotiz_select_i.append(type_cotiz) + type_cotiz_select_list.append( + (type_cotiz, cotiz_type[type_cotiz].name)) + return type_cotiz_select_list + + # ------------------------------------------------------ + # Action + # ------------------------------------------------------ + def create_refund(self): + """ + Create refund + """ + bordereau_id = self.bordereau_id + ur_hdf = self.env.ref('cgscop_partner.riga_14232').id + + if bordereau_id.partner_id.ur_id.id == ur_hdf: + product_ur = self.env.user.company_id.contribution_hdf_id + else: # ur = ur_med + product_ur = self.env.user.company_id.contribution_med_id + + cotiz_type = { + self.env.ref('cgscop_partner.riga_14397').id: + self.env.user.company_id.contribution_cg_id, + self.env.ref('cgscop_partner.riga_14398').id: + self.env.user.company_id.contribution_fede_com_id, + self.env.ref('cgscop_partner.cotiz_fede_cae').id: + self.env.user.company_id.contribution_fede_cae_id, + self.env.ref('cgscop_partner.riga_14399').id: + product_ur, + } + product = cotiz_type.get(int(self.type_cotiz)) + refund = self.env['account.invoice'].create({ + 'partner_id': bordereau_id.partner_id.id, + 'journal_id': self.env.user.company_id.contribution_journal_id.id, + 'account_id': bordereau_id.partner_id.property_account_receivable_id.id, + 'type': 'out_refund', + 'date_invoice': self.date_refund, + 'date': self.date_refund, + 'state': 'draft', + 'number': False, + 'origin': bordereau_id.name, + 'reference': False, + 'bordereau_id': bordereau_id.id, + 'is_contribution': True, + 'year': bordereau_id.year, + 'liasse_fiscale_id': bordereau_id.liasse_fiscale_id.id, + 'type_contribution_id': self.type_cotiz, + 'payment_mode_id': bordereau_id.payment_mode_id.id, + 'date_due': self.date_refund, + }) + self.env['account.invoice.line'].create({ + 'name': self.comment, + 'invoice_id': refund.id, + 'product_id': product.id, + 'account_id': product.property_account_income_id.id, + 'price_unit': self.amount_refund + }) diff --git a/wizard/scop_bordereau_refund_wizard.xml b/wizard/scop_bordereau_refund_wizard.xml new file mode 100644 index 0000000000000000000000000000000000000000..dc9382aee36184045cf21d7648f3688ec46cec3b --- /dev/null +++ b/wizard/scop_bordereau_refund_wizard.xml @@ -0,0 +1,40 @@ +<?xml version="1.0" encoding="utf-8"?> +<odoo> + <!-- Copyright 2021 Le Filament + License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). --> + <data> + + <record id="scop_bordereau_refund_wizard_form_view" model="ir.ui.view"> + <field name="name">scop.bordereau.refund.wizard.form</field> + <field name="model">scop.bordereau.refund.wizard</field> + <field name="arch" type="xml"> + <form string="Générer un avoir"> + <sheet> + <group string="Nouveaux calculs"> + <field name="date_refund" required="1"/> + <separator/> + <field name="amount_refund"/> + <field name="comment"/> + <separator/> + <field name="type_cotiz"/> + </group> + </sheet> + <footer> + <button name="create_refund" type="object" string="Créer l'avoir" class="oe_highlight" confirm="Confirmer la création de l'avoir"/> + <button string="Annuler" special="cancel" class="oe_link"/> + </footer> + </form> + </field> + </record> + + <record id="scop_bordereau_refund_wizard_act_window" model="ir.actions.act_window"> + <field name="name">Avoir sur le bordereau</field> + <field name="type">ir.actions.act_window</field> + <field name="res_model">scop.bordereau.refund.wizard</field> + <field name="view_type">form</field> + <field name="view_mode">form</field> + <field name="target">new</field> + </record> + + </data> +</odoo> \ No newline at end of file diff --git a/wizard/scop_bordereau_change_liasse_wizard.py b/wizard/scop_bordereau_update_liasse_wizard.py similarity index 100% rename from wizard/scop_bordereau_change_liasse_wizard.py rename to wizard/scop_bordereau_update_liasse_wizard.py diff --git a/wizard/scop_bordereau_change_liasse_wizard.xml b/wizard/scop_bordereau_update_liasse_wizard.xml similarity index 100% rename from wizard/scop_bordereau_change_liasse_wizard.xml rename to wizard/scop_bordereau_update_liasse_wizard.xml