From 7009842da49048a802f34c60ae7f39c73b7072ae Mon Sep 17 00:00:00 2001 From: Ruben1700 Date: Thu, 8 Aug 2024 12:38:53 +0200 Subject: [PATCH 1/5] Permitir adjuntar documentos con categorias concretas --- .../post-0003_init_attach_categ_field.py | 37 +++++++++++++++++ poweremail_template.py | 15 +++++-- poweremail_template_view.xml | 1 + wizard/wizard_poweremail_preview.py | 40 +------------------ 4 files changed, 50 insertions(+), 43 deletions(-) create mode 100644 migrations/5.0.24.9.0/post-0003_init_attach_categ_field.py 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_template.py b/poweremail_template.py index ebaa2d2..f7e1061 100644 --- a/poweremail_template.py +++ b/poweremail_template.py @@ -524,6 +524,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, @@ -951,10 +956,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', 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..312fe42 100644 --- a/poweremail_template_view.xml +++ b/poweremail_template_view.xml @@ -94,6 +94,7 @@ + diff --git a/wizard/wizard_poweremail_preview.py b/wizard/wizard_poweremail_preview.py index e91a68b..07c51ee 100644 --- a/wizard/wizard_poweremail_preview.py +++ b/wizard/wizard_poweremail_preview.py @@ -139,46 +139,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) From 335a96b4ecca8783e67b971dd1f9fa4296c9bc56 Mon Sep 17 00:00:00 2001 From: Ruben1700 Date: Thu, 8 Aug 2024 14:36:08 +0200 Subject: [PATCH 2/5] Fix --- poweremail_template.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/poweremail_template.py b/poweremail_template.py index f7e1061..d8b3a8a 100644 --- a/poweremail_template.py +++ b/poweremail_template.py @@ -960,7 +960,8 @@ def _generate_attach_reports(self, cursor, user, template, record_ids, mail, con ('res_id', '=', record_id)] if template.record_attachment_categories: - attachment_sp.append([('category_id', 'in', template.record_attachment_categories)]) + template_categs = template.read(['record_attachment_categories'])[0]['record_attachment_categories'] + attachment_sp.append(('category_id', 'in', template_categs)) ids = attachment_obj.search(cursor, user, attachment_sp, context=context) attachment_id.extend(ids) From f7ba837fb417b8aec394a5f319c8aafd0a06dc77 Mon Sep 17 00:00:00 2001 From: Ruben1700 Date: Thu, 8 Aug 2024 15:38:19 +0200 Subject: [PATCH 3/5] =?UTF-8?q?Millorar=20visualitzaci=C3=B3=20dels=20camp?= =?UTF-8?q?s?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- poweremail_template_view.xml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/poweremail_template_view.xml b/poweremail_template_view.xml index 312fe42..f247594 100644 --- a/poweremail_template_view.xml +++ b/poweremail_template_view.xml @@ -94,7 +94,10 @@ - + + + + From c70f97a8a649551bdacf08d9b8368e9c999e9d20 Mon Sep 17 00:00:00 2001 From: Luis Carlos Bautista Date: Tue, 10 Sep 2024 12:29:29 +0200 Subject: [PATCH 4/5] fix: send wizard didnt attach attachments from record --- poweremail_send_wizard.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) 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]], From 712c3023b09070c3e8e00fdd32335082a4ca8c8d Mon Sep 17 00:00:00 2001 From: Luis Carlos Bautista Date: Tue, 10 Sep 2024 12:32:40 +0200 Subject: [PATCH 5/5] fix: wtf @Ruben1700 --- poweremail_template.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/poweremail_template.py b/poweremail_template.py index d8b3a8a..62ec81c 100644 --- a/poweremail_template.py +++ b/poweremail_template.py @@ -960,8 +960,7 @@ def _generate_attach_reports(self, cursor, user, template, record_ids, mail, con ('res_id', '=', record_id)] if template.record_attachment_categories: - template_categs = template.read(['record_attachment_categories'])[0]['record_attachment_categories'] - attachment_sp.append(('category_id', 'in', template_categs)) + 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)