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.

43 lines
1.2 KiB

  1. This module adds a 'jsonify' method to every model of the ORM.
  2. It works on the current recordset and requires a single argument 'parser'
  3. that specify the field to extract.
  4. Example of parser:
  5. .. code-block:: python
  6. parser = [
  7. 'name',
  8. 'number',
  9. 'create_date',
  10. ('partner_id', ['id', 'display_name', 'ref'])
  11. ('line_id', ['id', ('product_id', ['name']), 'price_unit'])
  12. ]
  13. In order to be consitent with the odoo api the jsonify method always
  14. return a list of object even if there is only one element in input
  15. By default the key into the json is the name of the field extracted
  16. from the model. If you need to specify an alternate name to use as key, you
  17. can define your mapping as follow into the parser definition:
  18. .. code-block:: python
  19. parser = [
  20. 'field_name:json_key'
  21. ]
  22. .. code-block:: python
  23. parser = [
  24. 'name',
  25. 'number',
  26. 'create_date:creationDate',
  27. ('partner_id:partners', ['id', 'display_name', 'ref'])
  28. ('line_id:lines', ['id', ('product_id', ['name']), 'price_unit'])
  29. ]
  30. Also the module provide a method "get_json_parser" on the ir.exports object
  31. that generate a parser from an ir.exports configuration.