Browse Source

[12.0][MIG] base_jsonify: cleanup

pull/1472/head
Simone Orsi 6 years ago
parent
commit
dcae543b0d
  1. 3
      base_jsonify/__manifest__.py
  2. 26
      base_jsonify/models/ir_export.py
  3. 7
      base_jsonify/models/models.py
  4. 4
      base_jsonify/readme/DESCRIPTION.rst
  5. 2
      base_jsonify/tests/test_get_parser.py
  6. 2
      base_jsonify/tests/test_ir_exports_line.py

3
base_jsonify/__manifest__.py

@ -6,12 +6,11 @@
{
"name": "Base Jsonify",
"summary": "Base module that provide the jsonify method on all models",
"version": "10.0.1.0.0",
"version": "12.0.1.0.0",
"category": "Uncategorized",
"website": "https://github.com/OCA/server-tools",
"author": "Akretion, Odoo Community Association (OCA)",
"license": "AGPL-3",
"application": False,
"installable": True,
"depends": [
"base",

26
base_jsonify/models/ir_export.py

@ -7,12 +7,15 @@ from odoo import api, models
def update_dict(data, fields):
"""
Contruct a tree of fields.
ie: {
"name": True,
"resource": True,
"""Contruct a tree of fields.
Example:
{
"name": True,
"resource": True,
}
Order of keys is important.
"""
field = fields[0]
@ -27,10 +30,9 @@ def update_dict(data, fields):
def convert_dict(dict_parser):
"""
Converts the dict returned by update_dict to a list consistent with the
Odoo API. The list is composed of strings (field names or aliases) or
tuples.
"""Convert dict returned by update_dict to list consistent w/ Odoo API.
The list is composed of strings (field names or aliases) or tuples.
"""
parser = []
for field, value in dict_parser.items():
@ -46,9 +48,9 @@ class IrExport(models.Model):
@api.multi
def get_json_parser(self):
"""
Creates a parser from a ir_exports record and returns it. This parser
can then be used to "jsonify" records of the ir_export's model.
"""Creates a parser from ir.exports record and return it.
The final parser can be used to "jsonify" records of ir.export's model.
"""
self.ensure_one()
dict_parser = OrderedDict()

7
base_jsonify/models/models.py

@ -14,9 +14,7 @@ class Base(models.AbstractModel):
@api.model
def __parse_field(self, parser_field):
"""
Deducts how to handle a field from its parser
"""
"""Deduct how to handle a field from its parser."""
field_name = parser_field
subparser = None
if isinstance(parser_field, tuple):
@ -28,7 +26,8 @@ class Base(models.AbstractModel):
@api.multi
def jsonify(self, parser):
""" Convert the record according to the parser given
"""Convert the record according to the given parser.
Example of parser:
parser = [
'name',

4
base_jsonify/readme/DESCRIPTION.rst

@ -25,7 +25,7 @@ can define your mapping as follow into the parser definition:
.. code-block:: python
parser = [
'field_name:json_key'
'field_name:json_key'
]
.. code-block:: python
@ -40,4 +40,4 @@ can define your mapping as follow into the parser definition:
]
Also the module provide a method "get_json_parser" on the ir.exports object
that generate a parser from an ir.exports configuration
that generate a parser from an ir.exports configuration.

2
base_jsonify/tests/test_get_parser.py

@ -1,4 +1,4 @@
# © <YEAR(S)> <AUTHOR(S)>
# Copyright 2017 ACSONE SA/NV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo.tests.common import TransactionCase

2
base_jsonify/tests/test_ir_exports_line.py

@ -1,4 +1,4 @@
# © 2017 ACSONE SA/NV
# Copyright 2017 ACSONE SA/NV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo.exceptions import ValidationError

Loading…
Cancel
Save