|
|
@ -1,14 +1,20 @@ |
|
|
|
# -*- coding: utf-8 -*- |
|
|
|
# © 2016 Akretion (http://www.akretion.com) |
|
|
|
# © 2017 Akretion (http://www.akretion.com) |
|
|
|
# Sébastien BEAU <sebastien.beau@akretion.com> |
|
|
|
# Raphaël Reverdy <raphael.reverdy@akretion.com> |
|
|
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). |
|
|
|
|
|
|
|
from openerp import api, models |
|
|
|
from openerp.exceptions import Warning as UserError |
|
|
|
from openerp.tools.translate import _ |
|
|
|
from odoo import api, models |
|
|
|
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): |
|
|
@ -45,15 +51,16 @@ def jsonify(self, parser): |
|
|
|
""" |
|
|
|
result = [] |
|
|
|
empty_value = { |
|
|
|
'char': '', |
|
|
|
'int': 0, |
|
|
|
'float': 0, |
|
|
|
'char': None, |
|
|
|
'int': None, |
|
|
|
# 'float': None, TODO: 0.0 != False |
|
|
|
'text': None, |
|
|
|
} |
|
|
|
|
|
|
|
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'): |
|
|
@ -71,6 +78,3 @@ def jsonify(self, parser): |
|
|
|
res[json_key] = empty_value[field_type] |
|
|
|
result.append(res) |
|
|
|
return result |
|
|
|
|
|
|
|
|
|
|
|
models.Model.jsonify = jsonify |