[FIX] account_edi: edi.document are re-send if they are in error

Before the introduction of account_edi_extended and blocking_level, if an edi.document was in error, it was retried each the time the edi.documents were processed. With account_edi_extended a bug was introduced and only the document not in error were processed. This commit aims to restore the previous behavior.

Also fixes tests of account_edi.

See https://github.com/odoo/odoo/commit/a9a46cf09b0c841c7fda95b5ed03033fc6936ca2

X-original-commit: 385fa29322f6dffc7d7d0de96a1cfbddb0cab7f0
This commit is contained in:
Benjamin Frantzen (bfr)
2021-02-08 12:20:37 +00:00
parent b51a08a6e1
commit 7785fcb819
3 changed files with 12 additions and 4 deletions
@@ -236,8 +236,6 @@ class AccountMove(models.Model):
docs = self.edi_document_ids.filtered(lambda d: d.state in ('to_send', 'to_cancel'))
if 'blocking_level' in self.env['account.edi.document']._fields:
docs = docs.filtered(lambda d: d.blocking_level != 'error')
else:
docs = docs.filtered(lambda d: not d.error)
docs._process_documents_web_services(with_commit=False)
class AccountMoveLine(models.Model):
+1 -1
View File
@@ -90,7 +90,7 @@ class AccountEdiTestCommon(AccountTestInvoicingCommon):
:param move: The move of the document or None to create a new one.
:param move_type: If move is None, the type of the invoice to create, defaults to 'out_invoice'.
"""
move = move or self.init_invoice(move_type or 'out_invoice')
move = move or self.init_invoice(move_type or 'out_invoice', products=self.product_a)
return self.env['account.edi.document'].create({
'edi_format_id': edi_format.id,
'move_id': move.id,
+11 -1
View File
@@ -8,7 +8,7 @@ from unittest.mock import patch
class TestAccountEdi(AccountEdiTestCommon):
def test_export_edi(self):
invoice = self.init_invoice('out_invoice')
invoice = self.init_invoice('out_invoice', products=self.product_a)
self.assertEqual(len(invoice.edi_document_ids), 0)
invoice.action_post()
self.assertEqual(len(invoice.edi_document_ids), 1)
@@ -37,3 +37,13 @@ class TestAccountEdi(AccountEdiTestCommon):
with patch('odoo.addons.account_edi.models.account_edi_format.AccountEdiFormat._support_batching', return_value=True):
to_process = edi_docs._prepare_jobs()
self.assertEqual(len(to_process), 2)
@patch('odoo.addons.account_edi.models.account_edi_format.AccountEdiFormat._post_invoice_edi')
def test_error(self, patched):
with patch('odoo.addons.account_edi.models.account_edi_format.AccountEdiFormat._needs_web_services',
new=lambda edi_format: True):
edi_docs = self.create_edi_document(self.edi_format, 'to_send')
edi_docs.error = 'Test Error'
edi_docs.move_id.action_process_edi_web_services()
patched.assert_called_once()