From fc11b58239f4097be907be3ad41b1c0757b00e7a Mon Sep 17 00:00:00 2001 From: Alexis de Lattre Date: Fri, 12 Dec 2014 12:21:35 +0100 Subject: [PATCH 1/2] [FIX] stock: service lines duplication when grouping DO invoices This is possible that changes happen during the loop in the multiple pickings: an update in a picking could update another picking. The browse must therefore be done inside the loop to update the pickings with the latest changes. Fixes #4201 --- addons/stock/stock.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/addons/stock/stock.py b/addons/stock/stock.py index 276e24b4e2d2f..7fa2f4e92a27a 100644 --- a/addons/stock/stock.py +++ b/addons/stock/stock.py @@ -1132,7 +1132,9 @@ def action_invoice_create(self, cr, uid, ids, journal_id=False, invoices_group = {} res = {} inv_type = type - for picking in self.browse(cr, uid, ids, context=context): + for picking_id in ids: + # The browse inside the loop is done on purpose, as a change in the pickings during the loop is possible + picking = self.browse(cr, uid, picking_id, context=context) if picking.invoice_state != '2binvoiced': continue partner = self._get_partner_to_invoice(cr, uid, picking, context=context) From 117b636d3fdcc32b1e430d41d245a7d8237ca87f Mon Sep 17 00:00:00 2001 From: Christophe Simonis Date: Fri, 25 Sep 2015 14:43:00 +0200 Subject: [PATCH 2/2] [FIX] mail: catch database errors when sending mails --- addons/mail/mail_mail.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/addons/mail/mail_mail.py b/addons/mail/mail_mail.py index 19852e1b18211..aa02654ef58ce 100644 --- a/addons/mail/mail_mail.py +++ b/addons/mail/mail_mail.py @@ -26,6 +26,8 @@ from urllib import urlencode from urlparse import urljoin +import psycopg2 + from openerp import tools from openerp import SUPERUSER_ID from openerp.osv import fields, osv @@ -338,6 +340,12 @@ def send(self, cr, uid, ids, auto_commit=False, recipient_ids=None, context=None # prevent catching transient MemoryErrors, bubble up to notify user or abort cron job # instead of marking the mail as failed raise + except psycopg2.Error: + # If an error with the database occurs, chances are that the cursor is unusable. + # This will lead to an `psycopg2.InternalError` being raised when trying to write + # `state`, shadowing the original exception and forbid a retry on concurrent + # update. Let's bubble it. + raise except Exception: _logger.exception('failed sending mail.mail %s', mail.id) mail.write({'state': 'exception'})