N3mo
N3mo

Reputation: 3

odoo datamigration: Enter one product on several pricelists via odoorpc on python

I am working on a python import-script to import data from an xls sheet to odooErp. In the script, there is information like "name", "if it is a bom list" and (important) for "prices" for different pricelists (in this case p1-p4).

I am using the following versions: Odoo: Community v.12 python: v. 3.7.6 odoorpc: 0.7.0

My script is already able to find the products in the odoodb, take some of the xls-data and writes it to the product in the odoodb. These are field like name, price (which is the standard price), type, etc. (standard rpc calls) But I was not able to manage writing the product to a pricelist or to assign a pricelist to the product. I did not found any documentation about this step on how to manage the syntax for solving this. So I tried to do this:

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 
      })

Unfortunately even with no errors shown and receiving a "True" from the function this call is not successful and is doing nothing.

Now my questions are:

Cheers and thank you very much for your time :)

Upvotes: 0

Views: 145

Answers (1)

Hendra Juice
Hendra Juice

Reputation: 34

try this code:

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)] 
    })

you can read https://www.odoo.com/documentation/13.0/reference/orm.html#create-update as reference for One2many special command

Upvotes: 1

Related Questions