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/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/somenergia_soci_view.xml b/som_generationkwh/somenergia_soci_view.xml
index daf74496..f1532dcd 100644
--- a/som_generationkwh/somenergia_soci_view.xml
+++ b/som_generationkwh/somenergia_soci_view.xml
@@ -66,23 +66,5 @@
-
-
- somenergia.soci.form
- somenergia.soci
- form
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/som_generationkwh/tests/__init__.py b/som_generationkwh/tests/__init__.py
index fd1d69bf..f6d963f1 100644
--- a/som_generationkwh/tests/__init__.py
+++ b/som_generationkwh/tests/__init__.py
@@ -1,4 +1,5 @@
from emission_tests import *
from investment_tests import *
from partner_tests import *
-from somenergia_soci_tests import *
\ No newline at end of file
+from somenergia_soci_tests import *
+from test_wizard_baixa_soci import *
\ No newline at end of file
diff --git a/som_generationkwh/tests/generation_data_demo.xml b/som_generationkwh/tests/generation_data_demo.xml
index 6462bbd7..57ed75ba 100644
--- a/som_generationkwh/tests/generation_data_demo.xml
+++ b/som_generationkwh/tests/generation_data_demo.xml
@@ -280,6 +280,17 @@
approved
587
+
+
+ info@somenergia.coop
+ yes
+ smtp.mandrillapp.com
+ html
+ Info Som Energia
+ approved
+ 587
+
+
diff --git a/som_generationkwh/tests/test_wizard_baixa_soci.py b/som_generationkwh/tests/test_wizard_baixa_soci.py
new file mode 100644
index 00000000..ee990704
--- /dev/null
+++ b/som_generationkwh/tests/test_wizard_baixa_soci.py
@@ -0,0 +1,97 @@
+# -*- coding: utf-8 -*-
+from destral import testing
+from destral.transaction import Transaction
+from osv import osv
+from datetime import datetime
+import poweremail
+import mock
+
+
+class TestWizardBaixaSoci(testing.OOTestCase):
+ def setUp(self):
+ self.txn = Transaction().start(self.database)
+ self.cursor = self.txn.cursor
+ self.uid = self.txn.user
+ self.Investment = self.openerp.pool.get('generationkwh.investment')
+ self.IrModelData = self.openerp.pool.get('ir.model.data')
+ self.Soci = self.openerp.pool.get('somenergia.soci')
+ self.WizardBaixaSoci = self.openerp.pool.get('wizard.baixa.soci')
+ self.AccountObj = self.openerp.pool.get('poweremail.core_accounts')
+
+ def tearDown(self):
+ self.txn.stop()
+
+ def test__baixa_soci__allowed(self):
+ member_id = self.IrModelData.get_object_reference(
+ self.cursor, self.uid, 'som_generationkwh', 'soci_0003'
+ )[1]
+ self.Soci.write(self.cursor, self.uid, [member_id], {'baixa': False, 'data_baixa_soci': None})
+ context = {'active_ids':[member_id]}
+
+ wiz_id = self.WizardBaixaSoci.create(self.cursor, self.uid, {'info':''}, context=context)
+ self.WizardBaixaSoci.baixa_soci(self.cursor, self.uid, wiz_id, context=context, send_mail=False)
+
+ baixa = self.Soci.read(self.cursor, self.uid, member_id, ['baixa'])['baixa']
+ self.assertTrue(baixa)
+
+ def test__baixa_soci__notAllowed(self):
+ member_id = self.IrModelData.get_object_reference(
+ self.cursor, self.uid, 'som_generationkwh', 'soci_0001'
+ )[1]
+ self.Soci.write(self.cursor, self.uid, [member_id], {'baixa': False, 'data_baixa_soci': None})
+ context = {'active_ids':[member_id]}
+
+ wiz_id = self.WizardBaixaSoci.create(self.cursor, self.uid, {'info':''}, context=context)
+ self.WizardBaixaSoci.baixa_soci(self.cursor, self.uid, wiz_id, context=context, send_mail=False)
+
+ baixa = self.Soci.read(self.cursor, self.uid, member_id, ['baixa'])['baixa']
+ self.assertFalse(baixa)
+
+ @mock.patch("poweremail.poweremail_send_wizard.poweremail_send_wizard.send_mail")
+ def test__baixa_soci_and_send_mail__allowed(self, mocked_send_mail):
+ member_id = self.IrModelData.get_object_reference(
+ self.cursor, self.uid, 'som_generationkwh', 'soci_0003'
+ )[1]
+ self.Soci.write(self.cursor, self.uid, [member_id], {'baixa': False, 'data_baixa_soci': None})
+ context = {'active_ids':[member_id]}
+
+ wiz_id = self.WizardBaixaSoci.create(self.cursor, self.uid, {'info':''}, context=context)
+ self.WizardBaixaSoci.baixa_soci(self.cursor, self.uid, wiz_id, context=context, send_mail=True)
+
+ baixa = self.Soci.read(self.cursor, self.uid, member_id, ['baixa'])['baixa']
+ self.assertTrue(baixa)
+
+ template_id = self.IrModelData.get_object_reference(
+ self.cursor, self.uid, 'som_generationkwh', 'email_baixa_soci'
+ )[1]
+
+ email_from = self.AccountObj.search(self.cursor, self.uid, [('name', '=', 'Info Som Energia')])[0]
+
+ expected_ctx = {
+ 'active_ids': [member_id],
+ 'active_id': member_id,
+ 'template_id': template_id,
+ 'src_model': 'somenergia.soci',
+ 'src_rec_ids': [member_id],
+ 'from': email_from,
+ 'state': 'single',
+ 'priority': '0',
+ }
+
+ mocked_send_mail.assert_called_with(self.cursor, self.uid, mock.ANY, expected_ctx)
+
+ @mock.patch("poweremail.poweremail_send_wizard.poweremail_send_wizard.send_mail")
+ def test__baixa_soci_and_send_mail__notAllowed(self, mocked_send_mail):
+ member_id = self.IrModelData.get_object_reference(
+ self.cursor, self.uid, 'som_generationkwh', 'soci_0001'
+ )[1]
+ self.Soci.write(self.cursor, self.uid, [member_id], {'baixa': False, 'data_baixa_soci': None})
+
+ context = {'active_ids':[member_id]}
+
+ wiz_id = self.WizardBaixaSoci.create(self.cursor, self.uid, {'info':''}, context=context)
+ self.WizardBaixaSoci.baixa_soci_and_send_mail(self.cursor, self.uid, wiz_id, context=context)
+
+ baixa = self.Soci.read(self.cursor, self.uid, member_id, ['baixa'])['baixa']
+ self.assertFalse(baixa)
+ mocked_send_mail.assert_not_called()
\ No newline at end of file
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..7a816a65
--- /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()
+
diff --git a/som_generationkwh/wizard/wizard_baixa_soci.xml b/som_generationkwh/wizard/wizard_baixa_soci.xml
new file mode 100644
index 00000000..f418152f
--- /dev/null
+++ b/som_generationkwh/wizard/wizard_baixa_soci.xml
@@ -0,0 +1,63 @@
+
+
+
+
+ wizard.soci.baixa.form
+ wizard.baixa.soci
+ form
+
+
+
+
+
+
+
+ Baixa de sòcia
+ wizard.baixa.soci
+ form
+ form
+ new
+
+
+
+
+
+ Baixa de sòcia
+ client_action_multi
+ action
+ somenergia.soci
+
+
+
+