[12.0][MIG] base_jsonify: cleanup
parent
b2c4d92730
commit
7d2dee18e4
|
@ -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",
|
||||||
|
|
|
@ -7,12 +7,15 @@ from odoo import api, models
|
||||||
|
|
||||||
|
|
||||||
def update_dict(data, fields):
|
def update_dict(data, fields):
|
||||||
"""
|
"""Contruct a tree of fields.
|
||||||
Contruct a tree of fields.
|
|
||||||
ie: {
|
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):
|
||||||
"""
|
"""Convert dict returned by update_dict to list consistent w/ Odoo API.
|
||||||
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
|
The list is composed of strings (field names or aliases) or tuples.
|
||||||
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 ir.exports record and return it.
|
||||||
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.
|
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()
|
||||||
|
|
|
@ -14,9 +14,7 @@ class Base(models.AbstractModel):
|
||||||
|
|
||||||
@api.model
|
@api.model
|
||||||
def __parse_field(self, parser_field):
|
def __parse_field(self, parser_field):
|
||||||
"""
|
"""Deduct how to handle a field from its parser."""
|
||||||
Deducts 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',
|
||||||
|
|
|
@ -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.
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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…
Reference in New Issue