python通过xmlrpc连接odoo的postgresql

import xmlrpc.client
from pprint import pprint

url = "https://.odoo.com"
db = "-production-"
username = "admin"
password = "admin"
common = xmlrpc.client.ServerProxy('{}/xmlrpc/2/common'.format(url))
uid = common.authenticate(db, username, password, {})
models = xmlrpc.client.ServerProxy('{}/xmlrpc/2/object'.format(url))


def call_check_access_rights():
    data = models.execute_kw(db, uid, password,
                             'res.partner', 'check_access_rights',
                             ['read'], {'raise_exception': False})
    print(data)

# call_check_access_rights()


def list_all_records(): #search是查询id
    records_data = models.execute_kw(db, uid, password,
                                     'res.partner', 'search', [[]])
    print(records_data)

# list_all_records()


def list_records(): #search是查询id
    records_data = models.execute_kw(db, uid, password,
                                     'res.partner', 'search',
                                     [[('is_company', '=', True)]])
    print(records_data)

# list_records()


def count_records(): #search_count是计数
    records_count = models.execute_kw(db, uid, password,
                                      'res.partner', 'search_count',
                                      [[('is_company', '=', True)]])
    print(records_count)

# count_records()


def read_records(): #search是查询id。跳过0个 开始查询,并依次返回3笔
    # Read records
    ids = models.execute_kw(db, uid, password,
                            'res.partner', 'search',
                            [[['is_company', '=', True]]],
                            {'offset': 0, 'limit': 3})
    print('ids:', ids)
    return ids

# read_records()


def read_all_field(): #read是查询详细字段,这里返回所有的字段
    ids = read_records()
    # all field
    record = models.execute_kw(db, uid, password,
                               'res.partner', 'read', [ids])
    print('record')
    pprint(record)

# read_all_field()


def read_need_field(): #read是查询详细字段,这里返回想要看到的字段
    ids = read_records()
    # need field
    record = models.execute_kw(db, uid, password,
                               'res.partner', 'read',
                               [ids], {'fields': ['id', 'name', 'vat']})
    print('record')
    pprint(record)

# read_need_field()


def read_field_get(): #fields_get返回字段的类型、备注
    record = models.execute_kw(db, uid, password,
                               'res.partner', 'fields_get',
                               [], {'attributes': ['string', 'help', 'type']})
    print('record')
    pprint(record)

# read_field_get()


def search_and_read(): #search_read:终极简化,条件查询,按需显示
    record = models.execute_kw(db, uid, password,
                               'res.partner', 'search_read',
                               [[('vat', '=', '300048757700003'),
                                 ('name', '=', 'Alshaya Enterprises®')]], {'fields': ['id', 'name', 'email', 'vat']})
    print('record')
    pprint(record)

search_and_read()


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值