Odoo XML RPC 搜索和插入
Odoo XML RPC search and insert
我想使用他们的名字从 xl 中搜索 res.partner 中的客户,然后如果是,我在我在 xmlrpc 中创建的销售订单中分配他们的合作伙伴 ID,否则插入该合作伙伴并在销售订单中使用他的 ID我 creating.note 目的是将销售订单从 xls 文件迁移到 odoo,现在实际代码如下。
import psycopg2
import psycopg2.extras
import pyexcel_xls
import pyexcel as pe
from pyexcel_xls import get_data
from datetime import datetime
import xmlrpclib
import json
url = 'http://localhost:8070'
db = 'Docker'
username = 'admin'
password = 'odoo'
#data = get_data("salesorder.xls")
#print(json.dumps(data))
records = pe.get_records(file_name="salesorder.xls")
for record in records:
print record['name']
names = record['name']
print record['location']
print record['zip']
print record['republic']
dates = record['date']
print dates
print datetime.strptime(dates,'%d/%M/%Y')
lastdat=datetime.strptime(dates,'%d/%M/%Y')
common = xmlrpclib.ServerProxy('{}/xmlrpc/2/common'.format(url))
output = common.version()
models = xmlrpclib.ServerProxy('{}/xmlrpc/2/object'.format(url))
ids = models.execute_kw(db, uid, password,
'res.partner', 'search',
['name', '=', "names"])
uid = common.authenticate(db, username, password, {})
print output
models = xmlrpclib.ServerProxy('{}/xmlrpc/2/object'.format(url))
id = models.execute_kw(db, uid, password, 'sale.order', 'create', [{
'name': names,
'validity_date':"2016-01-18"
#'payment_term_id':"1"
# 'user_id':"1"
# 'state':"sale"
}])
print id
这是对您的脚本的修改,我认为应该可以。我没有研究应该将哪些值传递到销售订单的创建中。您必须确保传递正确的值。您还导入了一些您不使用的包,但我将它们保留在其中,因为我假设您计划使用它们。最重要的是,您需要在系统中搜索您的联系人。如果您找到他们,请使用该 ID,如果找不到,请创建联系人并使用新的联系人 ID 来创建您的销售订单。
import psycopg2
import psycopg2.extras
import pyexcel_xls
import pyexcel as pe
from pyexcel_xls import get_data
from datetime import datetime
import xmlrpclib
import json
url = 'http://localhost:8070'
db = 'Docker'
username = 'admin'
password = 'odoo'
models = xmlrpclib.ServerProxy('{}/xmlrpc/2/object'.format(url))
common = xmlrpclib.ServerProxy('{}/xmlrpc/2/common'.format(url))
uid = common.authenticate(db, username, password, {})
records = pe.get_records(file_name="salesorder.xls")
for record in records:
print record['name']
# DEFINE THE VALUES YOU PLAN ON PASSING INTO YOUR SALES ORDER HERE
vals = {
'name': record['name'],
'validity_date':"2016-01-18"
}
ids = models.execute_kw(db, uid, password, 'res.partner', 'search', [[['name', '=', names]]])
# IF YOU FIND THE CONTACT IN THE SYSTEM ADD THEIR ID TO YOUR VALS OBJECT
# IF YOU ARE CONFIDENT YOU DO NOT HAVE DUPLICATES OF NAMES THIS SHOULD WORK, OTHERWISE A MORE PRECISE SEARCH DOMAIN IS NECESSARY
if len(ids) > 0:
vals['partner_id'] = ids[0]
# IF YOU DONT FIND A MATCH YOU CAN CREATE A NEW PARTNER AND USE THAT ID
else:
vals['partner_id'] = models.execute_kw(db, uid, password, 'res.partner', 'create', [{ 'name': record['name'] }])
sale_order_id = models.execute_kw(db, uid, password, 'sale.order', 'create',[vals])
print sale_order_id
我想使用他们的名字从 xl 中搜索 res.partner 中的客户,然后如果是,我在我在 xmlrpc 中创建的销售订单中分配他们的合作伙伴 ID,否则插入该合作伙伴并在销售订单中使用他的 ID我 creating.note 目的是将销售订单从 xls 文件迁移到 odoo,现在实际代码如下。
import psycopg2
import psycopg2.extras
import pyexcel_xls
import pyexcel as pe
from pyexcel_xls import get_data
from datetime import datetime
import xmlrpclib
import json
url = 'http://localhost:8070'
db = 'Docker'
username = 'admin'
password = 'odoo'
#data = get_data("salesorder.xls")
#print(json.dumps(data))
records = pe.get_records(file_name="salesorder.xls")
for record in records:
print record['name']
names = record['name']
print record['location']
print record['zip']
print record['republic']
dates = record['date']
print dates
print datetime.strptime(dates,'%d/%M/%Y')
lastdat=datetime.strptime(dates,'%d/%M/%Y')
common = xmlrpclib.ServerProxy('{}/xmlrpc/2/common'.format(url))
output = common.version()
models = xmlrpclib.ServerProxy('{}/xmlrpc/2/object'.format(url))
ids = models.execute_kw(db, uid, password,
'res.partner', 'search',
['name', '=', "names"])
uid = common.authenticate(db, username, password, {})
print output
models = xmlrpclib.ServerProxy('{}/xmlrpc/2/object'.format(url))
id = models.execute_kw(db, uid, password, 'sale.order', 'create', [{
'name': names,
'validity_date':"2016-01-18"
#'payment_term_id':"1"
# 'user_id':"1"
# 'state':"sale"
}])
print id
这是对您的脚本的修改,我认为应该可以。我没有研究应该将哪些值传递到销售订单的创建中。您必须确保传递正确的值。您还导入了一些您不使用的包,但我将它们保留在其中,因为我假设您计划使用它们。最重要的是,您需要在系统中搜索您的联系人。如果您找到他们,请使用该 ID,如果找不到,请创建联系人并使用新的联系人 ID 来创建您的销售订单。
import psycopg2
import psycopg2.extras
import pyexcel_xls
import pyexcel as pe
from pyexcel_xls import get_data
from datetime import datetime
import xmlrpclib
import json
url = 'http://localhost:8070'
db = 'Docker'
username = 'admin'
password = 'odoo'
models = xmlrpclib.ServerProxy('{}/xmlrpc/2/object'.format(url))
common = xmlrpclib.ServerProxy('{}/xmlrpc/2/common'.format(url))
uid = common.authenticate(db, username, password, {})
records = pe.get_records(file_name="salesorder.xls")
for record in records:
print record['name']
# DEFINE THE VALUES YOU PLAN ON PASSING INTO YOUR SALES ORDER HERE
vals = {
'name': record['name'],
'validity_date':"2016-01-18"
}
ids = models.execute_kw(db, uid, password, 'res.partner', 'search', [[['name', '=', names]]])
# IF YOU FIND THE CONTACT IN THE SYSTEM ADD THEIR ID TO YOUR VALS OBJECT
# IF YOU ARE CONFIDENT YOU DO NOT HAVE DUPLICATES OF NAMES THIS SHOULD WORK, OTHERWISE A MORE PRECISE SEARCH DOMAIN IS NECESSARY
if len(ids) > 0:
vals['partner_id'] = ids[0]
# IF YOU DONT FIND A MATCH YOU CAN CREATE A NEW PARTNER AND USE THAT ID
else:
vals['partner_id'] = models.execute_kw(db, uid, password, 'res.partner', 'create', [{ 'name': record['name'] }])
sale_order_id = models.execute_kw(db, uid, password, 'sale.order', 'create',[vals])
print sale_order_id