|
|
@ -5,11 +5,16 @@ |
|
|
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). |
|
|
|
|
|
|
|
from odoo import api, models |
|
|
|
from odoo.exceptions import Warning as UserError |
|
|
|
from odoo.exceptions import UserError |
|
|
|
from odoo.tools.translate import _ |
|
|
|
|
|
|
|
|
|
|
|
def __parse_field(parser_field): |
|
|
|
class Base(models.AbstractModel): |
|
|
|
|
|
|
|
_inherit = 'base' |
|
|
|
|
|
|
|
@api.model |
|
|
|
def __parse_field(self, parser_field): |
|
|
|
field_name = parser_field |
|
|
|
subparser = None |
|
|
|
if isinstance(parser_field, tuple): |
|
|
@ -20,8 +25,8 @@ def __parse_field(parser_field): |
|
|
|
return field_name, json_key, subparser |
|
|
|
|
|
|
|
|
|
|
|
@api.multi |
|
|
|
def jsonify(self, parser): |
|
|
|
@api.multi |
|
|
|
def jsonify(self, parser): |
|
|
|
""" Convert the record according to the parser given |
|
|
|
Example of parser: |
|
|
|
parser = [ |
|
|
@ -55,7 +60,7 @@ def jsonify(self, parser): |
|
|
|
for rec in self: |
|
|
|
res = {} |
|
|
|
for field in parser: |
|
|
|
field_name, json_key, subparser = __parse_field(field) |
|
|
|
field_name, json_key, subparser = self.__parse_field(field) |
|
|
|
field_type = rec._fields[field_name].type |
|
|
|
if subparser: |
|
|
|
if field_type in ('one2many', 'many2many'): |
|
|
@ -73,6 +78,3 @@ def jsonify(self, parser): |
|
|
|
res[json_key] = empty_value[field_type] |
|
|
|
result.append(res) |
|
|
|
return result |
|
|
|
|
|
|
|
|
|
|
|
models.Model.jsonify = jsonify |