odoo数据迁移:通过python上的odoorpc在多个价格表上输入一个产品

2024-06-07 00:33:45 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在编写一个python导入脚本,将数据从xls工作表导入odooErp。 在脚本中,有诸如“名称”、“如果是bom表”和(重要的)不同价格表(在本例中为p1-p4)的“价格”等信息

我正在使用以下版本: 奥多:社区v.12 python:v。3.7.6 ODORPC:0.7.0

我的脚本已经能够在odoodb中找到产品,获取一些xls数据并将其写入odoodb中的产品。 这些字段包括名称、价格(标准价格)、类型等(标准rpc调用) 但我无法将产品写入价格表或为产品分配价格表。 我没有找到任何关于如何管理解决此问题的语法的文档。 所以我试着这样做:

PricelistModel = odoo.env['product.pricelist'] pricelist = PricelistModel.search([('name', '=', 'p1')], limit=1) if pricelist: p = PricelistModel.browse(pricelist) item = { 'applied_on': '1_product', 'product_tmpl_id': product['id'], #<-- this is int also tried string 'compute_price': 'fixed', 'fixed_price': float(row[3]) #<--- this is int also tried string } p.write({ 'item_ids': item })

不幸的是,即使没有显示错误,并且从函数中接收到“True”,此调用也不会成功,并且什么也不做

现在我的问题是:

  • 我想用odoorpc做更多的事情,但是文档非常简短,甚至没有触及我所能想象的所有可能性的表面-&燃气轮机;有没有办法打印出为什么奥多没有写信给DB的答案,这样我就可以教自己如何与奥多“交谈”

  • 有人知道解决这个问题的方法吗

干杯,非常感谢您抽出时间:)


Tags: 数据文档脚本名称标准产品价格product
1条回答
网友
1楼 · 发布于 2024-06-07 00:33:45

请尝试以下代码:

PricelistModel = odoo.env['product.pricelist']
pricelist = PricelistModel.search([('name', '=', 'p1')], limit=1)
if pricelist:
    item = {
        'applied_on': '1_product',
        'product_tmpl_id': product['id'], #<  this is int also tried string
        'compute_price': 'fixed',
        'fixed_price': float(row[3]) #< - this is int also tried string
    }

    # I assume the 'item' is a correct dictionary and the 'item_ids' is a One2many field, so you need an One2many special command

    p.write({
        'item_ids': [(0, False, item)] 
    })

您可以读取https://www.odoo.com/documentation/13.0/reference/orm.html#create-update作为One2many特殊命令的参考

相关问题 更多 >