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)