You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

44 lines
1.2 KiB

  1. # -*- coding: utf-8 -*-
  2. # © 2017 Akretion (http://www.akretion.com)
  3. # Sébastien BEAU <sebastien.beau@akretion.com>
  4. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  5. from collections import OrderedDict
  6. from odoo import api, models
  7. def update_dict(data, fields):
  8. field = fields[0]
  9. if len(fields) == 1:
  10. if field == '.id':
  11. field = 'id'
  12. data[field] = True
  13. else:
  14. if field not in data:
  15. data[field] = OrderedDict()
  16. update_dict(data[field], fields[1:])
  17. def convert_dict(dict_parser):
  18. parser = []
  19. for field, value in dict_parser.iteritems():
  20. if value is True:
  21. parser.append(field)
  22. else:
  23. parser.append((field, convert_dict(value)))
  24. return parser
  25. class IrExport(models.Model):
  26. _inherit = 'ir.exports'
  27. @api.multi
  28. def get_json_parser(self):
  29. self.ensure_one()
  30. dict_parser = OrderedDict()
  31. for line in self.export_fields:
  32. names = line.name.split('/')
  33. if line.alias:
  34. names = line.alias.split('/')
  35. update_dict(dict_parser, names)
  36. return convert_dict(dict_parser)