Browse Source

[12.0][MIG] base_jsonify: cleanup

13.0
Simone Orsi 6 years ago
committed by laurent.corron
parent
commit
7d2dee18e4
  1. 3
      base_jsonify/__manifest__.py
  2. 22
      base_jsonify/models/ir_export.py
  3. 7
      base_jsonify/models/models.py
  4. 2
      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", "name": "Base Jsonify",
"summary": "Base module that provide the jsonify method on all models", "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", "category": "Uncategorized",
"website": "https://github.com/OCA/server-tools", "website": "https://github.com/OCA/server-tools",
"author": "Akretion, Odoo Community Association (OCA)", "author": "Akretion, Odoo Community Association (OCA)",
"license": "AGPL-3", "license": "AGPL-3",
"application": False,
"installable": True, "installable": True,
"depends": [ "depends": [
"base", "base",

22
base_jsonify/models/ir_export.py

@ -7,12 +7,15 @@ from odoo import api, models
def update_dict(data, fields): def update_dict(data, fields):
"""
Contruct a tree of fields.
ie: {
"""Contruct a tree of fields.
Example:
{
"name": True, "name": True,
"resource": True, "resource": True,
} }
Order of keys is important. Order of keys is important.
""" """
field = fields[0] field = fields[0]
@ -27,10 +30,9 @@ def update_dict(data, fields):
def convert_dict(dict_parser): 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 = [] parser = []
for field, value in dict_parser.items(): for field, value in dict_parser.items():
@ -46,9 +48,9 @@ class IrExport(models.Model):
@api.multi @api.multi
def get_json_parser(self): 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() self.ensure_one()
dict_parser = OrderedDict() dict_parser = OrderedDict()

7
base_jsonify/models/models.py

@ -14,9 +14,7 @@ class Base(models.AbstractModel):
@api.model @api.model
def __parse_field(self, parser_field): 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 field_name = parser_field
subparser = None subparser = None
if isinstance(parser_field, tuple): if isinstance(parser_field, tuple):
@ -28,7 +26,8 @@ class Base(models.AbstractModel):
@api.multi @api.multi
def jsonify(self, parser): def jsonify(self, parser):
""" Convert the record according to the parser given
"""Convert the record according to the given parser.
Example of parser: Example of parser:
parser = [ parser = [
'name', 'name',

2
base_jsonify/readme/DESCRIPTION.rst

@ -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 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). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo.tests.common import TransactionCase 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). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo.exceptions import ValidationError from odoo.exceptions import ValidationError

Loading…
Cancel
Save