Odoo create stock.move.line

162 views Asked by At

when i try to create stock move line in transfer with automation with the following code, error pop up saying "psycopg2.errors.InFailedSqlTransaction: current transaction is aborted, commands ignored until end of transaction block".

The code:

result=[]

result.append(
  {'company_id':record.partner_id.id,
  'date':record.date,
  'location_dest_id':5,
  'location_id':8 ,
  'product_uom_qty':1,
  'product_uom_id':32,
  'product_id':465
  })

env['stock.move.line'].create(result)

May I ask any idea what is the problem with my code or how can i programmtically create stock move line. Thanks

1

There are 1 answers

0
Kenly On

You set the company_id to the partner_id which may not be present in res.company table and if it happens you should see the following error message:

DETAIL:  Key (company_id)=(...) is not present in table "res_company".

This will prevent Odoo from creating a stock move line, try to set the company_id to self.env.user.company_id.id

Note that since v12 Odoo supports passing a list of values to create function