From fa9db1a6a46366481e6d088f72131a5c4e30ed64 Mon Sep 17 00:00:00 2001 From: duongtq Date: Tue, 10 Oct 2023 16:27:07 +0700 Subject: [PATCH] [ADD] edi_sale_edifact_oca --- edi_sale_edifact_oca/README.rst | 83 ++++ edi_sale_edifact_oca/__init__.py | 0 edi_sale_edifact_oca/__manifest__.py | 23 + .../demo/edi_exchange_type.xml | 24 + edi_sale_edifact_oca/readme/CONTRIBUTORS.rst | 2 + edi_sale_edifact_oca/readme/DESCRIPTION.rst | 2 + .../static/description/index.html | 429 ++++++++++++++++++ edi_sale_edifact_oca/tests/__init__.py | 1 + edi_sale_edifact_oca/tests/common.py | 23 + edi_sale_edifact_oca/tests/test_order.py | 75 +++ .../odoo/addons/edi_sale_edifact_oca | 1 + setup/edi_sale_edifact_oca/setup.py | 6 + 12 files changed, 669 insertions(+) create mode 100644 edi_sale_edifact_oca/README.rst create mode 100644 edi_sale_edifact_oca/__init__.py create mode 100644 edi_sale_edifact_oca/__manifest__.py create mode 100644 edi_sale_edifact_oca/demo/edi_exchange_type.xml create mode 100644 edi_sale_edifact_oca/readme/CONTRIBUTORS.rst create mode 100644 edi_sale_edifact_oca/readme/DESCRIPTION.rst create mode 100644 edi_sale_edifact_oca/static/description/index.html create mode 100644 edi_sale_edifact_oca/tests/__init__.py create mode 100644 edi_sale_edifact_oca/tests/common.py create mode 100644 edi_sale_edifact_oca/tests/test_order.py create mode 120000 setup/edi_sale_edifact_oca/odoo/addons/edi_sale_edifact_oca create mode 100644 setup/edi_sale_edifact_oca/setup.py diff --git a/edi_sale_edifact_oca/README.rst b/edi_sale_edifact_oca/README.rst new file mode 100644 index 000000000..6911ec475 --- /dev/null +++ b/edi_sale_edifact_oca/README.rst @@ -0,0 +1,83 @@ +================= +EDI Sales EDIFACT +================= + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:3682f5bd844859e51719ea849a8334a9b34c7196c689abd3f55d15395de59470 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Alpha-red.png + :target: https://odoo-community.org/page/development-status + :alt: Alpha +.. |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--framework-lightgray.png?logo=github + :target: https://github.com/OCA/edi-framework/tree/16.0/edi_sale_edifact_oca + :alt: OCA/edi-framework +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/edi-framework-16-0/edi-framework-16-0-edi_sale_edifact_oca + :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-framework&target_branch=16.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module provides an example on how to configure and exchange type for EDIFACT standard, +as well as some test coverage for importing orders with the same standard. + +.. IMPORTANT:: + This is an alpha version, the data model and design can change at any time without warning. + Only for development or testing purpose, do not use in production. + `More details on development status `_ + +**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 +~~~~~~~ + +* Camptocamp + +Contributors +~~~~~~~~~~~~ + +* Duong (Tran Quoc) +* Simone Orsi + +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. + +This module is part of the `OCA/edi-framework `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/edi_sale_edifact_oca/__init__.py b/edi_sale_edifact_oca/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/edi_sale_edifact_oca/__manifest__.py b/edi_sale_edifact_oca/__manifest__.py new file mode 100644 index 000000000..9fe342a3a --- /dev/null +++ b/edi_sale_edifact_oca/__manifest__.py @@ -0,0 +1,23 @@ +# Copyright 2023 Camptocamp SA +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +{ + "name": "EDI Sales EDIFACT", + "summary": """ + Provide a demo exchange type setting and common tests for EDIFACT standard + in EDI on sales. + """, + "version": "16.0.1.0.0", + "development_status": "Alpha", + "license": "AGPL-3", + "author": "Camptocamp,Odoo Community Association (OCA)", + "website": "https://github.com/OCA/edi-framework", + "depends": [ + "sale_order_import_edifact", + "edi_sale_oca", + "edi_edifact_oca", + "sale_stock", + ], + "demo": [ + "demo/edi_exchange_type.xml", + ], +} diff --git a/edi_sale_edifact_oca/demo/edi_exchange_type.xml b/edi_sale_edifact_oca/demo/edi_exchange_type.xml new file mode 100644 index 000000000..34d892ba6 --- /dev/null +++ b/edi_sale_edifact_oca/demo/edi_exchange_type.xml @@ -0,0 +1,24 @@ + + + + + + Demo EDIFACT Sale Order + demo_EDIFACT_SaleOrder_in + input + txt + + components: + process: + usage: input.process.sale.order + env_ctx: + # Values for the wizard + default_file_ext: 'edi' + defaut_release: 'd96a' + default_doc_type: 'rfq' + default_confirm_order: false + default_price_source: 'order' + default_import_type: 'edifact' + + + diff --git a/edi_sale_edifact_oca/readme/CONTRIBUTORS.rst b/edi_sale_edifact_oca/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000..b1f5c7f98 --- /dev/null +++ b/edi_sale_edifact_oca/readme/CONTRIBUTORS.rst @@ -0,0 +1,2 @@ +* Duong (Tran Quoc) +* Simone Orsi diff --git a/edi_sale_edifact_oca/readme/DESCRIPTION.rst b/edi_sale_edifact_oca/readme/DESCRIPTION.rst new file mode 100644 index 000000000..254d9d778 --- /dev/null +++ b/edi_sale_edifact_oca/readme/DESCRIPTION.rst @@ -0,0 +1,2 @@ +This module provides an example on how to configure and exchange type for EDIFACT standard, +as well as some test coverage for importing orders with the same standard. diff --git a/edi_sale_edifact_oca/static/description/index.html b/edi_sale_edifact_oca/static/description/index.html new file mode 100644 index 000000000..a3be0b3d2 --- /dev/null +++ b/edi_sale_edifact_oca/static/description/index.html @@ -0,0 +1,429 @@ + + + + + + +EDI Sales EDIFACT + + + +
+

EDI Sales EDIFACT

+ + +

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

+

This module provides an example on how to configure and exchange type for EDIFACT standard, +as well as some test coverage for importing orders with the same standard.

+
+

Important

+

This is an alpha version, the data model and design can change at any time without warning. +Only for development or testing purpose, do not use in production. +More details on development status

+
+

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

+
    +
  • Camptocamp
  • +
+
+
+

Contributors

+ +
+
+

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.

+

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

+

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

+
+
+
+ + diff --git a/edi_sale_edifact_oca/tests/__init__.py b/edi_sale_edifact_oca/tests/__init__.py new file mode 100644 index 000000000..e6fb64b6b --- /dev/null +++ b/edi_sale_edifact_oca/tests/__init__.py @@ -0,0 +1 @@ +from . import test_order diff --git a/edi_sale_edifact_oca/tests/common.py b/edi_sale_edifact_oca/tests/common.py new file mode 100644 index 000000000..a75838e29 --- /dev/null +++ b/edi_sale_edifact_oca/tests/common.py @@ -0,0 +1,23 @@ +# Copyright 2023 Camptocamp SA +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + + +from odoo.addons.sale_order_import_edifact.tests.common import get_test_data + + +class OrderInboundTestMixin: + @classmethod + def _setup_inbound_order(cls, backend): + cls.exc_type_in = cls.env.ref( + "edi_sale_edifact_oca.demo_edi_exc_type_edifact_order_in" + ) + cls.exc_type_in.backend_id = backend + cls.exc_record_in = backend.create_record( + cls.exc_type_in.code, {"edi_exchange_state": "input_received"} + ) + cls.edifact_data = get_test_data(cls.env) + fname = "Retail_EDIFACT_ORDERS_sample1.txt" + cls.order_data = cls.edifact_data[fname] + fcontent = cls.order_data._get_content() + cls.exc_record_in._set_file_content(fcontent) + cls.err_msg_already_imported = "Sales order has already been imported before" diff --git a/edi_sale_edifact_oca/tests/test_order.py b/edi_sale_edifact_oca/tests/test_order.py new file mode 100644 index 000000000..69404d49c --- /dev/null +++ b/edi_sale_edifact_oca/tests/test_order.py @@ -0,0 +1,75 @@ +# Copyright 2023 Camptocamp SA +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import exceptions + +from odoo.addons.edi_oca.tests.common import EDIBackendCommonComponentRegistryTestCase + +from .common import OrderInboundTestMixin + + +class TestOrderInbound( + EDIBackendCommonComponentRegistryTestCase, OrderInboundTestMixin +): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.backend = cls._get_backend() + cls._setup_inbound_order(cls.backend) + + @classmethod + def _get_backend(cls): + return cls.env.ref("edi_edifact_oca.edi_backend_edifact_demo") + + def test_new_order(self): + self.exc_record_in.action_exchange_process() + self.assertEqual(self.exc_record_in.edi_exchange_state, "input_processed") + order = self.exc_record_in.record + self.assertEqual(order.partner_id, self.order_data["partner"]) + self.assertEqual(order.client_order_ref, self.order_data["client_order_ref"]) + self.assertEqual(order.partner_shipping_id, self.order_data["shipping_partner"]) + + order_msg = order.message_ids[0] + self.assertIn("Exchange processed successfully", order_msg.body) + self.assertIn(self.exc_record_in.identifier, order_msg.body) + order.env.invalidate_all() + # Test relations + self.assertEqual(len(order.exchange_record_ids), 1) + exc_record = order.exchange_record_ids.filtered( + lambda x: x.type_id == self.exc_type_in + ) + self.assertEqual(exc_record, self.exc_record_in) + + def test_existing_order_break_on_error(self): + self.assertEqual(self.exc_record_in.edi_exchange_state, "input_received") + self.env["sale.order"].create( + { + "partner_id": self.env.ref( + "sale_order_import_edifact.partner_edi_dm" + ).id, + "client_order_ref": self.order_data["client_order_ref"], + } + ) + with self.assertRaisesRegex( + exceptions.UserError, self.err_msg_already_imported + ): + self.exc_record_in.with_context( + _edi_process_break_on_error=True + ).action_exchange_process() + self.assertEqual(self.exc_record_in.edi_exchange_state, "input_received") + + def test_existing_order(self): + self.assertEqual(self.exc_record_in.edi_exchange_state, "input_received") + self.env["sale.order"].create( + { + "partner_id": self.env.ref( + "sale_order_import_edifact.partner_edi_dm" + ).id, + "client_order_ref": self.order_data["client_order_ref"], + } + ) + # Test w/ error handling + self.exc_record_in.action_exchange_process() + self.assertEqual(self.exc_record_in.edi_exchange_state, "input_processed_error") + err_msg = "Sales order has already been imported before" + self.assertEqual(self.exc_record_in.exchange_error, err_msg) diff --git a/setup/edi_sale_edifact_oca/odoo/addons/edi_sale_edifact_oca b/setup/edi_sale_edifact_oca/odoo/addons/edi_sale_edifact_oca new file mode 120000 index 000000000..e54df8d05 --- /dev/null +++ b/setup/edi_sale_edifact_oca/odoo/addons/edi_sale_edifact_oca @@ -0,0 +1 @@ +../../../../edi_sale_edifact_oca \ No newline at end of file diff --git a/setup/edi_sale_edifact_oca/setup.py b/setup/edi_sale_edifact_oca/setup.py new file mode 100644 index 000000000..28c57bb64 --- /dev/null +++ b/setup/edi_sale_edifact_oca/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)