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.

40 lines
1.0 KiB

  1. # -*- coding: utf-8 -*-
  2. # © 2016 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 openerp import api, models
  6. def update_dict(data, fields):
  7. field = fields[0]
  8. if len(fields) == 1:
  9. if field == '.id':
  10. field = 'id'
  11. data[field] = True
  12. else:
  13. if field not in data:
  14. data[field] = {}
  15. update_dict(data[field], fields[1:])
  16. def convert_dict(dict_parser):
  17. parser = []
  18. for field, value in dict_parser.iteritems():
  19. if value is True:
  20. parser.append(field)
  21. else:
  22. parser.append((field, convert_dict(value)))
  23. return parser
  24. class IrExport(models.Model):
  25. _inherit = 'ir.exports'
  26. @api.multi
  27. def get_json_parser(self):
  28. self.ensure_one()
  29. dict_parser = {}
  30. for line in self.export_fields:
  31. update_dict(dict_parser, line.name.split('/'))
  32. return convert_dict(dict_parser)