Skip to content

Commit

Permalink
Merge pull request #143 from gisce/52649_show_model_data_name_in_powe…
Browse files Browse the repository at this point in the history
…remail_templates

Añadir el model data name en el formulario de las plantillas de email
  • Loading branch information
lcbautista authored Jan 3, 2024
2 parents 6785625 + fe4ae22 commit a427ef6
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# -*- coding: utf-8 -*-
import logging
from oopgrade.oopgrade import load_data_records
import pooler


def up(cursor, installed_version):
if not installed_version:
return

pool = pooler.get_pool(cursor.dbname)
logger = logging.getLogger('openerp.migration')

logger.info("Adding related column to poweremail.templates")
pool.get("poweremail.templates")._auto_init(cursor, context={'module': 'poweremail'})
logger.info("Related column loaded successfully.")

view = "poweremail_template_view.xml"
view_record = [
"poweremail_template_form",
]
logger.info("Updating XML {}".format(view))

load_data_records(cursor, 'poweremail', view, view_record, mode='update')

logger.info("XMLs succesfully updated.")


def down(cursor, installed_version):
pass


migrate = up
45 changes: 44 additions & 1 deletion poweremail_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,43 @@ def fnct_inv_attachment_ids(self, cursor, uid, ids, field_name, value, args, con
attach_obj.unlink(cursor, uid, [attach_id], context=context)
return True

def _get_model_data_name(
self, cursor, uid, template_ids, field_name, arg, context=None):
res = {}
for template_id in template_ids:
cursor.execute("SELECT name FROM ir_model_data WHERE model = 'poweremail.templates' AND res_id = %s",(template_id,))
sql_res = cursor.fetchone()
if sql_res:
res[template_id] = sql_res[0]
return res

def _get_model_data_name_search(
self, cursor, uid, template_ids, field_name, arg, context=None):
if not context:
context = {}
if not arg:
return [('id', '=', 0)]
else:
if arg[0][2]:
model_data_obj = self.pool.get('ir.model.data')
ids_model_data = model_data_obj.search(cursor, uid, [
('name', 'ilike', arg[0][2]),
('model', '=', 'poweremail.templates')
], context=context)
records = model_data_obj.read(cursor, uid, ids_model_data,
['id', 'res_id'], context=context)
res_ids = [record['res_id'] for record in records]
return [('id', 'in', res_ids)]
else:
model_data_obj = self.pool.get('ir.model.data')
ids_model_data = model_data_obj.search(cursor, uid, [
('model', '=', 'poweremail.templates')
], context=context)
records = model_data_obj.read(cursor, uid, ids_model_data,
['id', 'res_id'], context=context)
res_ids = [record['res_id'] for record in records]
return [('id', 'not in', res_ids)]

_columns = {
'name': fields.char('Name of Template', size=100, required=True),
'object_name': fields.many2one('ir.model', 'Model'),
Expand Down Expand Up @@ -471,7 +508,13 @@ def fnct_inv_attachment_ids(self, cursor, uid, ids, field_name, value, args, con
method=True, type='one2many',
relation='ir.attachment',
string='Attachments'),
'attach_record_items': fields.boolean('Attach record items', select=2, help=u"Si es marca aquesta opcio, s'enviaran com a fitxers adjunts del email tots els adjunts del registre utilitzat per renderitzar el email.")
'attach_record_items': fields.boolean('Attach record items', select=2, help=u"Si es marca aquesta opcio, s'enviaran com a fitxers adjunts del email tots els adjunts del registre utilitzat per renderitzar el email."),
'model_data_name': fields.function(
_get_model_data_name, string='Code',
type='char', size=250, method=True,
help="Model Data Name.",
fnct_search=_get_model_data_name_search,
),
}

_defaults = {
Expand Down
1 change: 1 addition & 0 deletions poweremail_template_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Power Email Templates">
<field name="model_data_name" colspan="4" select="1"/>
<field name="name" />
<field name="object_name" required="1"/>
<field name="model_int_name" invisible="1" />
Expand Down

0 comments on commit a427ef6

Please sign in to comment.