From 6a70d9c5b8d1900157973491fc8b2248d5611cfc Mon Sep 17 00:00:00 2001 From: Alex Date: Thu, 21 Dec 2023 10:06:18 +0100 Subject: [PATCH 1/7] reference_extra_data en campaign line --- .../pre-0001_add_reference_extra_data.py | 25 +++++++++++++++++++ poweremail_campaign/poweremail_campaign.py | 3 ++- .../poweremail_campaign_line.py | 4 ++- 3 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 poweremail_campaign/migrations/5.0.23.12.0/pre-0001_add_reference_extra_data.py diff --git a/poweremail_campaign/migrations/5.0.23.12.0/pre-0001_add_reference_extra_data.py b/poweremail_campaign/migrations/5.0.23.12.0/pre-0001_add_reference_extra_data.py new file mode 100644 index 0000000..142cf76 --- /dev/null +++ b/poweremail_campaign/migrations/5.0.23.12.0/pre-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") + pool.get("poweremail.campaign")._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.py b/poweremail_campaign/poweremail_campaign.py index da44f96..6c23a40 100644 --- a/poweremail_campaign/poweremail_campaign.py +++ b/poweremail_campaign/poweremail_campaign.py @@ -146,7 +146,8 @@ def send_emails(self, cursor, uid, ids, context=None): 'create_date': fields.datetime('Create Date', readonly=1), 'template_obj': fields.function(_ff_created_sent_object, multi='barra_progres', string='Object', type='char', size=64, method=True, readonly=1), 'batch': fields.integer('Batch', help='Sends the indicated quantity of emails each time the "Send Emails" button is pressed. 0 to send all.'), - 'distinct_mails': fields.boolean('Avoid same email', help='Check to avoid send repeated campaigns to the same email') + 'distinct_mails': fields.boolean('Avoid same email', help='Check to avoid send repeated campaigns to the same email'), + 'reference_extra_data': fields.text('Extra data', widget='json') } _defaults = { diff --git a/poweremail_campaign/poweremail_campaign_line.py b/poweremail_campaign/poweremail_campaign_line.py index 66c580c..36e13cc 100644 --- a/poweremail_campaign/poweremail_campaign_line.py +++ b/poweremail_campaign/poweremail_campaign_line.py @@ -77,7 +77,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 +85,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'] = 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: From 7a670116b42c7b5404f7678b934046047e8e9030 Mon Sep 17 00:00:00 2001 From: Alex Date: Thu, 21 Dec 2023 11:45:49 +0100 Subject: [PATCH 2/7] rename migrations --- ...erence_extra_data.py => post-0001_add_reference_extra_data.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename poweremail_campaign/migrations/5.0.23.12.0/{pre-0001_add_reference_extra_data.py => post-0001_add_reference_extra_data.py} (100%) diff --git a/poweremail_campaign/migrations/5.0.23.12.0/pre-0001_add_reference_extra_data.py b/poweremail_campaign/migrations/5.0.23.12.0/post-0001_add_reference_extra_data.py similarity index 100% rename from poweremail_campaign/migrations/5.0.23.12.0/pre-0001_add_reference_extra_data.py rename to poweremail_campaign/migrations/5.0.23.12.0/post-0001_add_reference_extra_data.py From b5c482644539c876ebb1bf85d95dd1c2dbdcaa4c Mon Sep 17 00:00:00 2001 From: Alex Date: Tue, 2 Jan 2024 11:27:01 +0100 Subject: [PATCH 3/7] fix columns --- .../5.0.23.12.0/post-0001_add_reference_extra_data.py | 4 ++-- poweremail_campaign/poweremail_campaign.py | 3 +-- poweremail_campaign/poweremail_campaign_line.py | 1 + 3 files changed, 4 insertions(+), 4 deletions(-) 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 index 142cf76..ae80b9d 100644 --- 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 @@ -14,8 +14,8 @@ def up(cursor, installed_version): pool = pooler.get_pool(cursor.dbname) ##UPDATAR UN MODUL NOU AL CREAR-LO O AFEGIR UNA COLUMNA## - logger.info("Creating table: poweremail.campaign") - pool.get("poweremail.campaign")._auto_init(cursor, context={'module': 'poweremail_campaign'}) + 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): diff --git a/poweremail_campaign/poweremail_campaign.py b/poweremail_campaign/poweremail_campaign.py index 6c23a40..da44f96 100644 --- a/poweremail_campaign/poweremail_campaign.py +++ b/poweremail_campaign/poweremail_campaign.py @@ -146,8 +146,7 @@ def send_emails(self, cursor, uid, ids, context=None): 'create_date': fields.datetime('Create Date', readonly=1), 'template_obj': fields.function(_ff_created_sent_object, multi='barra_progres', string='Object', type='char', size=64, method=True, readonly=1), 'batch': fields.integer('Batch', help='Sends the indicated quantity of emails each time the "Send Emails" button is pressed. 0 to send all.'), - 'distinct_mails': fields.boolean('Avoid same email', help='Check to avoid send repeated campaigns to the same email'), - 'reference_extra_data': fields.text('Extra data', widget='json') + 'distinct_mails': fields.boolean('Avoid same email', help='Check to avoid send repeated campaigns to the same email') } _defaults = { diff --git a/poweremail_campaign/poweremail_campaign_line.py b/poweremail_campaign/poweremail_campaign_line.py index 36e13cc..87d4846 100644 --- a/poweremail_campaign/poweremail_campaign_line.py +++ b/poweremail_campaign/poweremail_campaign_line.py @@ -140,6 +140,7 @@ class PoweremailCampaign(osv.osv): _columns = { 'reference_ids': fields.one2many('poweremail.campaign.line', 'campaign_id', 'Campaign Line'), + 'reference_extra_data': fields.text('Extra data', widget='json') } From 40ca90b02f5048e9e74c495f1c775f50cae16c56 Mon Sep 17 00:00:00 2001 From: Alex Date: Tue, 2 Jan 2024 14:40:15 +0100 Subject: [PATCH 4/7] change columns --- poweremail_campaign/poweremail_campaign_line.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/poweremail_campaign/poweremail_campaign_line.py b/poweremail_campaign/poweremail_campaign_line.py index 87d4846..24e545c 100644 --- a/poweremail_campaign/poweremail_campaign_line.py +++ b/poweremail_campaign/poweremail_campaign_line.py @@ -127,6 +127,7 @@ def generate_mail_button(self, cursor, uid, ids, context=None): _defaults = { 'state': lambda *a: 'to_send', + 'reference_extra_data': fields.text('Extra data', widget='json') } @@ -139,8 +140,7 @@ class PoweremailCampaign(osv.osv): _inherit = 'poweremail.campaign' _columns = { - 'reference_ids': fields.one2many('poweremail.campaign.line', 'campaign_id', 'Campaign Line'), - 'reference_extra_data': fields.text('Extra data', widget='json') + 'reference_ids': fields.one2many('poweremail.campaign.line', 'campaign_id', 'Campaign Line') } From d9a998be52dac9c73b66335a420c141116f9328f Mon Sep 17 00:00:00 2001 From: Alex Date: Tue, 2 Jan 2024 14:45:20 +0100 Subject: [PATCH 5/7] fix error columns --- poweremail_campaign/poweremail_campaign_line.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/poweremail_campaign/poweremail_campaign_line.py b/poweremail_campaign/poweremail_campaign_line.py index 24e545c..14199fb 100644 --- a/poweremail_campaign/poweremail_campaign_line.py +++ b/poweremail_campaign/poweremail_campaign_line.py @@ -122,12 +122,12 @@ 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 = { 'state': lambda *a: 'to_send', - 'reference_extra_data': fields.text('Extra data', widget='json') } From 5ebbae90f1c0e3368f2898b285666fd874b578d6 Mon Sep 17 00:00:00 2001 From: Alex Date: Wed, 3 Jan 2024 12:46:10 +0100 Subject: [PATCH 6/7] mail funcional --- poweremail_campaign/poweremail_campaign_line.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/poweremail_campaign/poweremail_campaign_line.py b/poweremail_campaign/poweremail_campaign_line.py index 14199fb..42fe054 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): @@ -86,7 +88,7 @@ def send_mail_from_line(self, cursor, uid, line_id, template, context=None): context['src_rec_id'] = line_id context['src_model'] = self._name if line_v.get('reference_extra_data'): - context['reference_extra_data'] = line_v['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: @@ -123,7 +125,7 @@ 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), - 'reference_extra_data': fields.text('Extra data', widget='json') + 'reference_extra_data': fields.char('Extra data', widget='json', size=256) } _defaults = { From ba9d0379165ccdaea62f4133043934307c602520 Mon Sep 17 00:00:00 2001 From: Alex Date: Wed, 3 Jan 2024 12:48:46 +0100 Subject: [PATCH 7/7] undo canvi columns --- poweremail_campaign/poweremail_campaign_line.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/poweremail_campaign/poweremail_campaign_line.py b/poweremail_campaign/poweremail_campaign_line.py index 42fe054..93ba94a 100644 --- a/poweremail_campaign/poweremail_campaign_line.py +++ b/poweremail_campaign/poweremail_campaign_line.py @@ -125,7 +125,7 @@ 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), - 'reference_extra_data': fields.char('Extra data', widget='json', size=256) + 'reference_extra_data': fields.text('Extra data', widget='json') } _defaults = {