2 Star 0 Fork 0

oca-github/server-tools

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
DESCRIPTION.rst 1.20 KB
一键复制 编辑 原始数据 按行查看 历史
Pierrick brun 提交于 2018-12-11 23:51 +08:00 . [FIX] misc. fixes in the comments/docstrings

This module adds a 'jsonify' method to every model of the ORM. It works on the current recordset and requires a single argument 'parser' that specify the field to extract.

Example of parser:

parser = [
    'name',
    'number',
    'create_date',
    ('partner_id', ['id', 'display_name', 'ref'])
    ('line_id', ['id', ('product_id', ['name']), 'price_unit'])
]

In order to be consitent with the odoo api the jsonify method always return a list of object even if there is only one element in input

By default the key into the json is the name of the field extracted from the model. If you need to specify an alternate name to use as key, you can define your mapping as follow into the parser definition:

parser = [
     'field_name:json_key'
]
parser = [
    'name',
    'number',
    'create_date:creationDate',
    ('partner_id:partners', ['id', 'display_name', 'ref'])
    ('line_id:lines', ['id', ('product_id', ['name']), 'price_unit'])
]

Also the module provide a method "get_json_parser" on the ir.exports object that generate a parser from an ir.exports configuration

Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/oca-github/server-tools.git
git@gitee.com:oca-github/server-tools.git
oca-github
server-tools
server-tools
10.0

搜索帮助