From 396f9903b444a7d9e06fff7cb88a935c883ba4b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Su=C3=A1rez?= Date: Tue, 23 Jun 2020 17:39:51 +0200 Subject: [PATCH 1/4] added wizard for baixa soci --- som_generationkwh/__terp__.py | 1 + som_generationkwh/somenergia_soci.py | 4 +- som_generationkwh/wizard/__init__.py | 1 + som_generationkwh/wizard/wizard_baixa_soci.py | 94 +++++++++++++++++++ 4 files changed, 99 insertions(+), 1 deletion(-) create mode 100644 som_generationkwh/wizard/wizard_baixa_soci.py diff --git a/som_generationkwh/__terp__.py b/som_generationkwh/__terp__.py index a2235dc5..eaf1d522 100644 --- a/som_generationkwh/__terp__.py +++ b/som_generationkwh/__terp__.py @@ -37,6 +37,7 @@ "wizard/wizard_investment_transfer.xml", "wizard/wizard_aeat193_from_gkwh_invoices_view.xml", "wizard/wizard_send_retencio_estalvi_to_members.xml", + "wizard/wizard_baixa_soci.xml", "investment_view.xml", "assignment_view.xml", "somenergia_soci_view.xml", diff --git a/som_generationkwh/somenergia_soci.py b/som_generationkwh/somenergia_soci.py index 6fffa752..5bfa4523 100644 --- a/som_generationkwh/somenergia_soci.py +++ b/som_generationkwh/somenergia_soci.py @@ -158,7 +158,7 @@ def verifica_baixa_soci(self, cursor, uid, ids, context=None): if baixa: raise osv.except_osv(_('El soci no pot ser donat de baixa!'), - _('Ja ha estat donat de baixa baixa anteriorment!')) + _('Ja ha estat donat de baixa anteriorment!')) gen_invest = invest_obj.search(cursor, uid, [('member_id', '=', member_id), ('emission_id', '=', 1), @@ -204,6 +204,8 @@ def delete_rel(cursor, uid, categ_id, res_partner_id): 'comment': comment }) delete_rel(cursor, uid, soci_category_id, res_partner_id) + return True + _columns = { 'has_gkwh': fields.function( diff --git a/som_generationkwh/wizard/__init__.py b/som_generationkwh/wizard/__init__.py index d12a0cbd..73a1bb05 100644 --- a/som_generationkwh/wizard/__init__.py +++ b/som_generationkwh/wizard/__init__.py @@ -8,3 +8,4 @@ import wizard_investment_transfer import wizard_aeat193_from_gkwh_invoices import wizard_send_retencio_estalvi_to_members +import wizard_baixa_soci diff --git a/som_generationkwh/wizard/wizard_baixa_soci.py b/som_generationkwh/wizard/wizard_baixa_soci.py new file mode 100644 index 00000000..cf766f8e --- /dev/null +++ b/som_generationkwh/wizard/wizard_baixa_soci.py @@ -0,0 +1,94 @@ +# -*- coding: utf-8 -*- + +from osv import osv, fields +from tools.translate import _ +import logging + +class WizardBaixaSoci(osv.osv): + + _name = 'wizard.baixa.soci' + _columns = { + 'state': fields.char('State', size=16), + 'info': fields.text('Info') + } + _defaults = { + 'state': 'init' + } + + def baixa_soci(self, cursor, uid, ids, context=None, send_mail=False): + soci_obj = self.pool.get('somenergia.soci') + soci_id = context['active_ids'] + + if not isinstance(soci_id, list): + soci_id = [soci_id] + if len(soci_id) != 1: + raise "Has de seleccionar un sol soci" + + try: + soci_obj.verifica_baixa_soci(cursor, uid, soci_id[0], context) + except osv.except_osv as e: + self.write(cursor, uid, ids, {'state':'error', + 'info': e.message}) + else: + if send_mail: + self.send_mail(cursor, uid, soci_id[0]) + self.write(cursor, uid, ids, {'state':'ok'}) + + + def baixa_soci_and_send_mail(self, cursor, uid, ids, context=None): + self.baixa_soci(cursor, uid, ids, context, send_mail=True) + + def send_mail(self, cursor, uid, soci_id, context=None): + ir_model_data = self.pool.get('ir.model.data') + account_obj = self.pool.get('poweremail.core_accounts') + power_email_tmpl_obj = self.pool.get('poweremail.templates') + + template_id = ir_model_data.get_object_reference( + cursor, uid, 'som_generationkwh', 'email_baixa_soci' + )[1] + template = power_email_tmpl_obj.read(cursor, uid, template_id) + + email_from = False + template_name = 'Info Som Energia' + + if template.get(template_name, False): + email_from = template.get('enforce_from_account')[0] + + if not email_from: + email_from = account_obj.search(cursor, uid, [('name', '=', template_name)])[0] + + email_params = dict({ + 'email_from': email_from, + 'template_id': template_id + }) + + logger = logging.getLogger('openerp.poweremail') + + try: + wiz_send_obj = self.pool.get('poweremail.send.wizard') + ctx = { + 'active_ids': [soci_id], + 'active_id': soci_id, + 'template_id': email_params['template_id'], + 'src_model': 'somenergia.soci', + 'src_rec_ids': [soci_id], + 'from': email_params['email_from'], + 'state': 'single', + 'priority': '0', + } + + params = {'state': 'single', 'priority': '0', 'from': ctx['from']} + wiz_id = wiz_send_obj.create(cursor, uid, params, ctx) + return wiz_send_obj.send_mail(cursor, uid, [wiz_id], ctx) + + except Exception as e: + logger.info( + 'ERROR sending email to member {soci_id}: {exc}'.format( + soci_id=soci_id, + exc=e + ) + ) + + +WizardBaixaSoci() + From 0162d7350ddd5750883c49944473ebb28b97f8c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Su=C3=A1rez?= Date: Tue, 23 Jun 2020 17:41:46 +0200 Subject: [PATCH 2/4] added wizard xml content & poweremail template --- som_generationkwh/somenergia_soci_data.xml | 85 +++++++++++++++++++ .../wizard/wizard_baixa_soci.xml | 63 ++++++++++++++ 2 files changed, 148 insertions(+) create mode 100644 som_generationkwh/wizard/wizard_baixa_soci.xml diff --git a/som_generationkwh/somenergia_soci_data.xml b/som_generationkwh/somenergia_soci_data.xml index d292501f..b02541f5 100644 --- a/som_generationkwh/somenergia_soci_data.xml +++ b/som_generationkwh/somenergia_soci_data.xml @@ -5,5 +5,90 @@ 2016-03-01 170 + + + + Email de notificació de baixa d'una sòcia + + + somenergia.soci + ${object.partner_id.address[0].email} + + + + Confirmació baixa persona sòcia / Confirmación baja persona socia + mako + + + + support.17062.b8d9f4469fa4d856@helpscout.net + + + + +<% +from mako.template import Template +def render(text_to_render, object_): + templ = Template(text_to_render) + return templ.render_unicode( + object=object_, + format_exceptions=True + ) +t_obj = object.pool.get('poweremail.templates') +md_obj = object.pool.get('ir.model.data') +template_id = md_obj.get_object_reference( + object._cr, object._uid, 'som_poweremail_common_templates', 'common_template_legal_footer' + )[1] +text_legal = render(t_obj.read( + object._cr, object._uid, [template_id], ['def_body_text'])[0]['def_body_text'], + object +) +%> +% if object.partner_id.lang != "es_ES": +
+Hola,
+
+Ens posem amb contacte amb tu per informar-te que hem tramitat correctament la teva baixa de persona sòcia.
+
+T’agraïm el temps que has passat amb nosaltres ajudant-nos a canviar el model energètic actual.
+
+Desitgem que ens retrobem en un futur.
+
+Salut i bona energia!
+
+Equip de Som Energia
+www.somenergia.coop +info@somenergia.coop +Contactar amb Som Energia +% endif + +% if object.partner_id.lang != "ca_ES" and object.partner_id.lang != "es_ES": +---------------------------------------------------------------------------------------------------- +% endif + +% if object.partner_id.lang != "ca_ES": +
+Hola,
+
+Nos ponemos en contacto contigo para informarte que hemos tramitado correctamente tu baja de persona socia.
+
+Te agradecemos el tiempo que has pasado con nosotros ayudándonos a cambiar el modelo energético actual.
+
+Deseamos reencontrarnos en un futuro.
+
+Salud y buena energía!
+
+Equipo de Som Energia
+www.somenergia.coop +info@somenergia.coop +Contactar con Som Energia +% endif +${text_legal} + + + + ]]>
+
+ diff --git a/som_generationkwh/wizard/wizard_baixa_soci.xml b/som_generationkwh/wizard/wizard_baixa_soci.xml new file mode 100644 index 00000000..0ca91076 --- /dev/null +++ b/som_generationkwh/wizard/wizard_baixa_soci.xml @@ -0,0 +1,63 @@ + + + + + wizard.soci.baixa.form + wizard.baixa.soci + form + +
+ + + + + + +