Skip to content

Commit

Permalink
Merge pull request #31 from gisce/52708_Comunicacio_automatica_rectif…
Browse files Browse the repository at this point in the history
…icatives

Nuevo campo reference_extra_data
  • Loading branch information
lcbautista authored Jan 24, 2024
2 parents 05f5a81 + ba9d037 commit d663d27
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -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
11 changes: 8 additions & 3 deletions poweremail_campaign/poweremail_campaign_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -77,14 +79,16 @@ 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']
id_aux = int(ref_aux.split(",")[1])
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:
Expand Down Expand Up @@ -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 = {
Expand All @@ -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')
}


Expand Down

0 comments on commit d663d27

Please sign in to comment.