diff --git a/jsonifier/README.rst b/jsonifier/README.rst index b5b971bfe24..60633f54567 100644 --- a/jsonifier/README.rst +++ b/jsonifier/README.rst @@ -263,12 +263,13 @@ Contributors - Iván Todorovich - Nguyen Minh Chien - Thien Vo +- Mangono team Other credits ------------- -The migration of this module from 17.0 to 18.0 was financially supported -by Camptocamp. +The migration of this module from 18.0 to 19.0 was financially supported +by Mangono. Maintainers ----------- diff --git a/jsonifier/__manifest__.py b/jsonifier/__manifest__.py index 69f296199d3..d6fccb8370f 100644 --- a/jsonifier/__manifest__.py +++ b/jsonifier/__manifest__.py @@ -18,9 +18,4 @@ "views/ir_exports_view.xml", "views/ir_exports_resolver_view.xml", ], - "demo": [ - "demo/resolver_demo.xml", - "demo/export_demo.xml", - "demo/ir.exports.line.csv", - ], } diff --git a/jsonifier/demo/export_demo.xml b/jsonifier/demo/export_demo.xml deleted file mode 100644 index a060d300266..00000000000 --- a/jsonifier/demo/export_demo.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - Partner Export - res.partner - - diff --git a/jsonifier/demo/ir.exports.line.csv b/jsonifier/demo/ir.exports.line.csv deleted file mode 100644 index 4744c11ea0c..00000000000 --- a/jsonifier/demo/ir.exports.line.csv +++ /dev/null @@ -1,16 +0,0 @@ -id,export_id/id,name -name,ir_exp_partner,name -active,ir_exp_partner,active -partner_latitude,ir_exp_partner,partner_latitude -color,ir_exp_partner,color -category_id_name,ir_exp_partner,category_id/name -country_id_name,ir_exp_partner,country_id/name -country_id_code,ir_exp_partner,country_id/code -child_ids_name,ir_exp_partner,child_ids/name -child_ids_id,ir_exp_partner,child_ids/id -child_ids_email,ir_exp_partner,child_ids/email -child_ids_country_id_name,ir_exp_partner,child_ids/country_id/name -child_ids_country_id_code,ir_exp_partner,child_ids/country_id/code -child_ids_child_ids_name,ir_exp_partner,child_ids/child_ids/name -lang,ir_exp_partner,lang -comment,ir_exp_partner,comment diff --git a/jsonifier/demo/resolver_demo.xml b/jsonifier/demo/resolver_demo.xml deleted file mode 100644 index 540302be23d..00000000000 --- a/jsonifier/demo/resolver_demo.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - ExtraData dictionary (number/text) - -is_number = field_type in ('integer', 'float') -ftype = "NUMBER" if is_number else "TEXT" -value = value if is_number else str(value) -result = {"Key": name, "Value": value, "Type": ftype, "IsPublic": True} - - - diff --git a/jsonifier/models/ir_exports_line.py b/jsonifier/models/ir_exports_line.py index b6dbf925683..049a0312175 100644 --- a/jsonifier/models/ir_exports_line.py +++ b/jsonifier/models/ir_exports_line.py @@ -52,7 +52,8 @@ def _check_target(self): raise ValidationError( self.env._( "The target must reference the same field as in " - "name '%(name)s' not in '%(name_with_target)s'" - ), - dict(name=name, name_with_target=name_with_target), + "name '%(name)s' not in '%(name_with_target)s'", + name=name, + name_with_target=name_with_target, + ) ) diff --git a/jsonifier/readme/CONTRIBUTORS.md b/jsonifier/readme/CONTRIBUTORS.md index 4323549dad8..953d2f19f2d 100644 --- a/jsonifier/readme/CONTRIBUTORS.md +++ b/jsonifier/readme/CONTRIBUTORS.md @@ -6,3 +6,4 @@ - Iván Todorovich \<\> - Nguyen Minh Chien \<\> - Thien Vo \<\> +- Mangono team \<\> diff --git a/jsonifier/readme/CREDITS.md b/jsonifier/readme/CREDITS.md index 83b3ec91f7d..514b5a21b3b 100644 --- a/jsonifier/readme/CREDITS.md +++ b/jsonifier/readme/CREDITS.md @@ -1 +1 @@ -The migration of this module from 17.0 to 18.0 was financially supported by Camptocamp. +The migration of this module from 18.0 to 19.0 was financially supported by Mangono. diff --git a/jsonifier/static/description/index.html b/jsonifier/static/description/index.html index ef88f8cf774..876c5f2324c 100644 --- a/jsonifier/static/description/index.html +++ b/jsonifier/static/description/index.html @@ -584,12 +584,13 @@

Contributors

  • Iván Todorovich <ivan.todorovich@camptocamp.com>
  • Nguyen Minh Chien <chien@trobz.com>
  • Thien Vo <thienvh@trobz.com>
  • +
  • Mangono team <opensource@mangono.fr>
  • Other credits

    -

    The migration of this module from 17.0 to 18.0 was financially supported -by Camptocamp.

    +

    The migration of this module from 18.0 to 19.0 was financially supported +by Mangono.

    Maintainers

    diff --git a/jsonifier/tests/__init__.py b/jsonifier/tests/__init__.py index 3402bb15298..abc56bc947c 100644 --- a/jsonifier/tests/__init__.py +++ b/jsonifier/tests/__init__.py @@ -1,3 +1,4 @@ +from . import test_data_setup from . import test_get_parser from . import test_helpers from . import test_ir_exports_line diff --git a/jsonifier/tests/test_data_setup.py b/jsonifier/tests/test_data_setup.py new file mode 100644 index 00000000000..ff0bb4fb328 --- /dev/null +++ b/jsonifier/tests/test_data_setup.py @@ -0,0 +1,60 @@ +class JsonifierTestDataMixin: + @classmethod + def _create_demo_export_class(cls): + cls.ir_exp_partner = cls.env["ir.exports"].create( + { + "name": "Partner Export", + "resource": "res.partner", + } + ) + return cls.ir_exp_partner + + @classmethod + def _create_demo_export_lines_class(cls): + export_lines_data = [ + {"name": "name"}, + {"name": "active"}, + {"name": "partner_latitude"}, + {"name": "color"}, + {"name": "category_id/name"}, + {"name": "country_id/name"}, + {"name": "country_id/code"}, + {"name": "child_ids/name"}, + {"name": "child_ids/id"}, + {"name": "child_ids/email"}, + {"name": "child_ids/country_id/name"}, + {"name": "child_ids/country_id/code"}, + {"name": "child_ids/child_ids/name"}, + {"name": "lang"}, + {"name": "comment"}, + ] + + export_lines = cls.env["ir.exports.line"] + + for line_data in export_lines_data: + line_data["export_id"] = cls.ir_exp_partner.id + line = cls.env["ir.exports.line"].create(line_data) + export_lines |= line + + return export_lines + + @classmethod + def _create_demo_resolver_class(cls): + python_code = """is_number = field_type in ('integer', 'float') +ftype = "NUMBER" if is_number else "TEXT" +value = value if is_number else str(value) +result = {"Key": name, "Value": value, "Type": ftype, "IsPublic": True}""" + + cls.ir_exports_resolver_dict = cls.env["ir.exports.resolver"].create( + { + "name": "ExtraData dictionary (number/text)", + "python_code": python_code, + } + ) + return cls.ir_exports_resolver_dict + + @classmethod + def setUpClass_demo_data(cls): + cls._create_demo_export_class() + cls._create_demo_export_lines_class() + cls._create_demo_resolver_class() diff --git a/jsonifier/tests/test_get_parser.py b/jsonifier/tests/test_get_parser.py index 0f587ec5a48..0d33dc3262a 100644 --- a/jsonifier/tests/test_get_parser.py +++ b/jsonifier/tests/test_get_parser.py @@ -9,16 +9,18 @@ from odoo.tests.common import TransactionCase from ..models.utils import convert_simple_to_full_parser +from .test_data_setup import JsonifierTestDataMixin def jsonify_custom(self, field_name): return "yeah!" -class TestParser(TransactionCase): +class TestParser(TransactionCase, JsonifierTestDataMixin): @classmethod def setUpClass(cls): super().setUpClass() + cls.setUpClass_demo_data() # disable tracking test suite wise cls.env = cls.env(context=dict(cls.env.context, tracking_disable=True)) cls.env.user.tz = "Europe/Brussels" @@ -104,16 +106,8 @@ def test_getting_parser(self): "comment", ] - exporter = self.env.ref("jsonifier.ir_exp_partner") - parser = exporter.get_json_parser() - expected_full_parser = convert_simple_to_full_parser(expected_parser) - self.assertEqual(parser, expected_full_parser) + exporter = self.ir_exp_partner - # modify an ir.exports_line to put a target for a field - self.env.ref("jsonifier.category_id_name").write( - {"target": "category_id:category/name"} - ) - expected_parser[4] = ("category_id:category", ["name"]) parser = exporter.get_json_parser() expected_full_parser = convert_simple_to_full_parser(expected_parser) self.assertEqual(parser, expected_full_parser) diff --git a/jsonifier/tests/test_helpers.py b/jsonifier/tests/test_helpers.py index 6c57a4a23aa..2c60b4db790 100644 --- a/jsonifier/tests/test_helpers.py +++ b/jsonifier/tests/test_helpers.py @@ -4,11 +4,14 @@ from odoo.tests.common import TransactionCase +from .test_data_setup import JsonifierTestDataMixin -class TestJsonifyHelpers(TransactionCase): + +class TestJsonifyHelpers(TransactionCase, JsonifierTestDataMixin): @classmethod def setUpClass(cls): super().setUpClass() + cls.setUpClass_demo_data() cls.env = cls.env(context=dict(cls.env.context, tracking_disable=True)) cls.partner = cls.env["res.partner"].create( { diff --git a/jsonifier/tests/test_ir_exports_line.py b/jsonifier/tests/test_ir_exports_line.py index c83e1f96592..fbf680a5022 100644 --- a/jsonifier/tests/test_ir_exports_line.py +++ b/jsonifier/tests/test_ir_exports_line.py @@ -4,12 +4,15 @@ from odoo.exceptions import ValidationError from odoo.tests.common import TransactionCase +from .test_data_setup import JsonifierTestDataMixin -class TestIrExportsLine(TransactionCase): + +class TestIrExportsLine(TransactionCase, JsonifierTestDataMixin): @classmethod def setUpClass(cls): super().setUpClass() - cls.ir_export = cls.env.ref("jsonifier.ir_exp_partner") + cls.env = cls.env(context=dict(cls.env.context, tracking_disable=True)) + cls.setUpClass_demo_data() def test_target_constrains(self): ir_export_lines_model = self.env["ir.exports.line"] @@ -17,7 +20,7 @@ def test_target_constrains(self): # The field into the name must be also into the target ir_export_lines_model.create( { - "export_id": self.ir_export.id, + "export_id": self.ir_exp_partner.id, "name": "name", "target": "toto:my_target", } @@ -27,7 +30,7 @@ def test_target_constrains(self): # the name ir_export_lines_model.create( { - "export_id": self.ir_export.id, + "export_id": self.ir_exp_partner.id, "name": "child_ids/child_ids/name", "target": "child_ids:children/name", } @@ -37,14 +40,14 @@ def test_target_constrains(self): # the name and must contains the same fields as into the name ir_export_lines_model.create( { - "export_id": self.ir_export.id, + "export_id": self.ir_exp_partner.id, "name": "child_ids/child_ids/name", "target": "child_ids:children/category_id:category/name", } ) line = ir_export_lines_model.create( { - "export_id": self.ir_export.id, + "export_id": self.ir_exp_partner.id, "name": "child_ids/child_ids/name", "target": "child_ids:children/child_ids:children/name", } @@ -60,7 +63,7 @@ def test_resolver_function_constrains(self): # the callable should be an existing model function, but it's not checked ir_export_lines_model.create( { - "export_id": self.ir_export.id, + "export_id": self.ir_exp_partner.id, "name": "name", "resolver_id": resolver.id, "instance_method_name": "function_name",