From 318f2547617d8c8b746cf21810d6f21e19ae487f Mon Sep 17 00:00:00 2001 From: Julien Legros Date: Mon, 9 Feb 2015 13:21:06 +0100 Subject: [PATCH 1/2] [IMP] fetchmail: process pop messages in subsets Most pop servers don't perform deletions until QUIT. If for some reason the process is killed while fetching a large quantity of messages, the quit method isn't invoked, while the commit method has been. We may thus end up with duplicated messages the next time we try to fetch. It therefore helps to fetch the messages in small subsets and call the quit method between those subsets. --- addons/fetchmail/fetchmail.py | 47 +++++++++++++++++++---------------- 1 file changed, 26 insertions(+), 21 deletions(-) diff --git a/addons/fetchmail/fetchmail.py b/addons/fetchmail/fetchmail.py index 4d32cc13139..0a27a05b275 100644 --- a/addons/fetchmail/fetchmail.py +++ b/addons/fetchmail/fetchmail.py @@ -40,6 +40,7 @@ from openerp import tools from openerp.tools.translate import _ _logger = logging.getLogger(__name__) +MAX_POP_MESSAGES = 50 class fetchmail_server(osv.osv): """Incoming POP/IMAP mail server account""" @@ -223,27 +224,31 @@ openerp_mailgate: "|/path/to/openerp-mailgate.py --host=localhost -u %(uid)d -p imap_server.logout() elif server.type == 'pop': try: - pop_server = server.connect() - (numMsgs, totalSize) = pop_server.stat() - pop_server.list() - for num in range(1, numMsgs + 1): - (header, msges, octets) = pop_server.retr(num) - msg = '\n'.join(msges) - res_id = None - try: - res_id = mail_thread.message_process(cr, uid, server.object_id.model, - msg, - save_original=server.original, - strip_attachments=(not server.attach), - context=context) - pop_server.dele(num) - except Exception: - _logger.exception('Failed to process mail from %s server %s.', server.type, server.name) - failed += 1 - if res_id and server.action_id: - action_pool.run(cr, uid, [server.action_id.id], {'active_id': res_id, 'active_ids': [res_id], 'active_model': context.get("thread_model", server.object_id.model)}) - cr.commit() - _logger.info("Fetched %d email(s) on %s server %s; %d succeeded, %d failed.", numMsgs, server.type, server.name, (numMsgs - failed), failed) + while True: + pop_server = server.connect() + (numMsgs, totalSize) = pop_server.stat() + pop_server.list() + for num in range(1, min(MAX_POP_MESSAGES, numMsgs) + 1): + (header, msges, octets) = pop_server.retr(num) + msg = '\n'.join(msges) + res_id = None + try: + res_id = mail_thread.message_process(cr, uid, server.object_id.model, + msg, + save_original=server.original, + strip_attachments=(not server.attach), + context=context) + pop_server.dele(num) + except Exception: + _logger.exception('Failed to process mail from %s server %s.', server.type, server.name) + failed += 1 + if res_id and server.action_id: + action_pool.run(cr, uid, [server.action_id.id], {'active_id': res_id, 'active_ids': [res_id], 'active_model': context.get("thread_model", server.object_id.model)}) + cr.commit() + if numMsgs < MAX_POP_MESSAGES: + break + pop_server.quit() + _logger.info("Fetched %d email(s) on %s server %s; %d succeeded, %d failed.", numMsgs, server.type, server.name, (numMsgs - failed), failed) except Exception: _logger.exception("General failure when trying to fetch mail from %s server %s.", server.type, server.name) finally: From 1d76586a1b0fff766581871cd277332bbfec030a Mon Sep 17 00:00:00 2001 From: Denis Ledoux Date: Mon, 9 Feb 2015 17:42:37 +0100 Subject: [PATCH 2/2] [FIX] web: context lang & active* in action buttons This reverts rev. 9f9e7ef0e1ca1d2f5fc5e0a166499c95359dbbf3 As explained in 9f9e7ef0e1ca1d2f5fc5e0a166499c95359dbbf3, if a field "lang" is present in the view, clicking in any action item in the more menu leaded for the action title to be translated in the lang value of the form, such as in the partner form. 9f9e7ef0e1ca1d2f5fc5e0a166499c95359dbbf3 fixed the issue, but has as side-effect to not update correctly the active* keys. So, if "active_id" was used in the context of the action button, and the active_id was set in the dataset context, for example because you come from another form, trough another action button (For instance, Customers > Opportunities > Logged Calls), the active_id was not updated with the current id of the record. opw-620293 opw-617321 fixes #3462 --- addons/web/controllers/main.py | 4 ++-- addons/web/static/src/js/view_form.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/addons/web/controllers/main.py b/addons/web/controllers/main.py index b3acbbe5119..f5c31b2d1bf 100644 --- a/addons/web/controllers/main.py +++ b/addons/web/controllers/main.py @@ -1422,7 +1422,7 @@ class Action(openerpweb.Controller): except Exception: action_id = 0 # force failed read - base_action = Actions.read([action_id], ['type'], req.context) + base_action = Actions.read([action_id], ['name', 'type'], req.session.get_context()) if base_action: ctx = {} action_type = base_action[0]['type'] @@ -1431,7 +1431,7 @@ class Action(openerpweb.Controller): ctx.update(req.context) action = req.session.model(action_type).read([action_id], False, ctx) if action: - value = clean_action(req, action[0]) + value = clean_action(req, dict(action[0], **base_action[0])) return value @openerpweb.jsonrequest diff --git a/addons/web/static/src/js/view_form.js b/addons/web/static/src/js/view_form.js index d4cf85a59f2..201f472b800 100644 --- a/addons/web/static/src/js/view_form.js +++ b/addons/web/static/src/js/view_form.js @@ -1165,7 +1165,7 @@ instance.web.FormView = instance.web.View.extend(instance.web.form.FieldManagerM }, build_eval_context: function() { var a_dataset = this.dataset; - return new instance.web.CompoundContext(this._build_view_fields_values(), a_dataset.get_context()); + return new instance.web.CompoundContext(a_dataset.get_context(), this._build_view_fields_values()); }, });