Skip to content

Commit

Permalink
Merge pull request #55 from rubencabrera/flujo-email-2023
Browse files Browse the repository at this point in the history
feat: flujo de emails nueva temporada
  • Loading branch information
rubencabrera authored Apr 15, 2023
2 parents 96962d5 + bee61b4 commit 3a289bf
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 21 deletions.
1 change: 0 additions & 1 deletion partner_portal_extra_details/controllers/portal.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,4 +134,3 @@ def receipt(self, redirect=None, **post):
self._set_partner_data()
return request.redirect('/my')
return response

55 changes: 38 additions & 17 deletions partner_portal_extra_details/models/res_partner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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):
Expand Down
19 changes: 16 additions & 3 deletions partner_portal_extra_details/views/res_partner.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
<xpath expr="//field[@name='display_name']" position="after">
<field name='birthdate_date'/>
<field name='vat'/>
<field name="current_year_confirmed" />
<field name="uniform_number" />
<field name='attach_receipt' />
</xpath>
Expand All @@ -45,12 +46,24 @@
<field name="inherit_id" ref="base.view_res_partner_filter"/>
<field name="arch" type="xml">
<xpath expr="//filter[@name='salesperson']" position="before">
<filter name="category" string="Category" context="{'group_by': 'player_category'}"/>
<filter name="category" string="Category"
context="{'group_by': 'player_category'}"
domain="[('is_player','=',True)]"
/>
</xpath>
<xpath expr="//separator[1]" position="after">
<filter name="unpaid" string="Validado sin pagar"
<filter name="is_player" string="Jugadores"
domain="[('is_player','=',True)]"
/>
<filter name="pending_review" string="Usuarios pendientes de validar"
domain="[('current_year_confirmed','=',True),('validate_portal_user','=',True)]"
/>
<filter name="current_year" string="Jugadores con alta este año confirmada"
domain="[('is_player','=',True), ('current_year_confirmed','=',True)]"
/>
<filter name="unpaid" string="Falta subir recibo"
domain="[('validate_portal_user','=',True), ('attach_receipt','=',False)]"/>
<filter name="pending" string="Recibo por validar"
<filter name="pending" string="Recibo subido pendiente de validar"
domain="[('valid_receipt','=',False), ('attach_receipt','=',True)]"/>
<separator />
</xpath>
Expand Down

0 comments on commit 3a289bf

Please sign in to comment.