From 74a4c2c713ecb1538e21d7dfd88638371dcd0a06 Mon Sep 17 00:00:00 2001
From: nans
Date: Mon, 5 Oct 2020 21:21:32 +0200
Subject: [PATCH] [REF] base_jsonify: rename ir.exports.line field `alias` to
`target`
---
base_jsonify/README.rst | 14 +++++-----
base_jsonify/__manifest__.py | 2 +-
base_jsonify/i18n/base_jsonify.pot | 14 +++++-----
base_jsonify/i18n/zh_CN.po | 14 +++++-----
.../migrations/13.0.2.0.0/pre-migrate.py | 6 ++++
base_jsonify/models/ir_export.py | 8 +++---
base_jsonify/models/ir_exports_line.py | 28 +++++++++----------
base_jsonify/models/models.py | 4 +--
base_jsonify/readme/DESCRIPTION.rst | 14 +++++-----
base_jsonify/static/description/index.html | 14 +++++-----
base_jsonify/tests/test_get_parser.py | 22 +++++++--------
base_jsonify/tests/test_ir_exports_line.py | 16 +++++------
base_jsonify/views/ir_exports_view.xml | 2 +-
13 files changed, 82 insertions(+), 76 deletions(-)
create mode 100644 base_jsonify/migrations/13.0.2.0.0/pre-migrate.py
diff --git a/base_jsonify/README.rst b/base_jsonify/README.rst
index 407433303..3d7cc741a 100644
--- a/base_jsonify/README.rst
+++ b/base_jsonify/README.rst
@@ -96,11 +96,11 @@ To use these features, a full parser follows the following structure:
False: [
{'name': 'description'},
{'name': 'number', 'resolver': 5},
- ({'name': 'partner_id', 'alias': 'partner'}, [{'name': 'display_name'}])
+ ({'name': 'partner_id', 'target': 'partner'}, [{'name': 'display_name'}])
],
'fr_FR': [
- {'name': 'description', 'alias': 'descriptions_fr'},
- ({'name': 'partner_id', 'alias': 'partner'}, [{'name': 'description', 'alias': 'description_fr'}])
+ {'name': 'description', 'target': 'descriptions_fr'},
+ ({'name': 'partner_id', 'target': 'partner'}, [{'name': 'description', 'target': 'description_fr'}])
],
}
}
@@ -132,7 +132,7 @@ but other features like custom resolvers are:
"fields": [
{'name': 'description'},
{'name': 'number', 'resolver': 5},
- ({'name': 'partner_id', 'alias': 'partners'}, [{'name': 'display_name'}]),
+ ({'name': 'partner_id', 'target': 'partners'}, [{'name': 'display_name'}]),
],
}
@@ -157,7 +157,7 @@ If the global resolver is given, then the json_dict goes through:
Which allows to add external data from the context or transform the dictionary
if necessary. Similarly if given for a field the resolver evaluates the result.
-It is possible for an alias to end with a '*':
+It is possible for a target to end with a '*':
in that case the result is put into a list.
.. code-block:: python
@@ -165,8 +165,8 @@ in that case the result is put into a list.
parser = {
fields: [
{'name': 'name'},
- {'name': 'field_1', 'alias': 'customTags*'},
- {'name': 'field_2', 'alias': 'customTags*'},
+ {'name': 'field_1', 'target': 'customTags*'},
+ {'name': 'field_2', 'target': 'customTags*'},
]
}
diff --git a/base_jsonify/__manifest__.py b/base_jsonify/__manifest__.py
index f21c68491..61c6b625d 100644
--- a/base_jsonify/__manifest__.py
+++ b/base_jsonify/__manifest__.py
@@ -6,7 +6,7 @@
{
"name": "Base Jsonify",
"summary": "Base module that provide the jsonify method on all models",
- "version": "13.0.1.3.1",
+ "version": "13.0.2.0.0",
"category": "Uncategorized",
"website": "https://github.com/OCA/server-tools",
"author": "Akretion, Odoo Community Association (OCA)",
diff --git a/base_jsonify/i18n/base_jsonify.pot b/base_jsonify/i18n/base_jsonify.pot
index 204e006bb..b4f6137be 100644
--- a/base_jsonify/i18n/base_jsonify.pot
+++ b/base_jsonify/i18n/base_jsonify.pot
@@ -19,8 +19,8 @@ msgid "Active"
msgstr ""
#. module: base_jsonify
-#: model:ir.model.fields,field_description:base_jsonify.field_ir_exports_line__alias
-msgid "Alias"
+#: model:ir.model.fields,field_description:base_jsonify.field_ir_exports_line__target
+msgid "Target"
msgstr ""
#. module: base_jsonify
@@ -57,20 +57,20 @@ msgstr ""
#. module: base_jsonify
#: code:addons/base_jsonify/models/ir_exports_line.py:0
#, python-format
-msgid "Name and Alias must have the same hierarchy depth"
+msgid "Name and Target must have the same hierarchy depth"
msgstr ""
#. module: base_jsonify
#: code:addons/base_jsonify/models/ir_exports_line.py:0
#, python-format
-msgid "The alias must reference the same field as in name '%s' not in '%s'"
+msgid "The target must reference the same field as in name '%s' not in '%s'"
msgstr ""
#. module: base_jsonify
-#: model:ir.model.fields,help:base_jsonify.field_ir_exports_line__alias
+#: model:ir.model.fields,help:base_jsonify.field_ir_exports_line__target
msgid ""
-"The complete path to the field where you can specify an alias on the a step "
-"as field:alias"
+"The complete path to the field where you can specify a target on the a step "
+"as field:target"
msgstr ""
#. module: base_jsonify
diff --git a/base_jsonify/i18n/zh_CN.po b/base_jsonify/i18n/zh_CN.po
index ad2d4dd0d..490be0292 100644
--- a/base_jsonify/i18n/zh_CN.po
+++ b/base_jsonify/i18n/zh_CN.po
@@ -22,8 +22,8 @@ msgid "Active"
msgstr ""
#. module: base_jsonify
-#: model:ir.model.fields,field_description:base_jsonify.field_ir_exports_line__alias
-msgid "Alias"
+#: model:ir.model.fields,field_description:base_jsonify.field_ir_exports_line__target
+msgid "Target"
msgstr "别名"
#. module: base_jsonify
@@ -60,20 +60,20 @@ msgstr "索引"
#. module: base_jsonify
#: code:addons/base_jsonify/models/ir_exports_line.py:0
#, python-format
-msgid "Name and Alias must have the same hierarchy depth"
+msgid "Name and Target must have the same hierarchy depth"
msgstr "名称和别名必须具有相同的层次结构深度"
#. module: base_jsonify
#: code:addons/base_jsonify/models/ir_exports_line.py:0
#, python-format
-msgid "The alias must reference the same field as in name '%s' not in '%s'"
+msgid "The target must reference the same field as in name '%s' not in '%s'"
msgstr "别名必须引用与名称相同的字段'%s'不在'%s'"
#. module: base_jsonify
-#: model:ir.model.fields,help:base_jsonify.field_ir_exports_line__alias
+#: model:ir.model.fields,help:base_jsonify.field_ir_exports_line__target
msgid ""
-"The complete path to the field where you can specify an alias on the a step "
-"as field:alias"
+"The complete path to the field where you can specify a target on the a step "
+"as field:target"
msgstr "字段的完整路径,您可以在其中指定步骤作为字段的别名:别名"
#. module: base_jsonify
diff --git a/base_jsonify/migrations/13.0.2.0.0/pre-migrate.py b/base_jsonify/migrations/13.0.2.0.0/pre-migrate.py
new file mode 100644
index 000000000..8ac71b839
--- /dev/null
+++ b/base_jsonify/migrations/13.0.2.0.0/pre-migrate.py
@@ -0,0 +1,6 @@
+# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
+
+
+def migrate(cr, version):
+ query = """ALTER TABLE "ir_exports_line" RENAME COLUMN "alias" TO "target";"""
+ cr.execute(query)
diff --git a/base_jsonify/models/ir_export.py b/base_jsonify/models/ir_export.py
index b41f57825..6c1d9c8b0 100644
--- a/base_jsonify/models/ir_export.py
+++ b/base_jsonify/models/ir_export.py
@@ -49,7 +49,7 @@ def update_dict(data, fields, options):
def convert_dict(dict_parser):
"""Convert dict returned by update_dict to list consistent w/ Odoo API.
- The list is composed of strings (field names or aliases) or tuples.
+ The list is composed of strings (field names or targets) or tuples.
"""
parser = []
for field, value in dict_parser.items():
@@ -63,7 +63,7 @@ def convert_dict(dict_parser):
def field_dict(field, options=None):
result = {"name": field.split(":")[0]}
if len(field.split(":")) > 1:
- result["alias"] = field.split(":")[1]
+ result["target"] = field.split(":")[1]
for option in options or {}:
if options[option]:
result[option] = options[option]
@@ -100,8 +100,8 @@ class IrExport(models.Model):
dict_parser = OrderedDict()
for line in lang_to_lines[lang]:
names = line.name.split("/")
- if line.alias:
- names = line.alias.split("/")
+ if line.target:
+ names = line.target.split("/")
options = {"resolver": line.resolver_id, "function": line.function}
update_dict(dict_parser, names, options)
lang_parsers[lang] = convert_dict(dict_parser)
diff --git a/base_jsonify/models/ir_exports_line.py b/base_jsonify/models/ir_exports_line.py
index 25804df4a..1c2898bcd 100644
--- a/base_jsonify/models/ir_exports_line.py
+++ b/base_jsonify/models/ir_exports_line.py
@@ -8,10 +8,10 @@ from odoo.exceptions import ValidationError
class IrExportsLine(models.Model):
_inherit = "ir.exports.line"
- alias = fields.Char(
- "Alias",
- help="The complete path to the field where you can specify an "
- "alias on the a step as field:alias",
+ target = fields.Char(
+ "Target",
+ help="The complete path to the field where you can specify a "
+ "target on the a step as field:target",
)
active = fields.Boolean(string="Active", default=True)
lang_id = fields.Many2one(
@@ -38,24 +38,24 @@ class IrExportsLine(models.Model):
_("Either set a function or a resolver, not both.")
)
- @api.constrains("alias", "name")
- def _check_alias(self):
+ @api.constrains("target", "name")
+ def _check_target(self):
for rec in self:
- if not rec.alias:
+ if not rec.target:
continue
names = rec.name.split("/")
- names_with_alias = rec.alias.split("/")
- if len(names) != len(names_with_alias):
+ names_with_target = rec.target.split("/")
+ if len(names) != len(names_with_target):
raise ValidationError(
- _("Name and Alias must have the same hierarchy depth")
+ _("Name and Target must have the same hierarchy depth")
)
- for name, name_with_alias in zip(names, names_with_alias):
- field_name = name_with_alias.split(":")[0]
+ for name, name_with_target in zip(names, names_with_target):
+ field_name = name_with_target.split(":")[0]
if name != field_name:
raise ValidationError(
_(
- "The alias must reference the same field as in "
+ "The target must reference the same field as in "
"name '%s' not in '%s'"
)
- % (name, name_with_alias)
+ % (name, name_with_target)
)
diff --git a/base_jsonify/models/models.py b/base_jsonify/models/models.py
index 5ef50cfda..e773262b6 100644
--- a/base_jsonify/models/models.py
+++ b/base_jsonify/models/models.py
@@ -25,7 +25,7 @@ class Base(models.AbstractModel):
field_split = f.split(":")
field_dict = {"name": field_split[0]}
if len(field_split) > 1:
- field_dict["alias"] = field_split[1]
+ field_dict["target"] = field_split[1]
if function:
field_dict["function"] = function
return field_dict
@@ -86,7 +86,7 @@ class Base(models.AbstractModel):
for field in parser:
field_dict, subparser = rec.__parse_field(field)
field_name = field_dict["name"]
- json_key = field_dict.get("alias", field_name)
+ json_key = field_dict.get("target", field_name)
field = rec._fields[field_name]
if field_dict.get("function"):
function = field_dict["function"]
diff --git a/base_jsonify/readme/DESCRIPTION.rst b/base_jsonify/readme/DESCRIPTION.rst
index 7a64779b1..1dc9a9e7b 100644
--- a/base_jsonify/readme/DESCRIPTION.rst
+++ b/base_jsonify/readme/DESCRIPTION.rst
@@ -69,11 +69,11 @@ To use these features, a full parser follows the following structure:
False: [
{'name': 'description'},
{'name': 'number', 'resolver': 5},
- ({'name': 'partner_id', 'alias': 'partner'}, [{'name': 'display_name'}])
+ ({'name': 'partner_id', 'target': 'partner'}, [{'name': 'display_name'}])
],
'fr_FR': [
- {'name': 'description', 'alias': 'descriptions_fr'},
- ({'name': 'partner_id', 'alias': 'partner'}, [{'name': 'description', 'alias': 'description_fr'}])
+ {'name': 'description', 'target': 'descriptions_fr'},
+ ({'name': 'partner_id', 'target': 'partner'}, [{'name': 'description', 'target': 'description_fr'}])
],
}
}
@@ -105,7 +105,7 @@ but other features like custom resolvers are:
"fields": [
{'name': 'description'},
{'name': 'number', 'resolver': 5},
- ({'name': 'partner_id', 'alias': 'partners'}, [{'name': 'display_name'}]),
+ ({'name': 'partner_id', 'target': 'partners'}, [{'name': 'display_name'}]),
],
}
@@ -130,7 +130,7 @@ If the global resolver is given, then the json_dict goes through:
Which allows to add external data from the context or transform the dictionary
if necessary. Similarly if given for a field the resolver evaluates the result.
-It is possible for an alias to end with a '*':
+It is possible for a target to end with a '*':
in that case the result is put into a list.
.. code-block:: python
@@ -138,8 +138,8 @@ in that case the result is put into a list.
parser = {
fields: [
{'name': 'name'},
- {'name': 'field_1', 'alias': 'customTags*'},
- {'name': 'field_2', 'alias': 'customTags*'},
+ {'name': 'field_1', 'target': 'customTags*'},
+ {'name': 'field_2', 'target': 'customTags*'},
]
}
diff --git a/base_jsonify/static/description/index.html b/base_jsonify/static/description/index.html
index 4eccd00a7..f8c92fd26 100644
--- a/base_jsonify/static/description/index.html
+++ b/base_jsonify/static/description/index.html
@@ -424,11 +424,11 @@ It is also to specify a lang to extract the translation of any given field.
False: [
{'name': 'description'},
{'name': 'number', 'resolver': 5},
- ({'name': 'partner_id', 'alias': 'partner'}, [{'name': 'display_name'}])
+ ({'name': 'partner_id', 'target': 'partner'}, [{'name': 'display_name'}])
],
'fr_FR': [
- {'name': 'description', 'alias': 'descriptions_fr'},
- ({'name': 'partner_id', 'alias': 'partner'}, [{'name': 'description', 'alias': 'description_fr'}])
+ {'name': 'description', 'target': 'descriptions_fr'},
+ ({'name': 'partner_id', 'target': 'partner'}, [{'name': 'description', 'target': 'description_fr'}])
],
}
}
@@ -454,7 +454,7 @@ but other features like custom resolvers are:
"fields": [
{'name': 'description'},
{'name': 'number', 'resolver': 5},
- ({'name': 'partner_id', 'alias': 'partners'}, [{'name': 'display_name'}]),
+ ({'name': 'partner_id', 'target': 'partners'}, [{'name': 'display_name'}]),
],
}
@@ -472,14 +472,14 @@ with the added benefit of being able to use resolvers.
Which allows to add external data from the context or transform the dictionary
if necessary. Similarly if given for a field the resolver evaluates the result.
-It is possible for an alias to end with a ‘*’:
+
It is possible for a target to end with a ‘*’:
in that case the result is put into a list.
parser = {
fields: [
{'name': 'name'},
- {'name': 'field_1', 'alias': 'customTags*'},
- {'name': 'field_2', 'alias': 'customTags*'},
+ {'name': 'field_1', 'target': 'customTags*'},
+ {'name': 'field_2', 'target': 'customTags*'},
]
}
diff --git a/base_jsonify/tests/test_get_parser.py b/base_jsonify/tests/test_get_parser.py
index cf0c025d6..1737bb0bb 100644
--- a/base_jsonify/tests/test_get_parser.py
+++ b/base_jsonify/tests/test_get_parser.py
@@ -41,7 +41,7 @@ class TestParser(SavepointCase):
cls.lang.active = True
cls.env["ir.translation"]._load_module_terms(["base"], [cls.lang.code])
category = cls.env["res.partner.category"].create({"name": "name"})
- cls.translated_alias = "name_{}".format(cls.lang.code)
+ cls.translated_target = "name_{}".format(cls.lang.code)
cls.env["ir.translation"].create(
{
"type": "model",
@@ -49,7 +49,7 @@ class TestParser(SavepointCase):
"module": "base",
"lang": cls.lang.code,
"res_id": category.id,
- "value": cls.translated_alias,
+ "value": cls.translated_target,
"state": "translated",
}
)
@@ -70,7 +70,7 @@ class TestParser(SavepointCase):
0,
{
"name": "name",
- "alias": "name:{}".format(cls.translated_alias),
+ "target": "name:{}".format(cls.translated_target),
"lang_id": cls.lang.id,
},
),
@@ -79,7 +79,7 @@ class TestParser(SavepointCase):
0,
{
"name": "name",
- "alias": "name:name_resolved",
+ "target": "name:name_resolved",
"resolver_id": cls.resolver.id,
},
),
@@ -116,9 +116,9 @@ class TestParser(SavepointCase):
expected_full_parser = exporter.convert_simple_to_full_parser(expected_parser)
self.assertEqual(parser, expected_full_parser)
- # modify an ir.exports_line to put an alias for a field
+ # modify an ir.exports_line to put a target for a field
self.env.ref("base_jsonify.category_id_name").write(
- {"alias": "category_id:category/name"}
+ {"target": "category_id:category/name"}
)
expected_parser[4] = ("category_id:category", ["name"])
parser = exporter.get_json_parser()
@@ -226,7 +226,7 @@ class TestParser(SavepointCase):
self.assertEqual(
json, json_fr
) # starting from different languages should not change anything
- self.assertEqual(json[self.translated_alias], self.translated_alias)
+ self.assertEqual(json[self.translated_target], self.translated_target)
self.assertEqual(json["name_resolved"], "name_pidgin") # field resolver
self.assertEqual(json["X"], "X") # added by global resolver
@@ -238,9 +238,9 @@ class TestParser(SavepointCase):
json_fr = self.category_lang.jsonify(parser)[0]
self.assertEqual(json["name"], "name")
- self.assertEqual(json_fr["name"], self.translated_alias)
+ self.assertEqual(json_fr["name"], self.translated_target)
- def test_simple_star_alias_and_field_resolver(self):
+ def test_simple_star_target_and_field_resolver(self):
"""The simple parser result should depend on the context language.
"""
code = (
@@ -251,8 +251,8 @@ class TestParser(SavepointCase):
)
resolver = self.env["ir.exports.resolver"].create({"python_code": code})
lang_parser = [
- {"alias": "customTags*", "name": "name", "resolver": resolver.id},
- {"alias": "customTags*", "name": "id", "resolver": resolver.id},
+ {"target": "customTags*", "name": "name", "resolver": resolver.id},
+ {"target": "customTags*", "name": "id", "resolver": resolver.id},
]
parser = {"language_agnostic": True, "langs": {False: lang_parser}}
expected_json = {
diff --git a/base_jsonify/tests/test_ir_exports_line.py b/base_jsonify/tests/test_ir_exports_line.py
index 6aab58ee3..29184264b 100644
--- a/base_jsonify/tests/test_ir_exports_line.py
+++ b/base_jsonify/tests/test_ir_exports_line.py
@@ -10,42 +10,42 @@ class TestIrExportsLine(TransactionCase):
super(TestIrExportsLine, self).setUp()
self.ir_export = self.env.ref("base_jsonify.ir_exp_partner")
- def test_alias_contrains(self):
+ def test_target_contrains(self):
ir_export_lines_model = self.env["ir.exports.line"]
with self.assertRaises(ValidationError):
- # The field into the name must be also into the alias
+ # The field into the name must be also into the target
ir_export_lines_model.create(
{
"export_id": self.ir_export.id,
"name": "name",
- "alias": "toto:my_alias",
+ "target": "toto:my_target",
}
)
with self.assertRaises(ValidationError):
- # The hierarchy into the alias must be the same as the one into
+ # The hierarchy into the target must be the same as the one into
# the name
ir_export_lines_model.create(
{
"export_id": self.ir_export.id,
"name": "child_ids/child_ids/name",
- "alias": "child_ids:children/name",
+ "target": "child_ids:children/name",
}
)
with self.assertRaises(ValidationError):
- # The hierarchy into the alias must be the same as the one into
+ # The hierarchy into the target must be the same as the one into
# the name and must contains the same fields as into the name
ir_export_lines_model.create(
{
"export_id": self.ir_export.id,
"name": "child_ids/child_ids/name",
- "alias": "child_ids:children/category_id:category/name",
+ "target": "child_ids:children/category_id:category/name",
}
)
line = ir_export_lines_model.create(
{
"export_id": self.ir_export.id,
"name": "child_ids/child_ids/name",
- "alias": "child_ids:children/child_ids:children/name",
+ "target": "child_ids:children/child_ids:children/name",
}
)
self.assertTrue(line)
diff --git a/base_jsonify/views/ir_exports_view.xml b/base_jsonify/views/ir_exports_view.xml
index 075dc6bcc..a1878de74 100644
--- a/base_jsonify/views/ir_exports_view.xml
+++ b/base_jsonify/views/ir_exports_view.xml
@@ -18,7 +18,7 @@
-
+