From 7fbf1fffe04fd37efadffaf503c8a68d0e824448 Mon Sep 17 00:00:00 2001 From: Marc Calvo Date: Mon, 21 Oct 2024 14:04:33 +0200 Subject: [PATCH 1/2] allow sending mails right after creation --- .../post-0001_load_field_send_immediately.py | 29 +++++++++++++++++++ poweremail_template.py | 16 +++++++++- poweremail_template_view.xml | 1 + 3 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 migrations/5.0.25.1.0/post-0001_load_field_send_immediately.py diff --git a/migrations/5.0.25.1.0/post-0001_load_field_send_immediately.py b/migrations/5.0.25.1.0/post-0001_load_field_send_immediately.py new file mode 100644 index 0000000..7bdf424 --- /dev/null +++ b/migrations/5.0.25.1.0/post-0001_load_field_send_immediately.py @@ -0,0 +1,29 @@ +# -*- coding: utf-8 -*- +import logging +import pooler + +from oopgrade.oopgrade import load_data_records +from tools import config + +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.") + + load_data_records(cursor, 'poweremail', 'poweremail_template_view.xml', ['poweremail_template_form']) + + +def down(cursor, installed_version): + pass + + +migrate = up diff --git a/poweremail_template.py b/poweremail_template.py index 116f5cb..f751932 100644 --- a/poweremail_template.py +++ b/poweremail_template.py @@ -538,6 +538,8 @@ def _get_model_data_name_search( help="Model Data Name.", fnct_search=_get_model_data_name_search, ), + 'send_immediately': fields.boolean('Send Immediately', help="Emails created from this template will be sent" + " immediately without going throug outbox folder.") } _defaults = { @@ -1125,8 +1127,12 @@ def generate_mail_sync(self, cursor, user, template_id, record_ids, context=None # Generating email, attachments and event if not template.save_to_drafts: pe_obj = self.pool.get('poweremail.mailbox') + send_immediately = template.send_immediately if self.check_outbox(cursor, user, mailbox_id, context=context): - pe_obj.write(cursor, user, mailbox_id, {'folder': 'outbox'}, context=context) + if send_immediately: + pe_obj.send_this_mail(cursor, user, [mailbox_id], context=context) + else: + pe_obj.write(cursor, user, mailbox_id, {'folder': 'outbox'}, context=context) if len(mailbox_ids) > 1: return mailbox_ids elif mailbox_ids: @@ -1134,6 +1140,14 @@ def generate_mail_sync(self, cursor, user, template_id, record_ids, context=None else: return False + def check_send_email_on_creation(self, cursor, uid, context=None): + if context is None: + context = {} + conf_o = self.pool.get('res.config') + + send_on_creation = int(conf_o.get(cursor, uid, 'send_signature_email_on_creation', '0')) + return send_on_creation + def create_action_reference(self, cursor, uid, ids, context): template = self.pool.get('poweremail.templates').browse( cursor, uid, ids[0] diff --git a/poweremail_template_view.xml b/poweremail_template_view.xml index f247594..16045d8 100644 --- a/poweremail_template_view.xml +++ b/poweremail_template_view.xml @@ -112,6 +112,7 @@ attrs="{'required':[('auto_email','=',True)],'readonly':[('auto_email','=', False)]}" colspan="4"/> + From 03e92f067f7df759df727a6df26519e0c396c4a6 Mon Sep 17 00:00:00 2001 From: Marc Calvo Date: Wed, 23 Oct 2024 17:32:04 +0200 Subject: [PATCH 2/2] remove useless code --- poweremail_template.py | 8 -------- 1 file changed, 8 deletions(-) diff --git a/poweremail_template.py b/poweremail_template.py index f751932..ea392d6 100644 --- a/poweremail_template.py +++ b/poweremail_template.py @@ -1140,14 +1140,6 @@ def generate_mail_sync(self, cursor, user, template_id, record_ids, context=None else: return False - def check_send_email_on_creation(self, cursor, uid, context=None): - if context is None: - context = {} - conf_o = self.pool.get('res.config') - - send_on_creation = int(conf_o.get(cursor, uid, 'send_signature_email_on_creation', '0')) - return send_on_creation - def create_action_reference(self, cursor, uid, ids, context): template = self.pool.get('poweremail.templates').browse( cursor, uid, ids[0]