diff --git a/setup/test_base_import_pdf_simple/odoo/addons/test_base_import_pdf_simple b/setup/test_base_import_pdf_simple/odoo/addons/test_base_import_pdf_simple new file mode 120000 index 00000000000..e38e794a437 --- /dev/null +++ b/setup/test_base_import_pdf_simple/odoo/addons/test_base_import_pdf_simple @@ -0,0 +1 @@ +../../../../test_base_import_pdf_simple \ No newline at end of file diff --git a/setup/test_base_import_pdf_simple/setup.py b/setup/test_base_import_pdf_simple/setup.py new file mode 100644 index 00000000000..28c57bb6403 --- /dev/null +++ b/setup/test_base_import_pdf_simple/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +) diff --git a/test_base_import_pdf_simple/README.rst b/test_base_import_pdf_simple/README.rst new file mode 100644 index 00000000000..cf22570ec8f --- /dev/null +++ b/test_base_import_pdf_simple/README.rst @@ -0,0 +1,87 @@ +=========================== +Test Base Import Pdf Simple +=========================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:d1fd050f741ace1e34d8aa94bc309bc8c6e1522ce0a3f872a1cc382a71418dd6 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fedi-lightgray.png?logo=github + :target: https://github.com/OCA/edi/tree/15.0/test_base_import_pdf_simple + :alt: OCA/edi +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/edi-15-0/edi-15-0-test_base_import_pdf_simple + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png + :target: https://runboat.odoo-community.org/builds?repo=OCA/edi&target_branch=15.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +Test suite for base_import_pdf_simple. Normally you don't need to install this. + +**Table of contents** + +.. contents:: + :local: + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues `_. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us to smash it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* Tecnativa + +Contributors +~~~~~~~~~~~~ + +* `Tecnativa `_: + + * Víctor Martínez + * Pedro M. Baeza + +Maintainers +~~~~~~~~~~~ + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +.. |maintainer-victoralmau| image:: https://github.com/victoralmau.png?size=40px + :target: https://github.com/victoralmau + :alt: victoralmau + +Current `maintainer `__: + +|maintainer-victoralmau| + +This module is part of the `OCA/edi `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/test_base_import_pdf_simple/__init__.py b/test_base_import_pdf_simple/__init__.py new file mode 100644 index 00000000000..e315f7b241f --- /dev/null +++ b/test_base_import_pdf_simple/__init__.py @@ -0,0 +1 @@ +from .hooks import post_init_hook diff --git a/test_base_import_pdf_simple/__manifest__.py b/test_base_import_pdf_simple/__manifest__.py new file mode 100644 index 00000000000..23946c93796 --- /dev/null +++ b/test_base_import_pdf_simple/__manifest__.py @@ -0,0 +1,16 @@ +# Copyright 2024 Tecnativa - Víctor Martínez +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +{ + "name": "Test Base Import Pdf Simple", + "version": "15.0.1.0.0", + "website": "https://github.com/OCA/edi", + "author": "Tecnativa, Odoo Community Association (OCA)", + "license": "AGPL-3", + "depends": ["purchase", "base_import_pdf_simple"], + "installable": True, + "demo": [ + "demo/base_import_pdf_template.xml", + ], + "maintainers": ["victoralmau"], + "post_init_hook": "post_init_hook", +} diff --git a/test_base_import_pdf_simple/demo/base_import_pdf_template.xml b/test_base_import_pdf_simple/demo/base_import_pdf_template.xml new file mode 100644 index 00000000000..4591cd6685b --- /dev/null +++ b/test_base_import_pdf_simple/demo/base_import_pdf_template.xml @@ -0,0 +1,252 @@ + + + + Decathlon + + + Test Generic Product + GENERIC + + + + + 4449130 + + + Test Mochila + MOCHILA + + + + + + 5284409 + + + Test Aislante + AISLANTE + + + + + + 4225123 + + + Test Hamaca + HAMACA + + + + + + 4006580 + + + Test Botiquin + BOTIQUIN + + + + + + Purchase Orders Decathlon + + + + Referencia,Cantidad,Precio + + + + header + + fixed + + + + + header + + ES[0-9]{10} + variable + + + + lines + + 0 + ([0-9]{7}) [0-7]{1} + variable + + + + + + + lines + + 1 + [0-9]{7} ([0-7]{1}) + variable + + + + lines + + 2 + [0-9]{7} [0-9]{1} ([0-9]{2}.[0-9]{2}) + variable + + + + + Tecnativa + + + + CONS_0001 + + + Test Rotulador + ROTULADOR + + + + + + CONS_0002 + + + Test Boligrafo + BOLIGRAFO + + + + + + FURN_0003 + + + Test Leds + LEDS + + + + + + E-COM10 + + + Test Plastificadora + PLASTIFICADORA + + + + + + FURN_8621 + + + Test Lmaninas + LAMINAS + + + + + + FURN_7023 + + + Test Trituradora + TRITURADORA + + + + + Invoices Tecnativa + + + + Producto,Cantidad,Precio + + + + header + + fixed + + + + + lines + + 0 + \[([A-Z\d]+[_|-][A-Z\d]+)\] + variable + + + + + + + lines + + 1 + (^\d{1,3}\n)[0-9]{1,2} + variable + + + + lines + + 2 + (^\d{1,3}\.(?!00)\d{2}\n) + variable + + + diff --git a/test_base_import_pdf_simple/hooks.py b/test_base_import_pdf_simple/hooks.py new file mode 100644 index 00000000000..421e7c624e2 --- /dev/null +++ b/test_base_import_pdf_simple/hooks.py @@ -0,0 +1,36 @@ +# Copyright 2024 Tecnativa - Víctor Martínez +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import SUPERUSER_ID, api + + +def post_init_hook(cr, registry): + env = api.Environment(cr, SUPERUSER_ID, {}) + # Template changes + generic_product = env.ref("test_base_import_pdf_simple.generic_product") + template_po_decathlon = env.ref("test_base_import_pdf_simple.po_decathlon") + template_po_decathlon.write({"auto_detect_pattern": r"(?<=ESA79935607)[\S\s]*"}) + env.ref("test_base_import_pdf_simple.po_decathlon_line_product_id").write( + { + "default_value": "%s,%s" + % ( + "product.product", + generic_product.id, + ) + } + ) + template_invoice_tecnativa = env.ref( + "test_base_import_pdf_simple.invoice_tecnativa" + ) + template_invoice_tecnativa.write( + {"auto_detect_pattern": r"(?<=B 8 7 5 3 0 4 3 2)[\S\s]*"} + ) + env.ref("test_base_import_pdf_simple.invoice_tecnativa_line_product_id").write( + { + "default_value": "%s,%s" + % ( + "product.product", + generic_product.id, + ) + } + ) diff --git a/test_base_import_pdf_simple/readme/CONTRIBUTORS.rst b/test_base_import_pdf_simple/readme/CONTRIBUTORS.rst new file mode 100644 index 00000000000..5fb71305308 --- /dev/null +++ b/test_base_import_pdf_simple/readme/CONTRIBUTORS.rst @@ -0,0 +1,4 @@ +* `Tecnativa `_: + + * Víctor Martínez + * Pedro M. Baeza diff --git a/test_base_import_pdf_simple/readme/DESCRIPTION.rst b/test_base_import_pdf_simple/readme/DESCRIPTION.rst new file mode 100644 index 00000000000..95a51a0cc20 --- /dev/null +++ b/test_base_import_pdf_simple/readme/DESCRIPTION.rst @@ -0,0 +1 @@ +Test suite for base_import_pdf_simple. Normally you don't need to install this. diff --git a/test_base_import_pdf_simple/static/description/icon.png b/test_base_import_pdf_simple/static/description/icon.png new file mode 100644 index 00000000000..3a0328b516c Binary files /dev/null and b/test_base_import_pdf_simple/static/description/icon.png differ diff --git a/test_base_import_pdf_simple/static/description/index.html b/test_base_import_pdf_simple/static/description/index.html new file mode 100644 index 00000000000..e487172467d --- /dev/null +++ b/test_base_import_pdf_simple/static/description/index.html @@ -0,0 +1,427 @@ + + + + + + +Test Base Import Pdf Simple + + + +
+

Test Base Import Pdf Simple

+ + +

Beta License: AGPL-3 OCA/edi Translate me on Weblate Try me on Runboat

+

Test suite for base_import_pdf_simple. Normally you don’t need to install this.

+

Table of contents

+ +
+

Bug Tracker

+

Bugs are tracked on GitHub Issues. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us to smash it by providing a detailed and welcomed +feedback.

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • Tecnativa
  • +
+
+
+

Contributors

+
    +
  • Tecnativa:
      +
    • Víctor Martínez
    • +
    • Pedro M. Baeza
    • +
    +
  • +
+
+
+

Maintainers

+

This module is maintained by the OCA.

+Odoo Community Association +

OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use.

+

Current maintainer:

+

victoralmau

+

This module is part of the OCA/edi project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/test_base_import_pdf_simple/tests/__init__.py b/test_base_import_pdf_simple/tests/__init__.py new file mode 100644 index 00000000000..5a22ac824b3 --- /dev/null +++ b/test_base_import_pdf_simple/tests/__init__.py @@ -0,0 +1 @@ +from . import test_base_import_pdf_simple diff --git a/test_base_import_pdf_simple/tests/data/account_invoice_tecnativa.pdf b/test_base_import_pdf_simple/tests/data/account_invoice_tecnativa.pdf new file mode 100644 index 00000000000..4b34f8420bb Binary files /dev/null and b/test_base_import_pdf_simple/tests/data/account_invoice_tecnativa.pdf differ diff --git a/test_base_import_pdf_simple/tests/data/purchase_order_declathon.pdf b/test_base_import_pdf_simple/tests/data/purchase_order_declathon.pdf new file mode 100644 index 00000000000..c80d82ed6f2 Binary files /dev/null and b/test_base_import_pdf_simple/tests/data/purchase_order_declathon.pdf differ diff --git a/test_base_import_pdf_simple/tests/test_base_import_pdf_simple.py b/test_base_import_pdf_simple/tests/test_base_import_pdf_simple.py new file mode 100644 index 00000000000..124c4022e58 --- /dev/null +++ b/test_base_import_pdf_simple/tests/test_base_import_pdf_simple.py @@ -0,0 +1,108 @@ +# Copyright 2024 Tecnativa - Víctor Martínez +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from base64 import b64encode +from os import path + +from odoo.tests import common + + +class TestBaseImportPdfSimple(common.TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.env = cls.env( + context=dict( + cls.env.context, + mail_create_nolog=True, + mail_create_nosubscribe=True, + mail_notrack=True, + no_reset_password=True, + tracking_disable=True, + ) + ) + cls.partner_decathlon = cls.env.ref( + "test_base_import_pdf_simple.partner_decathlon" + ) + cls.template_po_decathlon = cls.env.ref( + "test_base_import_pdf_simple.po_decathlon" + ) + cls.partner_tecnativa = cls.env.ref( + "test_base_import_pdf_simple.partner_tecnativa" + ) + cls.template_invoice_tecnativa = cls.env.ref( + "test_base_import_pdf_simple.invoice_tecnativa" + ) + + def _data_file(self, filename, encoding=None): + filename = "data/" + filename + mode = "rt" if encoding else "rb" + with open(path.join(path.dirname(__file__), filename), mode) as file: + data = file.read() + return b64encode(data) + + def _create_ir_attachment(self, filename): + return self.env["ir.attachment"].create( + { + "name": filename, + "datas": self._data_file(filename), + } + ) + + def _create_wizard_base_import_pdf_upload(self, model, attachment): + wizard = self.env["wizard.base.import.pdf.upload"].create( + { + "model": model, + "attachment_ids": attachment.ids, + } + ) + return wizard + + def _get_attachments(self, record): + return self.env["ir.attachment"].search( + [("res_model", "=", record._name), ("res_id", "=", record.id)] + ) + + def test_purchase_order_decathlon(self): + attachment = self._create_ir_attachment("purchase_order_declathon.pdf") + wizard = self._create_wizard_base_import_pdf_upload( + "purchase.order", attachment + ) + res = wizard.action_process() + self.assertEqual(res["res_model"], "purchase.order") + record = self.env[res["res_model"]].browse(res["res_id"]) + attachments = self._get_attachments(record) + self.assertEqual(record.partner_id, self.partner_decathlon) + self.assertEqual(record.partner_ref, "ES9812110233") + self.assertIn(attachment, attachments) + self.assertEqual(len(record.order_line), 5) + self.assertEqual(sum(record.order_line.mapped("product_uom_qty")), 5) + default_codes = record.order_line.mapped("product_id.default_code") + self.assertIn("MOCHILA", default_codes) + self.assertIn("AISLANTE", default_codes) + self.assertIn("HAMACA", default_codes) + self.assertIn("BOTIQUIN", default_codes) + self.assertIn("GENERIC", default_codes) + self.assertIn("66.11", record.message_ids.body) + + def test_account_invoice_tecnativa(self): + attachment = self._create_ir_attachment("account_invoice_tecnativa.pdf") + wizard = self._create_wizard_base_import_pdf_upload("account.move", attachment) + # Similar context from Vendor invoices menu + wizard = wizard.with_context(**{"default_move_type": "in_invoice"}) + res = wizard.action_process() + self.assertEqual(res["res_model"], "account.move") + record = self.env[res["res_model"]].browse(res["res_id"]) + attachments = self._get_attachments(record) + self.assertEqual(record.partner_id, self.partner_tecnativa) + self.assertIn(attachment, attachments) + self.assertEqual(len(record.invoice_line_ids), 6) + self.assertEqual(sum(record.invoice_line_ids.mapped("quantity")), 665) + default_codes = record.invoice_line_ids.mapped("product_id.default_code") + self.assertIn("ROTULADOR", default_codes) + self.assertIn("BOLIGRAFO", default_codes) + self.assertIn("LEDS", default_codes) + self.assertIn("PLASTIFICADORA", default_codes) + self.assertIn("LAMINAS", default_codes) + self.assertIn("TRITURADORA", default_codes) + self.assertIn("100.25", record.message_ids.body)