|
@ -8,6 +8,14 @@ from odoo import api, models |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def update_dict(data, fields): |
|
|
def update_dict(data, fields): |
|
|
|
|
|
""" |
|
|
|
|
|
Contruct a tree of fields. |
|
|
|
|
|
ie: { |
|
|
|
|
|
"name": True, |
|
|
|
|
|
"resource": True, |
|
|
|
|
|
} |
|
|
|
|
|
Order of keys is important. |
|
|
|
|
|
""" |
|
|
field = fields[0] |
|
|
field = fields[0] |
|
|
if len(fields) == 1: |
|
|
if len(fields) == 1: |
|
|
if field == '.id': |
|
|
if field == '.id': |
|
@ -20,6 +28,11 @@ 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. |
|
|
|
|
|
""" |
|
|
parser = [] |
|
|
parser = [] |
|
|
for field, value in dict_parser.iteritems(): |
|
|
for field, value in dict_parser.iteritems(): |
|
|
if value is True: |
|
|
if value is True: |
|
@ -34,6 +47,10 @@ 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. |
|
|
|
|
|
""" |
|
|
self.ensure_one() |
|
|
self.ensure_one() |
|
|
dict_parser = OrderedDict() |
|
|
dict_parser = OrderedDict() |
|
|
for line in self.export_fields: |
|
|
for line in self.export_fields: |
|
@ -41,4 +58,5 @@ class IrExport(models.Model): |
|
|
if line.alias: |
|
|
if line.alias: |
|
|
names = line.alias.split('/') |
|
|
names = line.alias.split('/') |
|
|
update_dict(dict_parser, names) |
|
|
update_dict(dict_parser, names) |
|
|
|
|
|
|
|
|
return convert_dict(dict_parser) |
|
|
return convert_dict(dict_parser) |