diff --git a/migrations/5.0.23.12.0/post-0001_add_model_data_name_in_poweremail_templates.py b/migrations/5.0.23.12.0/post-0001_add_model_data_name_in_poweremail_templates.py new file mode 100644 index 0000000..86b3ff0 --- /dev/null +++ b/migrations/5.0.23.12.0/post-0001_add_model_data_name_in_poweremail_templates.py @@ -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 diff --git a/poweremail_template.py b/poweremail_template.py index 5df43eb..b0515dd 100644 --- a/poweremail_template.py +++ b/poweremail_template.py @@ -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'), @@ -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 = { diff --git a/poweremail_template_view.xml b/poweremail_template_view.xml index 5045671..b47074d 100644 --- a/poweremail_template_view.xml +++ b/poweremail_template_view.xml @@ -41,6 +41,7 @@ form
+