From def8eb4b51a80587f2b4a17da82ceb3abb7f017c Mon Sep 17 00:00:00 2001 From: "Benjamin Frantzen (bfr)" Date: Thu, 3 Dec 2020 08:05:16 +0000 Subject: [IMP] account_edi: Better OCR management in tests When importing an xml in tests, if the import fails, the OCR will try to parse the file, which will cause an user access error. This polutes the logs and makes it hard to debug the code/test. With this commit a helper is added to create and invoice with OCR deactivated to be used to import the file. closes odoo/odoo#62730 Related: odoo/enterprise#15124 Signed-off-by: Laurent Smet --- addons/account_edi/tests/common.py | 11 ++++++++++- addons/account_edi_facturx/tests/test_facturx.py | 4 ++-- addons/l10n_be_edi/tests/test_ubl.py | 2 +- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/addons/account_edi/tests/common.py b/addons/account_edi/tests/common.py index eb01e22da99..0a560c1bb81 100644 --- a/addons/account_edi/tests/common.py +++ b/addons/account_edi/tests/common.py @@ -34,6 +34,15 @@ class AccountEdiTestCommon(AccountTestInvoicingCommon): def edi_cron(self): self.env['account.edi.document'].sudo().with_context(edi_test_mode=True).search([('state', 'in', ('to_send', 'to_cancel'))])._process_documents_web_services() + def _create_empty_vendor_bill(self): + invoice = self.env['account.move'].create({ + 'move_type': 'in_invoice', + 'journal_id': self.company_data['default_journal_purchase'].id, + }) + if 'extract_state' in invoice._fields: + invoice.extract_state = 'done' # prevent ocr + return invoice + def update_invoice_from_file(self, module_name, subfolder, filename, invoice): file_path = get_module_resource(module_name, subfolder, filename) file = open(file_path, 'rb').read() @@ -58,7 +67,7 @@ class AccountEdiTestCommon(AccountTestInvoicingCommon): }) journal_id = self.company_data['default_journal_sale'] - invoice = journal_id.with_context(default_move_type='in_invoice')._create_invoice_from_single_attachment(attachment) + journal_id.with_context(default_move_type='in_invoice')._create_invoice_from_single_attachment(attachment) def assert_generated_file_equal(self, invoice, expected_values, applied_xpath=None): invoice.action_post() diff --git a/addons/account_edi_facturx/tests/test_facturx.py b/addons/account_edi_facturx/tests/test_facturx.py index f36382f121f..b1f556adceb 100644 --- a/addons/account_edi_facturx/tests/test_facturx.py +++ b/addons/account_edi_facturx/tests/test_facturx.py @@ -214,7 +214,7 @@ class TestAccountEdiFacturx(AccountEdiTestCommon): #################################################### def test_invoice_edi_pdf(self): - invoice = self.env['account.move'].with_context(default_move_type='in_invoice').create({}) + invoice = self._create_empty_vendor_bill() invoice_count = len(self.env['account.move'].search([])) self.update_invoice_from_file('account_edi_facturx', 'test_file', 'test_facturx.pdf', invoice) @@ -227,7 +227,7 @@ class TestAccountEdiFacturx(AccountEdiTestCommon): self.assertEqual(len(self.env['account.move'].search([])), invoice_count + 1) def test_invoice_edi_xml(self): - invoice = self.env['account.move'].with_context(default_move_type='in_invoice').create({}) + invoice = self._create_empty_vendor_bill() invoice_count = len(self.env['account.move'].search([])) self.update_invoice_from_file('account_edi_facturx', 'test_file', 'test_facturx.xml', invoice) diff --git a/addons/l10n_be_edi/tests/test_ubl.py b/addons/l10n_be_edi/tests/test_ubl.py index ae99c754c6d..388155ac21c 100644 --- a/addons/l10n_be_edi/tests/test_ubl.py +++ b/addons/l10n_be_edi/tests/test_ubl.py @@ -10,7 +10,7 @@ class TestUBL(AccountEdiTestCommon): cls.partner_a.vat = 'BE0123456789' def test_invoice_edi_xml(self): - invoice = self.env['account.move'].with_context(default_move_type='in_invoice').create({}) + invoice = self._create_empty_vendor_bill() invoice_count = len(self.env['account.move'].search([])) self.update_invoice_from_file('l10n_be_edi', 'test_xml_file', 'efff_test.xml', invoice) -- cgit v1.2.3