From e26ee0e44f11b2f5fdddee9990e1147f7c5cc1cc Mon Sep 17 00:00:00 2001 From: chaule97 Date: Fri, 19 Jul 2024 11:51:50 +0700 Subject: [PATCH] [ADD] edi_utm_oca --- edi_utm_oca/README.rst | 90 ++++ edi_utm_oca/__init__.py | 1 + edi_utm_oca/__manifest__.py | 20 + edi_utm_oca/data/utm_source.xml | 5 + edi_utm_oca/models/__init__.py | 1 + .../models/edi_exchange_consumer_mixin.py | 38 ++ edi_utm_oca/readme/CONTRIBUTORS.rst | 2 + edi_utm_oca/readme/DESCRIPTION.rst | 1 + edi_utm_oca/static/description/index.html | 432 ++++++++++++++++++ edi_utm_oca/tests/__init__.py | 1 + edi_utm_oca/tests/fake_models.py | 13 + edi_utm_oca/tests/test_edi_utm.py | 39 ++ setup/edi_utm_oca/odoo/addons/edi_utm_oca | 1 + setup/edi_utm_oca/setup.py | 6 + 14 files changed, 650 insertions(+) create mode 100644 edi_utm_oca/README.rst create mode 100644 edi_utm_oca/__init__.py create mode 100644 edi_utm_oca/__manifest__.py create mode 100644 edi_utm_oca/data/utm_source.xml create mode 100644 edi_utm_oca/models/__init__.py create mode 100644 edi_utm_oca/models/edi_exchange_consumer_mixin.py create mode 100644 edi_utm_oca/readme/CONTRIBUTORS.rst create mode 100644 edi_utm_oca/readme/DESCRIPTION.rst create mode 100644 edi_utm_oca/static/description/index.html create mode 100644 edi_utm_oca/tests/__init__.py create mode 100644 edi_utm_oca/tests/fake_models.py create mode 100644 edi_utm_oca/tests/test_edi_utm.py create mode 120000 setup/edi_utm_oca/odoo/addons/edi_utm_oca create mode 100644 setup/edi_utm_oca/setup.py diff --git a/edi_utm_oca/README.rst b/edi_utm_oca/README.rst new file mode 100644 index 000000000..473e09d2c --- /dev/null +++ b/edi_utm_oca/README.rst @@ -0,0 +1,90 @@ +======= +EDI UTM +======= + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:8906cc5516ab8b1df81638cd29e4e6f18d7ab2959e45af94db814aa964ec4c9d + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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_utm_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_utm_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 automatically assigns the EDI source to records created through the EDI mechanism. + +.. 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 +~~~~~~~~~~~~ + +* Simone Orsi +* Chau Le + +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-simahawk| image:: https://github.com/simahawk.png?size=40px + :target: https://github.com/simahawk + :alt: simahawk + +Current `maintainer `__: + +|maintainer-simahawk| + +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_utm_oca/__init__.py b/edi_utm_oca/__init__.py new file mode 100644 index 000000000..0650744f6 --- /dev/null +++ b/edi_utm_oca/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/edi_utm_oca/__manifest__.py b/edi_utm_oca/__manifest__.py new file mode 100644 index 000000000..3ff296e8e --- /dev/null +++ b/edi_utm_oca/__manifest__.py @@ -0,0 +1,20 @@ +# Copyright 2024 Camptocamp +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +{ + "name": "EDI UTM", + "summary": """ + Automatically assigns the EDI source to records created through the EDI mechanism. + """, + "version": "16.0.1.0.0", + "development_status": "Alpha", + "license": "AGPL-3", + "website": "https://github.com/OCA/edi-framework", + "author": "Camptocamp, Odoo Community Association (OCA)", + "maintainers": ["simahawk"], + "depends": ["utm", "edi_oca"], + "data": [ + "data/utm_source.xml", + ], + "installable": True, +} diff --git a/edi_utm_oca/data/utm_source.xml b/edi_utm_oca/data/utm_source.xml new file mode 100644 index 000000000..91c325a88 --- /dev/null +++ b/edi_utm_oca/data/utm_source.xml @@ -0,0 +1,5 @@ + + + EDI + + diff --git a/edi_utm_oca/models/__init__.py b/edi_utm_oca/models/__init__.py new file mode 100644 index 000000000..75d5b01df --- /dev/null +++ b/edi_utm_oca/models/__init__.py @@ -0,0 +1 @@ +from . import edi_exchange_consumer_mixin diff --git a/edi_utm_oca/models/edi_exchange_consumer_mixin.py b/edi_utm_oca/models/edi_exchange_consumer_mixin.py new file mode 100644 index 000000000..a76a92d68 --- /dev/null +++ b/edi_utm_oca/models/edi_exchange_consumer_mixin.py @@ -0,0 +1,38 @@ +# Copyright 2024 Camptocamp +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + + +from odoo import api, models + + +class EDIExchangeConsumerMixin(models.AbstractModel): + _inherit = "edi.exchange.consumer.mixin" + + def _edi_get_utm_source(self): + return self.env.ref( + "edi_utm_oca.utm_source_edi", + raise_if_not_found=False, + ) + + def _edi_update_source(self, vals): + """Set UTM source for records created via EDI.""" + + conditions = [ + "source_id" in self._fields, + vals.get("origin_exchange_record_id"), + "source_id" not in vals, + ] + + if all(conditions): + utm_source_edi = self._edi_get_utm_source() + + if utm_source_edi: + vals["source_id"] = utm_source_edi.id + + return vals + + @api.model_create_multi + def create(self, vals_list): + for vals in vals_list: + self._edi_update_source(vals) + return super().create(vals_list) diff --git a/edi_utm_oca/readme/CONTRIBUTORS.rst b/edi_utm_oca/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000..3f5ae78a6 --- /dev/null +++ b/edi_utm_oca/readme/CONTRIBUTORS.rst @@ -0,0 +1,2 @@ +* Simone Orsi +* Chau Le diff --git a/edi_utm_oca/readme/DESCRIPTION.rst b/edi_utm_oca/readme/DESCRIPTION.rst new file mode 100644 index 000000000..56b9c37a5 --- /dev/null +++ b/edi_utm_oca/readme/DESCRIPTION.rst @@ -0,0 +1 @@ +This module automatically assigns the EDI source to records created through the EDI mechanism. diff --git a/edi_utm_oca/static/description/index.html b/edi_utm_oca/static/description/index.html new file mode 100644 index 000000000..01b1d80df --- /dev/null +++ b/edi_utm_oca/static/description/index.html @@ -0,0 +1,432 @@ + + + + + +EDI UTM + + + +
+

EDI UTM

+ + +

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

+

This module automatically assigns the EDI source to records created through the EDI mechanism.

+
+

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.

+

Current maintainer:

+

simahawk

+

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_utm_oca/tests/__init__.py b/edi_utm_oca/tests/__init__.py new file mode 100644 index 000000000..88711aff6 --- /dev/null +++ b/edi_utm_oca/tests/__init__.py @@ -0,0 +1 @@ +from . import test_edi_utm diff --git a/edi_utm_oca/tests/fake_models.py b/edi_utm_oca/tests/fake_models.py new file mode 100644 index 000000000..e32d040ac --- /dev/null +++ b/edi_utm_oca/tests/fake_models.py @@ -0,0 +1,13 @@ +# Copyright 2024 Camptocamp +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import fields, models + + +class EDIUtmConsumerFake(models.Model): + _name = "edi.utm.consumer.fake" + _description = "Model used only for test" + _inherit = "edi.exchange.consumer.mixin" + + name = fields.Char() + source_id = fields.Many2one("utm.source", "Source", readonly=True) diff --git a/edi_utm_oca/tests/test_edi_utm.py b/edi_utm_oca/tests/test_edi_utm.py new file mode 100644 index 000000000..c625a175a --- /dev/null +++ b/edi_utm_oca/tests/test_edi_utm.py @@ -0,0 +1,39 @@ +# Copyright 2024 Camptocamp +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + + +from odoo_test_helper import FakeModelLoader + +from odoo.addons.edi_oca.tests.common import EDIBackendCommonTestCase + + +class TestEDIUtm(EDIBackendCommonTestCase): + @classmethod + def _setup_records(cls): # pylint: disable=missing-return + super()._setup_records() + cls.exchange_type_in.exchange_filename_pattern = "{record.id}-{type.code}-{dt}" + + # Load fake models ->/ + cls.loader = FakeModelLoader(cls.env, cls.__module__) + cls.loader.backup_registry() + from .fake_models import EDIUtmConsumerFake + + cls.loader.update_registry((EDIUtmConsumerFake,)) + cls.consumer_model = cls.env[EDIUtmConsumerFake._name] + + cls.exc_record_in = cls.backend.create_record( + cls.exchange_type_in.code, {"edi_exchange_state": "input_received"} + ) + + def test_edi_update_source(self): + consumer_record = self.consumer_model.create( + { + "name": "State Test Consumer", + "origin_exchange_record_id": self.exc_record_in.id, + } + ) + + self.assertEqual( + consumer_record.source_id, + self.env.ref("edi_utm_oca.utm_source_edi"), + ) diff --git a/setup/edi_utm_oca/odoo/addons/edi_utm_oca b/setup/edi_utm_oca/odoo/addons/edi_utm_oca new file mode 120000 index 000000000..b6934284a --- /dev/null +++ b/setup/edi_utm_oca/odoo/addons/edi_utm_oca @@ -0,0 +1 @@ +../../../../edi_utm_oca \ No newline at end of file diff --git a/setup/edi_utm_oca/setup.py b/setup/edi_utm_oca/setup.py new file mode 100644 index 000000000..28c57bb64 --- /dev/null +++ b/setup/edi_utm_oca/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)