我正在尝试将many2one字段传递给另一个数据库。现在,我的程序正在使用xmlrpc进入一个数据库,并从一个名为product.template的表中获取数据,然后创建一个csv。我要传递的字段与其他字段一起返回"54,'PARTS / COST'“。我只需要54,也就是id。你知道该从哪里截取这个问题或者如何解决它吗?这是我到目前为止得到的两个方法。
def FetchProducts(self):
products = self.odoo_object.execute_kw(
self.db,
self.uid,
self.password,
'product.template',
'search_read',
[[['sale_ok', '=', True], ['purchase_ok', '=', True]]],
{'fields': ['id', 'name', 'sale_ok', 'purchase_ok', 'type', 'default_code', 'barcode', 'list_price', 'standard_price', 'categ_id'], 'limit': 1}
)
return products
def ProductsCSV(self,products):
csv_columns = ['id', 'name', 'sale_ok', 'purchase_ok', 'type', 'default_code', 'barcode', 'list_price', 'standard_price', 'categ_id']
csv_file = "Products.csv"
try:
with open(csv_file, 'w', encoding='utf-8', newline='') as csvfile:
writer = csv.DictWriter(csvfile, csv_columns, delimiter=',')
writer.writeheader()
for data in products:
writer.writerow(data)
print("Writing Products " + str(data))
except IOError:
print("I/O error")
发布于 2020-01-02 05:34:04
我认为你在这一行有问题:
--> with open(csv_file,'w',encoding='utf-8',newline='')作为utf文件:
因此,在我看来,请删除参数:- encoding和newline。
我用project模块运行你的代码,它工作得很好。
https://stackoverflow.com/questions/55044865
复制相似问题