用python脚本通过odoorpc方法修改odoo中字段内容

一、安装odoorpc

1、安装python-dev和python-pip

apt-get install python-dev python-pip
pip install odoorpc

2、例子:想在协调单号为2016100的表单中,有个字段为项目联系人想在上面添加联系人

#!/usr/bin/env python
#_*_ coding:utf-8 _*_

import odoorpc
import os
import sys
import time
import logging

if __name__ == "__main__"
    odoo = odoorpc.ODOO('172.16.0.67','jsonrpc','8069') #输入odoo的环境
    odoo.login('linxerp','admin','123456') #想要连接的数据库登陆名和密码
    coordination_env = odoo.env['work.coordination.order']#想要改的表名
    coordiantion_search = coordination_env.search([('name','=',"2016100")])#想要改的内容通过条件找出
    coordination_browse = coordination_env.browse(coordination_search)#浏览找到的内容
    print coordination_browse.name,coordination_browse.project_contract#打印出姓名和项目联系人

    person_env = odoo.env['res.partner']#浏览员工信息表
    person_search = person_env.search([('name','in',["xxx","xxx"])])#通过条件查找相应的员工
    person_browse = person_nev.browse(person_search)#获取查找的内容
    for a in person_browse
        print a.name
    coordination_browse.project_contract = person_browse#把查出来的员工姓名付于项目联系人

你可能感兴趣的:(odoo开发)