diff --git a/migrations/5.0.24.9.0/post-0003_init_attach_categ_field.py b/migrations/5.0.24.9.0/post-0003_init_attach_categ_field.py new file mode 100644 index 0000000..ef2260a --- /dev/null +++ b/migrations/5.0.24.9.0/post-0003_init_attach_categ_field.py @@ -0,0 +1,37 @@ +# -*- coding: utf-8 -*- +import logging +import pooler + +from tools import config +from oopgrade.oopgrade import load_data_records + + +def up(cursor, installed_version): + if not installed_version: + return + if config.updating_all: + return + logger = logging.getLogger('openerp.migration') + + logger.info("Creating pooler") + pool = pooler.get_pool(cursor.dbname) + + logger.info("Creating table: giscedata.polissa") + pool.get("poweremail.templates")._auto_init(cursor, context={'module': 'poweremail'}) + logger.info("Table created succesfully.") + + logger.info("Updating XMLs") + list_of_records = [ + "poweremail_template_form", + ] + load_data_records( + cursor, 'poweremail', 'poweremail_template_view.xml', list_of_records, mode='update' + ) + logger.info("XMLs succesfully updated.") + + +def down(cursor, installed_version): + pass + + +migrate = up \ No newline at end of file diff --git a/poweremail_send_wizard.py b/poweremail_send_wizard.py index fb48b69..d3f3988 100644 --- a/poweremail_send_wizard.py +++ b/poweremail_send_wizard.py @@ -414,6 +414,18 @@ def add_template_attachments(self, cr, uid, template, mail_id, context=None): attachment_ids_templ.append(new_id) return attachment_ids_templ + def add_record_attachments(self, cursor, uid, template, src_rec_id, context=None): + attachment_ids = [] + if template.attach_record_items: + attachment_o = self.pool.get('ir.attachment') + attachment_sp = [('res_model', '=', template.object_name.model), + ('res_id', '=', src_rec_id)] + + if template.record_attachment_categories: + attachment_sp.append(('category_id', 'in', [c.id for c in template.record_attachment_categories])) + attachment_ids = attachment_o.search(cursor, uid, attachment_sp, context=context) + return attachment_ids + def create_partner_event(self, cr, uid, template, vals, data, src_rec_id, mail_id, attachment_ids, context=None): if context is None: context = {} @@ -516,6 +528,10 @@ def save_to_mailbox(self, cr, uid, ids, context=None): # Add template attachments attachment_ids_templ = self.add_template_attachments(cr, uid, template, mail_id, context=ctx) attachment_ids.extend(attachment_ids_templ) + # Add record attachments + attachment_ids_record = self.add_record_attachments(cr, uid, template, src_rec_id, context=ctx) + attachment_ids.extend(attachment_ids_record) + if attachment_ids: mailbox_vals = { 'pem_attachments_ids': [[6, 0, attachment_ids]], diff --git a/poweremail_template.py b/poweremail_template.py index 09a73c0..116f5cb 100644 --- a/poweremail_template.py +++ b/poweremail_template.py @@ -527,6 +527,11 @@ def _get_model_data_name_search( 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."), + 'record_attachment_categories': fields.many2many('ir.attachment.category', + 'template_attachment_category_rel', + 'templ_id', 'categ_id', + string="Record attachment categories", + help="Only attach record attachments with the included categories in case there's any."), 'model_data_name': fields.function( _get_model_data_name, string='Code', type='char', size=250, method=True, @@ -954,10 +959,12 @@ def _generate_attach_reports(self, cursor, user, template, record_ids, mail, con # vinculats als record_ids i afegirlos a la llista de attach_ids if template.attach_record_items: for record_id in record_ids: - ids = attachment_obj.search(cursor, user, [ - ('res_model', '=', template.object_name.model), - ('res_id', '=', record_id) - ], context=context) + attachment_sp = [('res_model', '=', template.object_name.model), + ('res_id', '=', record_id)] + + if template.record_attachment_categories: + attachment_sp.append(('category_id', 'in', [c.id for c in template.record_attachment_categories])) + ids = attachment_obj.search(cursor, user, attachment_sp, context=context) attachment_id.extend(ids) attach_ids = attachment_obj.search(cursor, user, search_params, context=context) diff --git a/poweremail_template_view.xml b/poweremail_template_view.xml index 340de64..f247594 100644 --- a/poweremail_template_view.xml +++ b/poweremail_template_view.xml @@ -94,6 +94,10 @@ + + + + diff --git a/wizard/wizard_poweremail_preview.py b/wizard/wizard_poweremail_preview.py index 25cf5e4..91a0c00 100644 --- a/wizard/wizard_poweremail_preview.py +++ b/wizard/wizard_poweremail_preview.py @@ -140,46 +140,8 @@ def action_send_static_mail(self, cursor, uid, ids, context=None): if not template: raise Exception("The requested template could not be loaded") - from_account = template_obj.get_from_account_id_from_template( - cursor, uid, template.id, context=context - ) - - # Evaluates an expression and returns its value - # recid: ID of the target record under evaluation - # message: The expression to be evaluated - # template: BrowseRecord object of the current template - # return: Computed message (unicode) or u"" - - pem_too = get_value( - cursor, uid, model_id, message=template.def_to, - template=template, context=context - ) - def_subject = get_value( - cursor, uid, model_id, message=template.def_subject, - template=template, context=context - ) - - body_text = get_value( - cursor, uid, model_id, message=template.def_body_text, - template=template, context=context - ) + mailbox_id = template_obj.generate_mail(cursor, uid, template_id, model_id, context=context) - mail_vals = { - 'pem_from': tools.ustr(from_account['name']) + \ - "<" + tools.ustr(from_account['email_id']) + ">", - 'pem_to': pem_too, - 'pem_cc': False, - 'pem_bcc': False, - 'pem_subject': def_subject, - 'pem_body_text': body_text, - 'pem_account_id': from_account['id'], - 'priority': '1', - 'state': 'na', - 'mail_type': 'multipart/alternative', - 'template_id': template_id - } - - mailbox_id = mailbox_obj.create(cursor, uid, mail_vals) if wizard.save_to_drafts_prev: mailbox_obj.write(cursor, uid, mailbox_id, {'folder': 'drafts'}, context=context)