[英]Python XML-RPC Export Import Program
我正在嘗試將 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")
我認為你在這一行有問題:-
--> 使用 open(csv_file, 'w', encoding='utf-8', newline='') 作為 csvfile:
所以在我看來,請刪除參數:-編碼和換行符。
我用項目模塊運行你的代碼,它完美地工作。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.