博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
odoo二次开发
阅读量:6810 次
发布时间:2019-06-26

本文共 3644 字,大约阅读时间需要 12 分钟。

  hot3.png

#odoo Odoo 的前身是 OpenERP,是一个开源的企业 ERP 系统。

通过官网可以看到odoo可以干很多事情,例如销售、CRM等等。
#odoo文档 我们可以在看到用户手册、开发者文档、API、安装说明、白皮书、法律文件。
由于我们要对odoo进行二次开发,则我们需要访问API文档。 #Web Service API 在odoo文档-API部分,我们将会访问的是web Service API,通过该文档,我们可以了解到,odoo的API通信方式,是通过xmlrpc方式进行远程调用。

#测试代码

# encoding=utf8import xmlrpclib# Connectionurl = "https://demo.odoo.com"db = ""username = "admin"password = "admin"# 通过demo服务器的start函数获取,实际测试的服务器的url,db,username,passwordinfo = xmlrpclib.ServerProxy('https://demo.odoo.com/start').start()url, db, username, password = info['host'], info['database'], info['user'], info['password']print "[url]:" + urlprint "[db]:" + dbprint "[username]:" + usernameprint "[password]:" + password# Loggingcommon = xmlrpclib.ServerProxy('{}/xmlrpc/2/common'.format(url))print "Method version:" + str(common.version())uid = common.authenticate(db, username, password, {})# print "[uid]:" + str(uid)# # Calling methodsmodels = xmlrpclib.ServerProxy('{}/xmlrpc/2/object'.format(url))result = models.execute_kw(db, uid, password,                  'res.partner', 'check_access_rights',                  ['read'], {'raise_exception': False})print result# Create recordsid = models.execute_kw(db, uid, password, 'res.partner', 'create', [{    'name': "中文测试",}])print "[id]:" + str(id)[record] = models.execute_kw(db, uid, password,    'res.partner', 'read', [id])print record

#形成类 20160816添加测试类 ##测试类

from unittest import TestCaseimport datetimefrom OdooServerApi import OdooServerApiclass TestOdooServerApi(TestCase):    def test_get_uid(self):        print "test_get_uid"        server = OdooServerApi()        print "[uid]:" + str(server.get_uid())        pass    def test_get_mac_address(self):        server = OdooServerApi()        print "[mac_address]:" + str(server.get_mac_address())        pass    def test_update(self):        start_time = datetime.datetime.now() - datetime.timedelta(hours=8)        print start_time        end_time = start_time + datetime.timedelta(hours=10)        print end_time        server = OdooServerApi()        server.update(start_time,end_time)        pass

##OdooServerApi类

import uuidimport xmlrpclibclass OdooServerApi:    url = "http://192.168.1.120:8069"    db = "Workload Account"    username = "testimporter@test.test"    password = "123456"    uid = None    mac_address = None    def __init__(self, url=None,db=None,username=None,password=None):        if url is not None:            self.url = url        if db is not None:            self.db = db        if username is not None:            self.username = username        if password is not None:            self.password = password    def get_uid(self):        common = xmlrpclib.ServerProxy('{}/xmlrpc/2/common'.format(self.url))        print "Method version:" + str(common.version())        uid = common.authenticate(self.db, self.username, self.password, {})        print "[uid]:" + str(uid)        self.uid = uid        return self.uid    def get_mac_address(self):        mac = uuid.UUID(int=uuid.getnode()).hex[-12:]        self.mac_address = ":".join([mac[e:e+2] for e in range(0,11,2)])        return self.mac_address    def update(self, start_time, end_time, mac_address=None,uid=None):        if uid is None:            self.get_uid()        if mac_address is None:            self.get_mac_address()        models = xmlrpclib.ServerProxy('{}/xmlrpc/2/object'.format(self.url))        models.execute_kw(self.db, self.uid, self.password, 'workload_account.raw_data', 'create', [{            'mac_address': self.mac_address,            'start_time': str(start_time),            'end_time': str(end_time)        }])

转载于:https://my.oschina.net/hava/blog/731865

你可能感兴趣的文章