【问题标题】:Python XML-RPC Export Import ProgramPython XML-RPC 导出导入程序
【发布时间】:2019-07-29 09:40:19
【问题描述】:

我正在尝试将 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")

【问题讨论】:

    标签: python-3.x export-to-csv xml-rpc odoo-12 xmlrpcclient


    【解决方案1】:

    我认为你在这一行有问题:-

    --> 用 open(csv_file, 'w', encoding='utf-8', newline='') as csvfile:

    所以在我看来,请删除参数:- 编码和换行符。

    我使用项目模块运行您的代码,它运行良好。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-12-30
      • 1970-01-01
      • 2021-04-04
      • 1970-01-01
      • 1970-01-01
      • 2019-04-08
      • 1970-01-01
      • 2020-04-09
      相关资源
      最近更新 更多