我有一个Python脚本,可以创建从MSSQL到Postgresql(Odoo)的记录。我现在要尝试和做的是更新现有字段并创建它们是否尚不存在。我的脚本是
#Retrieve data through recordset
RecCount =rs.RecordCount
print RecCount
while not rs.EOF:
# print rs.Fields.item('Description').value
# print rs.Fields.item('Price').value
name = rs.Fields.item('Description').value
barcode = rs.Fields.item('ItemLookupCode').value
categ_id = rs.Fields.item('ItemLookupCode').value
record = {'name' : name, 'barcode' : barcode}
#recordbarcode = {'barcode' : barcode}
filter = [[['barcode' ,'=', barcode]]]
product_id = OdooApi.execute_kw(database, uid, pwd, 'product.template', 'search', filter)
if not product_id:
print " Create - " + barcode
resultset = OdooApi.execute_kw(database, uid, pwd, 'product.template', 'create', [record] )
#product_id = OdooApi.execute_kw(database, uid, pwd, 'product.template', 'create', product_id)
else:
print "Product Barcode is already in the table - " + barcode
#resultset = OdooApi.execute_kw(database, uid, pwd,
# 'product.template', 'search', [record]
#resultset = OdooApi.execute_kw(database, uid, pwd,
#'product.template', 'create', [record])
# filter, {'fields': ['name','list_price'], 'limit': 50})
rs.Move(1)
我尝试了以下但我得到了result = method(recs, *args, **kwargs)\nTypeError: write() takes exactly 2 arguments (1 given)\n'>
未更新的代码
print RecCount
while not rs.EOF:
# print rs.Fields.item('Description').value
# print rs.Fields.item('Price').value
name = rs.Fields.item('Description').value
barcode = rs.Fields.item('ItemLookupCode').value
categ_id = rs.Fields.item('ItemLookupCode').value
record = {'name' : name, 'barcode' : barcode}
#recordbarcode = {'barcode' : barcode}
#filter = [[['barcode' ,'=', barcode]]]
#product_id = OdooApi.execute_kw(database, uid, pwd, 'product.template', 'search', filter)
#if not product_id:
# print " Create - " + barcode
# resultset = OdooApi.execute_kw(database, uid, pwd, 'product.template', 'write', [record] )
#product_id = OdooApi.execute_kw(database, uid, pwd, 'product.template', 'create', product_id)
result = OdooApi.execute_kw(database, uid, pwd, 'product.template', 'write', [record] )
#else:
#print "Product Barcode is already in the table - " + barcode
#resultset = OdooApi.execute_kw(database, uid, pwd,
# 'product.template', 'search', [record]
#resultset = OdooApi.execute_kw(database, uid, pwd,
#'product.template', 'create', [record])
# filter, {'fields': ['name','list_price'], 'limit': 50})
rs.Move(1)
答案 0 :(得分:0)
您调用write
方法,但要写入哪条记录?
当您使用xmlrpc在Odoo服务器上调用write方法时,您需要传递两个参数:
1)product.template
模块上要将这些record
值写入的{field:value_of_field}
模块上的记录的ID。
2)包含create
值的实际字典。
当您使用write
方法时,您会返回一个ID,将const agendaPointsReducer = function (state = initialState, action) {
switch (action.type) {
case OPEN_AGENDA_POINT: {
return {
...state,
modal_is_open: true,
point_id: action.id
};
}
case CLOSE_AGENDA_POINT: {
return {
...state,
modal_is_open: false,
};
}
}
}
方法上的该ID与您要写入的值一起传递。