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.

42 lines
1.2 KiB

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