Skip to content

Commit

Permalink
Merge pull request #48 from rubencabrera/temporada-2023
Browse files Browse the repository at this point in the history
feat: campo is_player y confirmación temporada
  • Loading branch information
rubencabrera authored Apr 11, 2023
2 parents 2ce2f5c + 2307fa5 commit 0e185f7
Show file tree
Hide file tree
Showing 11 changed files with 207 additions and 4,614 deletions.
4,549 changes: 0 additions & 4,549 deletions package-lock.json

This file was deleted.

6 changes: 5 additions & 1 deletion partner_portal_extra_details/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Contact portal extra details
============================

This module extends the user portal details with fields required by a sports
team.
team and adds some functionality for management.

**Table of contents**

Expand All @@ -24,6 +24,10 @@ If you spotted it first, help us smashing it by providing a detailed and welcome

Do not contact contributors directly about support or help with technical issues.

Roadmap
=======

- Make the season start date a variable.
Credits
=======

Expand Down
3 changes: 2 additions & 1 deletion partner_portal_extra_details/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{
"name": "Rayito Contact Details",
"summary": "Extended contact details in user portal",
'version': '12.0.1.1.0',
'version': '12.0.1.2.0',
"category": "Customer Relationship Management",
"website": "https://github.com/rubencabrera/odoo-addons",
"author": "Rubén Cabrera Martínez",
Expand All @@ -28,6 +28,7 @@
"data/product_template_data.xml",
"data/mail_template_data.xml",
"data/ir_cron_data.xml",
"data/season_start_cron.xml",
#views
"views/portal_templates.xml",
"views/res_partner.xml",
Expand Down
92 changes: 42 additions & 50 deletions partner_portal_extra_details/controllers/portal.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# -*- coding: utf-8 -*-

# Copyright 2020 Rubén Cabrera Martínez <[email protected]>
# Copyright 2020 CBMP Rayito Salinero
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

import base64
from odoo.addons.portal.controllers.portal import CustomerPortal
from odoo.http import request, route
Expand All @@ -22,37 +26,47 @@ class RayitoCustomerPortal(CustomerPortal):
]
OPTIONAL_BILLING_FIELDS = [
"company_name",
"current_year_confirmed",
"state_id",
"shirt_size",
"top_size",
"zipcode",
]

def _attach_payment_receipt(self, post):
Attachment = request.env['ir.attachment']
partner = request.env.user.partner_id
name = post.get('attachment').filename
file = post.get('attachment')
data = file.read()
attachment = Attachment.sudo().create({
'name': name,
'datas_fname': name,
'res_name': name,
'type': 'binary',
'res_model': 'res.partner',
'res_id': partner.id,
'datas': base64.b64encode(data)
})
return attachment

def _get_mandatory_billing_fields(self):
MANDATORY_BILLING_FIELDS = [
"birthdate_date",
"city",
"country_id",
"email",
"gender",
"name",
"phone",
"street",
"tutor_phone",
"tutor_name",
"vat",
]
return MANDATORY_BILLING_FIELDS
return self.MANDATORY_BILLING_FIELDS

def _get_optional_billing_fields(self):
OPTIONAL_BILLING_FIELDS = [
"company_name",
"shirt_size",
"top_size",
"state_id",
"zipcode",
]
return OPTIONAL_BILLING_FIELDS
return self.OPTIONAL_BILLING_FIELDS

def _render_receipt_payment(self, values):
response = request.render(
"partner_portal_extra_details.portal_my_details_receipt_payment",
values
)
response.headers['X-Frame-Options'] = 'DENY'
return response

def _set_partner_data(self):
partner = request.env.user.partner_id
partner.write({'attach_receipt': True})

@route(['/my/account'], type='http', auth='user', website=True)
def account(self, redirect=None, **post):
Expand All @@ -78,6 +92,12 @@ def account(self, redirect=None, **post):
if key in post
}
)
if "current_year_confirmed" not in values.keys():
values.update(
{
"current_year_confirmed": False,
}
)
values.update({'zip': values.pop('zipcode', '')})
partner.sudo().write(values)
if redirect:
Expand Down Expand Up @@ -115,31 +135,3 @@ def receipt(self, redirect=None, **post):
return request.redirect('/my')
return response

def _attach_payment_receipt(self, post):
Attachment = request.env['ir.attachment']
partner = request.env.user.partner_id
name = post.get('attachment').filename
file = post.get('attachment')
data = file.read()
attachment = Attachment.sudo().create({
'name': name,
'datas_fname': name,
'res_name': name,
'type': 'binary',
'res_model': 'res.partner',
'res_id': partner.id,
'datas': base64.b64encode(data)
})
return attachment

def _render_receipt_payment(self, values):
response = request.render(
"partner_portal_extra_details.portal_my_details_receipt_payment",
values
)
response.headers['X-Frame-Options'] = 'DENY'
return response

def _set_partner_data(self):
partner = request.env.user.partner_id
partner.write({'attach_receipt': True})
33 changes: 31 additions & 2 deletions partner_portal_extra_details/data/mail_template_data.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data noupdate="1">
<!-- <data noupdate="1"> -->
<data>
<!--Email template -->
<record id="email_template_send_user_payment_term" model="mail.template">
<field name="name">Validate user: Send info to the new user</field>
Expand Down Expand Up @@ -44,6 +45,34 @@
<field name="auto_delete" eval="True"/>
</record>

<record id="email_template_season_start" model="mail.template">
<field name="name">Correo de inicio de temporada</field>
<field name="model_id" ref="base.model_res_partner"/>
<field name="email_from">${object.user_id.email_formatted |safe}</field>
<field name="partner_to">${object.id}</field>
<field name="subject">Pronto empieza la temporada ${datetime.date.today().year}</field>
<field name="body_html" type="html">
<div style="margin: 0px; padding: 0px;">
<p style="margin: 0px; padding: 0px; font-size: 13px;">
Hola ${object.name}:
<br />
Ya llega el buen tiempo y con él empieza la preparación para una nueva temporada de balonmano playa.<br />
<br /><br />
En el Rayito Salinero te estamos esperando un año más para vivir la mejor experiencia del verano.
Recuerda iniciar sesión en nuestra web, ir a Mi Cuenta y Editar tu Información personal, para marcar la casilla
Confirmo mi participación en la temporada de este año.
Una vez guardes estos cambios contaremos contigo.
<br /><br />
¡Nos vemos en la arena!
</p>
</div>
</field>
<field name="report_name">Inicio de temporada ${datetime.date.today().year}</field>
<field name="lang">${object.lang}</field>
<field name="user_signature" eval="True"/>
<field name="auto_delete" eval="True"/>
</record>

<record id="email_template_send_user_valid_receipt" model="mail.template">
<field name="name">Validate receipt</field>
<field name="model_id" ref="partner_portal_extra_details.model_res_partner"/>
Expand Down Expand Up @@ -124,4 +153,4 @@
</record>

</data>
</odoo>
</odoo>
20 changes: 20 additions & 0 deletions partner_portal_extra_details/data/season_start_cron.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data>
<!-- En fase de desarrollo aún, dejamos que se actualice -->
<!-- <data noupdate="1"> -->
<record id="ir_cron_season_start" model="ir.cron">
<field name="name">Enviar correo de inicio de temporada</field>
<field name="model_id" ref="base.model_res_partner"/>
<field name="state">code</field>
<field name="code">model.season_start()</field>
<field name="user_id" ref="base.user_root"/>
<field name="interval_number">12</field>
<field name="interval_type">months</field>
<field name="numbercall">-1</field>
<field eval="True" name="doall"/>
<field name="priority">10</field>
<field name="nextcall">2024-03-20 19:30:22</field>
</record>
</data>
</odoo>
24 changes: 20 additions & 4 deletions partner_portal_extra_details/models/res_company.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,29 @@
class ResCompany(models.Model):
_inherit = 'res.company'

product_id = fields.Many2one(
comodel_name="product.product",
string="Service to invoice"
initial_template = fields.Many2one(
comodel_name="mail.template",
string="Plantilla de inicio de temporada",
)

payment_reminder_days = fields.Integer(
string='Payment reminder days',
help='Set the number of days to remind the user to make the payment. '
'Set zero to don\'t send reminder.',
default=3,
)
)

product_id = fields.Many2one(
comodel_name="product.product",
string="Servicio a facturar",
helps="El producto de tipo servicio que se usará para generar las facturas de cuota."
)

season_start = fields.Date(
string="Fecha de inicio próxima temporada",
help="""Fecha en la que se reiniciarán las casillas de participación en
la presente temporada y se enviarán los emails de notificación a los
jugadores. Esta fecha debe cambiarse cada año para que el proceso se
repita.
"""
)
79 changes: 73 additions & 6 deletions partner_portal_extra_details/models/res_partner.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,21 @@ class ResPartner(models.Model):
help="Allows to know if the user has attached the receipt of payment."
)

current_year_confirmed = fields.Boolean(
string="Confirmación de alta en la temporada."
)

is_player = fields.Boolean(
string="Es Jugador/a",
help="Marca esta casilla si este contacto es de un(a) jugador(a)"
)

player_category = fields.Char(
string='Player category',
compute='_compute_player_category',
store=True,
)

shirt_size = fields.Selection(
string="Talla de camiseta",
selection=[
Expand Down Expand Up @@ -68,11 +83,13 @@ class ResPartner(models.Model):
string="Validate receipt",
help="Allows to validate the attachment receipt."
)
player_category = fields.Char(
string='Player category',
compute='_compute_player_category',
store=True,
)

@api.model
def restore_current_year_confirmation(self):
"""
Restaurar la confirmación de participación del presente año.
"""
pass

@api.multi
def write(self, values):
Expand All @@ -86,7 +103,10 @@ def write(self, values):
@api.multi
def _send_mail_to_new_validate_user(self):
"""
This function sends an email to the new validated user of the portal.
Envía un correo a un usuario que acaba de ser validado para usar
el portal. Este correo de bienvenida sólo estaba pensado para
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']
Expand All @@ -101,6 +121,48 @@ def _send_mail_to_new_validate_user(self):
invoices |= self._create_partner_invoice()
invoices._send_payment_terms_mail()

@api.model
def _filter_players(self):
"""
Function to select which partners to send the season start
email to.
"""
return self.search(
[
('is_player', '=', True),
]
)

@api.model
def season_start(self):
"""
Filter and send season start emails.
Designed to run from a Cronjob.
"""
players = self._filter_players()
if players:
for player in players:
_logger.debug("Enviando correo a %s", player.name)
player._send_season_start_email()

@api.multi
def _send_season_start_email(self):
"""
Function to send the season start email using the
company template.
Called from records, expects singleton (template does so we
carry that).
"""
self.ensure_one()
# TODO: there's no default set, some error handling should be added
template = self.company_id.initial_template
template.send_mail(
self.id,
force_send=True # sends it NOW
)

def _create_partner_invoice(self):
self.ensure_one()
partner = self
Expand Down Expand Up @@ -158,6 +220,11 @@ def _grant_portal_access(self):
return portal_wizard.action_apply()

def _send_validate_mail(self):
"""
Envía un correo de validación. Es el correo de bienvenida de cada temporada.
Inicialmente se invoca desde la función write() cuando se ha validado el recibo.
"""
self.ensure_one()
partner = self
module_name = 'partner_portal_extra_details'
Expand Down
Loading

0 comments on commit 0e185f7

Please sign in to comment.