Search code examples
pythonodoo

How to search via production_id?


I am attempting to get a field from a manufacturing order to a related work order.

I have tried:

for record in records:
  if record.production_id:
    so = env['mrp.production'].search([('name', '=', record.production_id)])
    if so:
      record.write({"x_customer": so.x_customer_nick_name})

This however does not work, but if I do a search of the actual production ID name for manufacturing name it works as intended:

for record in records:
  if record.production_id:
    so = env['mrp.production'].search([('name', '=', record.'Boost/BoMO/73222')])
    if so:
      record.write({"x_customer": so.x_customer_nick_name})

I believe this is due to production_id, from the raw data I can see it is [11212,'Boost/BoMO/73222'].

So I only need the first element, however:

 so = env['mrp.production'].search([('name', '=', record.production_id[1])])

does not return the string name of the production_id. How should I go about getting this data?

Error Code

 pobjs = [adapt(o) for o in self._seq]\npsycopg2.ProgrammingError: can\'t adapt type \'dict\'\n'>

Solution

  • Wasn't able to find a solution here or on the odoo forums. For anyone else looking for a solution, I ended up using the web API. I scraped the work orders and the production ID manufacture orders. Built a tuple wrote to WO with a loop.

      models.execute_kw(db, uid, password, 'mrp.workorder', 'write', [workorders_id, {
                    'x_for_customer': x_customer_nick_name}
                }])