From dbaaf59f74ba0b7e26a1cb248d34fb58d101e306 Mon Sep 17 00:00:00 2001 From: Josse Colpaert Date: Sat, 26 Feb 2022 00:06:00 +0000 Subject: [PATCH] [FIX] account_edi: avoid savepoint error and inform the user correctly MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Before, when sending an invoice for the first time, it would give a "cannot find savepoint" traceback upon wanting to release it. We avoid that error by putting less code in the with statement, so the savepoint gets released a lot earlier while the record remains locked for the rest of the transaction. We also put a nice error message if the user can not send at the moment because another process is already sending. (might happen more often in v15) We also updated the translation .pot as we added a new message and some messages were missing anyways in the .pot, so we added those as well. closes odoo/odoo#86317 X-original-commit: a135ef6c78a5ddd1eed36bbb91ee01d82c18e592 Signed-off-by: William André (wan) --- addons/account_edi/i18n/account_edi.pot | 6 ++++++ addons/account_edi/models/account_edi_document.py | 14 +++++++++----- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/addons/account_edi/i18n/account_edi.pot b/addons/account_edi/i18n/account_edi.pot index b376c6ab2aa..12c267e8ee8 100644 --- a/addons/account_edi/i18n/account_edi.pot +++ b/addons/account_edi/i18n/account_edi.pot @@ -424,6 +424,12 @@ msgstr "" msgid "This code already exists" msgstr "" +#. module: account_edi +#: code:addons/account_edi/models/account_edi_document.py:0 +#, python-format +msgid "This document is being sent by another process already. " +msgstr "" + #. module: account_edi #: model:ir.model.fields.selection,name:account_edi.selection__account_edi_document__state__to_cancel #: model:ir.model.fields.selection,name:account_edi.selection__account_move__edi_state__to_cancel diff --git a/addons/account_edi/models/account_edi_document.py b/addons/account_edi/models/account_edi_document.py index 7dcf852f997..1db784e285d 100644 --- a/addons/account_edi/models/account_edi_document.py +++ b/addons/account_edi/models/account_edi_document.py @@ -1,7 +1,9 @@ # -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. -from odoo import models, fields, api +from odoo import models, fields, api, _ +from odoo.exceptions import UserError + from psycopg2 import OperationalError import base64 import logging @@ -234,15 +236,17 @@ class AccountEdiDocument(models.Model): if attachments_potential_unlink: self._cr.execute('SELECT * FROM ir_attachment WHERE id IN %s FOR UPDATE NOWAIT', [tuple(attachments_potential_unlink.ids)]) - self._process_job(documents, doc_type) except OperationalError as e: if e.pgcode == '55P03': _logger.debug('Another transaction already locked documents rows. Cannot process documents.') + if not with_commit: + raise UserError(_('This document is being sent by another process already. ')) + continue else: raise e - else: - if with_commit and len(jobs_to_process) > 1: - self.env.cr.commit() + self._process_job(documents, doc_type) + if with_commit and len(jobs_to_process) > 1: + self.env.cr.commit() return len(all_jobs) - len(jobs_to_process)