[FIX] account_edi: avoid savepoint error and inform the user correctly

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) <wan@odoo.com>
This commit is contained in:
Josse Colpaert
2022-03-12 10:57:13 +00:00
committed by william
parent 4525d65ad7
commit dbaaf59f74
2 changed files with 15 additions and 5 deletions
+6
View File
@@ -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
@@ -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)