From bee61b4e5636a1dd6a8ee5093e144418a77e76e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Cabrera?= Date: Sat, 15 Apr 2023 21:19:18 +0100 Subject: [PATCH] feat: flujo de emails nueva temporada --- .../controllers/portal.py | 1 - .../models/res_partner.py | 55 +++++++++++++------ .../views/res_partner.xml | 19 ++++++- 3 files changed, 54 insertions(+), 21 deletions(-) diff --git a/partner_portal_extra_details/controllers/portal.py b/partner_portal_extra_details/controllers/portal.py index af64fd6..569d0a3 100644 --- a/partner_portal_extra_details/controllers/portal.py +++ b/partner_portal_extra_details/controllers/portal.py @@ -134,4 +134,3 @@ def receipt(self, redirect=None, **post): self._set_partner_data() return request.redirect('/my') return response - diff --git a/partner_portal_extra_details/models/res_partner.py b/partner_portal_extra_details/models/res_partner.py index 42712be..481ac42 100644 --- a/partner_portal_extra_details/models/res_partner.py +++ b/partner_portal_extra_details/models/res_partner.py @@ -93,11 +93,31 @@ def restore_current_year_confirmation(self): @api.multi def write(self, values): - if values.get('validate_portal_user'): - self._send_mail_to_new_validate_user() - self._grant_portal_access() - if values.get('valid_receipt'): - self._send_validate_mail() + for partner in self: + if values.get("current_year_confirmed"): + if partner.validate_portal_user: + partner._send_mail_to_new_validate_user() + elif values.get("validate_portal_user"): + # Caso algo hipotético de que la confirmación + # y la validación se hagan en el mismo momento. + partner.is_player = True + partner._send_mail_to_new_validate_user() + partner._grant_portal_access() + + elif values.get('validate_portal_user'): + # Usuario nuevo, al que hemos validado manualmente desde + # administración y al que vamos a mandar el email. + partner.is_player = True + partner._grant_portal_access() + + if partner.current_year_confirmed: + # Si el jugador ya había confirmado este año antes + # de la presente validación. + partner._send_mail_to_new_validate_user() + + if values.get('valid_receipt'): + partner._send_validate_mail() + return super(ResPartner, self).write(values) @api.multi @@ -108,18 +128,19 @@ def _send_mail_to_new_validate_user(self): enviarse una vez, no cada año, pero lo usamos en 2022 como correo de inicio de temporada. """ - self.ensure_one() - account_invoice = invoices = self.env['account.invoice'] - dom = [ - ('partner_id', '=', self.id), - ('state', '=', 'draft') - ] - invoices |= account_invoice.search( - dom, order='date_invoice asc', limit=1 - ) - if not invoices: - invoices |= self._create_partner_invoice() - invoices._send_payment_terms_mail() + # self.ensure_one() + for partner in self: + account_invoice = invoices = self.env['account.invoice'] + dom = [ + ('partner_id', '=', partner.id), + ('state', '=', 'draft') + ] + invoices |= account_invoice.search( + dom, order='date_invoice asc', limit=1 + ) + if not invoices: + invoices |= partner._create_partner_invoice() + invoices._send_payment_terms_mail() @api.model def _filter_players(self): diff --git a/partner_portal_extra_details/views/res_partner.xml b/partner_portal_extra_details/views/res_partner.xml index 8450af7..7e1f23f 100644 --- a/partner_portal_extra_details/views/res_partner.xml +++ b/partner_portal_extra_details/views/res_partner.xml @@ -33,6 +33,7 @@ + @@ -45,12 +46,24 @@ - + - + + + -