From 202f1f14c3046bfafb2fc48fdb0a2b0543a19de5 Mon Sep 17 00:00:00 2001 From: thien Date: Fri, 27 Sep 2024 10:38:16 +0700 Subject: [PATCH] [MIG] jsonifier: Migration to 18.0 --- jsonifier/README.rst | 11 ++- jsonifier/__manifest__.py | 2 +- jsonifier/models/models.py | 4 +- jsonifier/readme/CONTRIBUTORS.md | 1 + jsonifier/readme/CREDITS.md | 1 + jsonifier/readme/USAGE.md | 2 +- jsonifier/static/description/index.html | 77 +++++++++++++++----- jsonifier/tests/test_get_parser.py | 15 ++-- jsonifier/views/ir_exports_resolver_view.xml | 2 +- jsonifier/views/ir_exports_view.xml | 6 +- 10 files changed, 84 insertions(+), 37 deletions(-) create mode 100644 jsonifier/readme/CREDITS.md diff --git a/jsonifier/README.rst b/jsonifier/README.rst index 1f383aa2c0d..c8df765977c 100644 --- a/jsonifier/README.rst +++ b/jsonifier/README.rst @@ -204,8 +204,8 @@ with_fieldname parameter ------------------------ The with_fieldname option of jsonify() method, when true, will inject on -the same level of the data "\_\ `fieldname <>`__\ $field" keys that will -contain the field name, in the language of the current user. +the same level of the data "\_fieldname\_$field" keys that will contain +the field name, in the language of the current user. Examples of with_fieldname usage: @@ -258,6 +258,13 @@ Contributors - Simone Orsi - Iván Todorovich - Nguyen Minh Chien +- Thien Vo + +Other credits +------------- + +The migration of this module from 17.0 to 18.0 was financially supported +by Camptocamp. Maintainers ----------- diff --git a/jsonifier/__manifest__.py b/jsonifier/__manifest__.py index 81f736f41c3..90b378db728 100644 --- a/jsonifier/__manifest__.py +++ b/jsonifier/__manifest__.py @@ -6,7 +6,7 @@ { "name": "JSONifier", "summary": "JSON-ify data for all models", - "version": "17.0.1.0.0", + "version": "18.0.1.0.0", "category": "Uncategorized", "website": "https://github.com/OCA/server-tools", "author": "Akretion, ACSONE, Camptocamp, Odoo Community Association (OCA)", diff --git a/jsonifier/models/models.py b/jsonifier/models/models.py index 3193ca1ec3e..44582f2c80d 100644 --- a/jsonifier/models/models.py +++ b/jsonifier/models/models.py @@ -132,7 +132,7 @@ def _jsonify_record_handle_function(self, rec, field_dict, strict): function = field_dict["function"] try: return self._function_value(rec, function, field_name) - except UserError: + except UserError as err: if strict: raise if not tools.config["test_enable"]: @@ -140,7 +140,7 @@ def _jsonify_record_handle_function(self, rec, field_dict, strict): "%(model)s.%(func)s not available", {"model": self._name, "func": str(function)}, ) - raise SwallableException() + raise SwallableException() from err def _jsonify_record_handle_subparser(self, rec, field_dict, strict, subparser): field_name = field_dict["name"] diff --git a/jsonifier/readme/CONTRIBUTORS.md b/jsonifier/readme/CONTRIBUTORS.md index d46a676fd6b..4323549dad8 100644 --- a/jsonifier/readme/CONTRIBUTORS.md +++ b/jsonifier/readme/CONTRIBUTORS.md @@ -5,3 +5,4 @@ - Simone Orsi \<\> - Iván Todorovich \<\> - Nguyen Minh Chien \<\> +- Thien Vo \<\> diff --git a/jsonifier/readme/CREDITS.md b/jsonifier/readme/CREDITS.md new file mode 100644 index 00000000000..83b3ec91f7d --- /dev/null +++ b/jsonifier/readme/CREDITS.md @@ -0,0 +1 @@ +The migration of this module from 17.0 to 18.0 was financially supported by Camptocamp. diff --git a/jsonifier/readme/USAGE.md b/jsonifier/readme/USAGE.md index 1e175196383..0d566cb52c9 100644 --- a/jsonifier/readme/USAGE.md +++ b/jsonifier/readme/USAGE.md @@ -1,7 +1,7 @@ ## with_fieldname parameter The with_fieldname option of jsonify() method, when true, will inject on -the same level of the data "\_[fieldname]()\$field" keys that will +the same level of the data "\_fieldname_\$field" keys that will contain the field name, in the language of the current user. > Examples of with_fieldname usage: diff --git a/jsonifier/static/description/index.html b/jsonifier/static/description/index.html index f9f165bf641..73ed5d78c5d 100644 --- a/jsonifier/static/description/index.html +++ b/jsonifier/static/description/index.html @@ -8,10 +8,11 @@ /* :Author: David Goodger (goodger@python.org) -:Id: $Id: html4css1.css 8954 2022-01-20 10:10:25Z milde $ +:Id: $Id: html4css1.css 9511 2024-01-13 09:50:07Z milde $ :Copyright: This stylesheet has been placed in the public domain. Default cascading style sheet for the HTML output of Docutils. +Despite the name, some widely supported CSS2 features are used. See https://docutils.sourceforge.io/docs/howto/html-stylesheets.html for how to customize this style sheet. @@ -274,7 +275,7 @@ margin-left: 2em ; margin-right: 2em } -pre.code .ln { color: grey; } /* line numbers */ +pre.code .ln { color: gray; } /* line numbers */ pre.code, code { background-color: #eeeeee } pre.code .comment, code .comment { color: #5C6576 } pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold } @@ -300,7 +301,7 @@ span.pre { white-space: pre } -span.problematic { +span.problematic, pre.problematic { color: red } span.section-subtitle { @@ -368,7 +369,7 @@

JSONifier

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !! source digest: sha256:ddd42fedebde78f1cd5b0cab74c7e30a308efa05c79efc2f84c0724cf3f40901 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! --> -

Beta License: LGPL-3 OCA/server-tools Translate me on Weblate Try me on Runboat

+

Beta License: LGPL-3 OCA/server-tools Translate me on Weblate Try me on Runboat

This module adds a ‘jsonify’ method to every model of the ORM. It works on the current recordset and requires a single argument ‘parser’ that specify the field to extract.

@@ -506,27 +507,61 @@

JSONifier

Table of contents

+
+

Usage

+
+

with_fieldname parameter

+

The with_fieldname option of jsonify() method, when true, will inject on +the same level of the data “_fieldname_$field” keys that will contain +the field name, in the language of the current user.

+
+Examples of with_fieldname usage:
+
+# example 1
+parser = [('name')]
+a.jsonify(parser=parser)
+[{'name': 'SO3996'}]
+>>> a.jsonify(parser=parser, with_fieldname=False)
+[{'name': 'SO3996'}]
+>>> a.jsonify(parser=parser, with_fieldname=True)
+[{'fieldname_name': 'Order Reference', 'name': 'SO3996'}}]
+
+
+# example 2 - with a subparser-
+parser=['name', 'create_date', ('order_line', ['id' , 'product_uom', 'is_expense'])]
+>>> a.jsonify(parser=parser, with_fieldname=False)
+[{'name': 'SO3996', 'create_date': '2015-06-02T12:18:26.279909+00:00', 'order_line': [{'id': 16649, 'product_uom': 'stuks', 'is_expense': False}, {'id': 16651, 'product_uom': 'stuks', 'is_expense': False}, {'id': 16650, 'product_uom': 'stuks', 'is_expense': False}]}]
+>>> a.jsonify(parser=parser, with_fieldname=True)
+[{'fieldname_name': 'Order Reference', 'name': 'SO3996', 'fieldname_create_date': 'Creation Date', 'create_date': '2015-06-02T12:18:26.279909+00:00', 'fieldname_order_line': 'Order Lines', 'order_line': [{'fieldname_id': 'ID', 'id': 16649, 'fieldname_product_uom': 'Unit of Measure', 'product_uom': 'stuks', 'fieldname_is_expense': 'Is expense', 'is_expense': False}]}]
+
+
+
-

Bug Tracker

+

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.

+feedback.

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

-

Credits

+

Credits

-

Authors

+

Authors

  • Akretion
  • ACSONE
  • @@ -534,7 +569,7 @@

    Authors

-

Contributors

+

Contributors

+
+

Other credits

+

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

+
-

Maintainers

+

Maintainers

This module is maintained by the OCA.

-Odoo Community Association + +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/server-tools project on GitHub.

+

This module is part of the OCA/server-tools project on GitHub.

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

diff --git a/jsonifier/tests/test_get_parser.py b/jsonifier/tests/test_get_parser.py index a10294ae3a1..364e9ac2105 100644 --- a/jsonifier/tests/test_get_parser.py +++ b/jsonifier/tests/test_get_parser.py @@ -5,7 +5,7 @@ from unittest import mock -from odoo import fields, tools +from odoo import tools from odoo.exceptions import UserError from odoo.tests.common import TransactionCase @@ -39,7 +39,6 @@ def setUpClass(cls): }, ) ], - "date": fields.Date.from_string("2019-10-31"), } ) Langs = cls.env["res.lang"].with_context(active_test=False) @@ -144,7 +143,6 @@ def test_json_export(self): "active", ("category_id", ["name"]), "create_date", - "date", ] # put our own create date to ease tests self.env.cr.execute( @@ -170,15 +168,13 @@ def test_json_export(self): } ], "create_date": "2019-10-31T14:39:49", - "date": "2019-10-31", } expected_json_with_fieldname = { "_fieldname_lang": "Language", "lang": "en_US", "_fieldname_comment": "Notes", "comment": None, - "_fieldname_credit_limit": "Credit Limit", - "credit_limit": 0.0, + "partner_latitude": 0.0, "_fieldname_name": "Name", "name": "Akretion", "_fieldname_color": "Color Index", @@ -213,11 +209,10 @@ def test_json_export(self): "_fieldname_active": "Active", "active": True, "_fieldname_category_id": "Tags", - "category_id": [{"_fieldname_name": "Tag Name", "name": "Inovator"}], + "category_id": [{"_fieldname_name": "Name", "name": "Inovator"}], "_fieldname_create_date": "Created on", - "create_date": "2019-10-31T15:39:49+01:00", - "_fieldname_date": "Date", - "date": "2019-10-31", + "_fieldname_partner_latitude": "Geo Latitude", + "create_date": "2019-10-31T14:39:49", } json_partner = self.partner.jsonify(parser) self.assertDictEqual(json_partner[0], expected_json) diff --git a/jsonifier/views/ir_exports_resolver_view.xml b/jsonifier/views/ir_exports_resolver_view.xml index 1f18bcaf011..f48124b7a86 100644 --- a/jsonifier/views/ir_exports_resolver_view.xml +++ b/jsonifier/views/ir_exports_resolver_view.xml @@ -16,7 +16,7 @@ Custom Export Resolvers ir.exports.resolver - tree,form + list,form - + - + @@ -32,7 +32,7 @@ Export Fields ir.exports - tree,form + list,form