diff --git a/poweremail_campaign/migrations/5.0.23.12.0/post-0001_add_reference_extra_data.py b/poweremail_campaign/migrations/5.0.23.12.0/post-0001_add_reference_extra_data.py new file mode 100644 index 0000000..ae80b9d --- /dev/null +++ b/poweremail_campaign/migrations/5.0.23.12.0/post-0001_add_reference_extra_data.py @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- +import logging +import pooler +from oopgrade.oopgrade import load_data, load_data_records + + +def up(cursor, installed_version): + if not installed_version: + return + + logger = logging.getLogger('openerp.migration') + + logger.info("Creating pooler") + pool = pooler.get_pool(cursor.dbname) + + ##UPDATAR UN MODUL NOU AL CREAR-LO O AFEGIR UNA COLUMNA## + logger.info("Creating table: poweremail.campaign.line") + pool.get("poweremail.campaign.line")._auto_init(cursor, context={'module': 'poweremail_campaign'}) + logger.info("Table created succesfully.") + +def down(cursor, installed_version): + pass + + +migrate = up diff --git a/poweremail_campaign/poweremail_campaign_line.py b/poweremail_campaign/poweremail_campaign_line.py index 66c580c..93ba94a 100644 --- a/poweremail_campaign/poweremail_campaign_line.py +++ b/poweremail_campaign/poweremail_campaign_line.py @@ -3,6 +3,8 @@ from osv import osv, fields from osv.osv import TransactionExecute from base.res.partner.partner import _lang_get +import json +from ast import literal_eval class PoweremailCampaignLine(osv.osv): @@ -77,7 +79,7 @@ def poweremail_unlink_callback(self, cursor, uid, ids, context=None): def send_mail_from_line(self, cursor, uid, line_id, template, context=None): pm_template_obj = TransactionExecute(cursor.dbname, uid, 'poweremail.templates') self_obj = TransactionExecute(cursor.dbname, uid, 'poweremail.campaign.line') - line_v = self.read(cursor, uid, line_id, ['state', 'mail_id']) + line_v = self.read(cursor, uid, line_id, ['state', 'mail_id', 'reference_extra_data']) if line_v['state'] in ('sent', 'sending') and line_v['mail_id']: return ref_aux = self.read(cursor, uid, line_id, ['ref'])['ref'] @@ -85,6 +87,8 @@ def send_mail_from_line(self, cursor, uid, line_id, template, context=None): try: context['src_rec_id'] = line_id context['src_model'] = self._name + if line_v.get('reference_extra_data'): + context['reference_extra_data'] = literal_eval(json.loads(line_v['reference_extra_data'])) self_obj.write(line_id, {'state': 'sending'}) pm_template_obj.generate_mail(template, id_aux, context=context) except Exception as e: @@ -120,7 +124,8 @@ def generate_mail_button(self, cursor, uid, ids, context=None): ), 'state': fields.selection(STATE_SELECTION, 'State'), 'log': fields.text('Line Log'), - 'lang': fields.selection(_lang_get, 'Language', size=5, readonly=True) + 'lang': fields.selection(_lang_get, 'Language', size=5, readonly=True), + 'reference_extra_data': fields.text('Extra data', widget='json') } _defaults = { @@ -137,7 +142,7 @@ class PoweremailCampaign(osv.osv): _inherit = 'poweremail.campaign' _columns = { - 'reference_ids': fields.one2many('poweremail.campaign.line', 'campaign_id', 'Campaign Line'), + 'reference_ids': fields.one2many('poweremail.campaign.line', 'campaign_id', 'Campaign Line') }