diff --git a/models/res_company.py b/models/res_company.py index e76b03a3d6a0be359567b2dccccb0c48944504ab..74b1685001f190931e6062e06de7228d53a9a6a2 100644 --- a/models/res_company.py +++ b/models/res_company.py @@ -13,3 +13,8 @@ class ScopCotisationCompany(models.Model): string='Journal des cotisations', domain="[('type', '=', 'sale')]" ) + tag_id = fields.Many2one( + comodel_name='res.partner.category', + string='Etiquette de cotisation', + ondelete='restrict' + ) diff --git a/models/res_config_settings.py b/models/res_config_settings.py index 8214d9c80651f6ce32b66c8e3bbcbaa57943e6fe..ad517e943b111da2be81c5660acb08a1c828811a 100644 --- a/models/res_config_settings.py +++ b/models/res_config_settings.py @@ -18,6 +18,15 @@ class CotisationsConfigSettings(models.TransientModel): string='Journal des cotisations', domain="[('type', '=', 'sale')]") + tag_id = fields.Many2one( + comodel_name='res.partner.category', + related="company_id.tag_id", + readonly=False, + string='Etiquette de cotisation') + + # ------------------------------------------------------ + # Actions + # ------------------------------------------------------ def add_company_to_menu(self, menu, bool_condition): """ Add current company to the list of companies allowed to see menu @@ -37,6 +46,9 @@ class CotisationsConfigSettings(models.TransientModel): "company_ids": [(3, current_company_id.id)] }) + # ------------------------------------------------------ + # Override Parent + # ------------------------------------------------------ def execute(self): """ Rewrite execute() function to add current company to the list diff --git a/models/scop_cotisation.py b/models/scop_cotisation.py index c601900dbcbfc4318f8e0892124e123ec5efd19c..32a95d6ede87403827617a142073548d6273e422 100644 --- a/models/scop_cotisation.py +++ b/models/scop_cotisation.py @@ -41,6 +41,17 @@ class ScopCotisation(models.AbstractModel): "Cotisations créées", compute='_compute_invoiced_member_count') + # Emails management + recipient_ids = fields.One2many( + comodel_name='res.partner', + compute='_compute_recipient' + ) + # TODO : Use when email active + # email_count = fields.Integer( + # string='Nombre de mails', + # compute='_compute_emails' + # ) + # ------------------------------------------------------ # Compute fields # ------------------------------------------------------ @@ -60,6 +71,18 @@ class ScopCotisation(models.AbstractModel): cotiz.invoiced_member_count = len( cotiz.invoice_ids.mapped('partner_id')) + @api.multi + def _compute_recipient(self): + tag_id = self.env.user.company_id.tag_id + for cotiz in self: + child_ids = cotiz.partner_id.child_ids.filtered( + lambda child: (tag_id in child.category_id) and child.email + ) + if cotiz.partner_id.email: + cotiz.recipient_ids = cotiz.partner_id + child_ids + else: + cotiz.recipient_ids = child_ids + # ------------------------------------------------------ # Global functions # ------------------------------------------------------ @@ -118,3 +141,8 @@ class ScopCotisation(models.AbstractModel): ('end', '>', date(self.year, 1, 1)) ]).mapped('partner_id') return members + + # TODO : Use when email active + # Email + # def get_recipients(self): + # return ','.join(map(lambda x: str(x), self.recipient_ids.ids)) diff --git a/views/res_config_settings.xml b/views/res_config_settings.xml index ec13cc9290d2f288fd94dcf2b565013f9e7411e7..c6c1c7b83f45efc775f7572fe5bf5c4f88090f69 100644 --- a/views/res_config_settings.xml +++ b/views/res_config_settings.xml @@ -15,20 +15,28 @@ <div class="o_setting_left_pane"> <field name="is_contribution" /> </div> - <div class="o_setting_right_pane"> + <div class="o_setting_right_pane"> <label for="is_contribution"/> <div class="text-muted"> Activer la gestion des cotisations pour cette société </div> - </div> - <div class="o_setting_left_pane"/> - <div class="o_setting_right_pane"> + </div> + <div class="o_setting_left_pane"/> + <div class="o_setting_right_pane"> <label for="contribution_journal_id"/> <div class="text-muted"> Définit le journal des cotisations </div> <field name="contribution_journal_id" options="{'no_open': True, 'no_create': True}"/> - </div> + </div> + <div class="o_setting_left_pane"/> + <div class="o_setting_right_pane"> + <label for="tag_id"/> + <div class="text-muted"> + Etiquette associée aux contacts cotisations + </div> + <field name="tag_id" options="{'no_open': True, 'no_create': True}"/> + </div> </div> </div> </xpath>