Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions jsonifier/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -263,12 +263,13 @@ Contributors
- Iván Todorovich <[email protected]>
- Nguyen Minh Chien <[email protected]>
- Thien Vo <[email protected]>
- Mangono team <[email protected]>

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
-----------
Expand Down
5 changes: 0 additions & 5 deletions jsonifier/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Comment on lines -21 to -24

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Medium · Demo installs lose sample exports

When a user installs the module with demo data enabled, the manifest no longer loads the sample export, resolver, or CSV records, so demo-enabled installations have no packaged example configuration for users exploring the module.

Retain the packaged examples as demo data while keeping unit tests independent by creating their own fixtures.

Prompt for AI agents
In `jsonifier/__manifest__.py` at lines 21-24:

**Demo installs lose sample exports**

When a user installs the module with demo data enabled, the manifest no longer loads the sample export, resolver, or CSV records, so demo-enabled installations have no packaged example configuration for users exploring the module.

Retain the packaged examples as demo data while keeping unit tests independent by creating their own fixtures.

],
}
7 changes: 0 additions & 7 deletions jsonifier/demo/export_demo.xml

This file was deleted.

16 changes: 0 additions & 16 deletions jsonifier/demo/ir.exports.line.csv

This file was deleted.

12 changes: 0 additions & 12 deletions jsonifier/demo/resolver_demo.xml

This file was deleted.

7 changes: 4 additions & 3 deletions jsonifier/models/ir_exports_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
)
1 change: 1 addition & 0 deletions jsonifier/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
- Iván Todorovich \<<[email protected]>\>
- Nguyen Minh Chien \<<[email protected]>\>
- Thien Vo \<<[email protected]>\>
- Mangono team \<<[email protected]>\>
2 changes: 1 addition & 1 deletion jsonifier/readme/CREDITS.md
Original file line number Diff line number Diff line change
@@ -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.
5 changes: 3 additions & 2 deletions jsonifier/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -584,12 +584,13 @@ <h3><a class="toc-backref" href="#toc-entry-6">Contributors</a></h3>
<li>Iván Todorovich &lt;<a class="reference external" href="mailto:ivan.todorovich&#64;camptocamp.com">ivan.todorovich&#64;camptocamp.com</a>&gt;</li>
<li>Nguyen Minh Chien &lt;<a class="reference external" href="mailto:chien&#64;trobz.com">chien&#64;trobz.com</a>&gt;</li>
<li>Thien Vo &lt;<a class="reference external" href="mailto:thienvh&#64;trobz.com">thienvh&#64;trobz.com</a>&gt;</li>
<li>Mangono team &lt;<a class="reference external" href="mailto:opensource&#64;mangono.fr">opensource&#64;mangono.fr</a>&gt;</li>
</ul>
</div>
<div class="section" id="other-credits">
<h3><a class="toc-backref" href="#toc-entry-7">Other credits</a></h3>
<p>The migration of this module from 17.0 to 18.0 was financially supported
by Camptocamp.</p>
<p>The migration of this module from 18.0 to 19.0 was financially supported
by Mangono.</p>
</div>
<div class="section" id="maintainers">
<h3><a class="toc-backref" href="#toc-entry-8">Maintainers</a></h3>
Expand Down
1 change: 1 addition & 0 deletions jsonifier/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from . import test_data_setup
from . import test_get_parser
from . import test_helpers
from . import test_ir_exports_line
60 changes: 60 additions & 0 deletions jsonifier/tests/test_data_setup.py
Original file line number Diff line number Diff line change
@@ -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()
14 changes: 4 additions & 10 deletions jsonifier/tests/test_get_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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(

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Medium · In-transaction edits keep stale targets

When an export line is edited after its parser is cached in the same transaction, the export line’s write_date stays at the transaction timestamp, so get_json_parser() reuses the cached parser and exports keep using the old target; without an edit-and-reparse assertion, the suite passes.

Restore a test that generates the parser, edits the target, generates the parser again in the same transaction, and asserts the updated result.

Also at jsonifier/tests/test_get_parser.py:115.

Prompt for AI agents
In `jsonifier/tests/test_get_parser.py` at line 113:

**In-transaction edits keep stale targets**

When an export line is edited after its parser is cached in the same transaction, the export line’s `write_date` stays at the transaction timestamp, so `get_json_parser()` reuses the cached parser and exports keep using the old target; without an edit-and-reparse assertion, the suite passes.

Restore a test that generates the parser, edits the target, generates the parser again in the same transaction, and asserts the updated result.

Also at `jsonifier/tests/test_get_parser.py:115`.

{"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)
Expand Down
5 changes: 4 additions & 1 deletion jsonifier/tests/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
{
Expand Down
17 changes: 10 additions & 7 deletions jsonifier/tests/test_ir_exports_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,23 @@
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"]
with self.assertRaises(ValidationError):
# 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",
}
Expand All @@ -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",
}
Expand All @@ -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",
}
Expand All @@ -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",
Expand Down
Loading