Odoo Help


Integrity Error while creating a bom manually

on 5/11/15, 3:23 AM 731 views


I have written a module which creates a product an then a bom an adds the bom to the product. On my development environment everything works fine but not on the productive server, both V8 installations.

Here some parts of the code.

class product_product_wizard(osv.osv):
_inherit = 'product.product'

def create(self, cr, uid, data, context=None):
# some code which fills all data for the new product
# after that I create the product with this line
id = super(product_product_wizard, self).create(cr, uid, data, context)

# now I create the bom
     product = self.browse(cr, uid, id)
     bom_obj = self.pool.get('mrp.bom')
     bom_line_obj = self.pool.get('mrp.bom.line')
parent_bom_id = bom_obj.create(cr, uid, {'name': product.name,
'code': data['default_code'],
'product_uom': product.product_tmpl_id.uom_id.id,
'product_tmpl_id': product.id})

But creating the bom gets me this error:

migration_debug openerp.sql_db: bad query: INSERT INTO "mrp_bom" ("id", "product_rounding", "code", "name", "product_uom", "company_id", "product_tmpl_id", "product_qty", "active", "product_efficiency", "type", "create_uid", "write_uid", "create_date", "write_date") VALUES(nextval('mrp_bom_id_seq'), 0.0, 'Test123', 'A4', 1, 1, 47342, '1.000', true, 1.0, 'normal', 1, 1, (now() at time zone 'UTC'), (now() at time zone 'UTC')) RETURNING id
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/openerp/sql_db.py", line 234, in execute
res = self._obj.execute(query, params)
IntegrityError: insert or update on table "mrp_bom" violates foreign key constraint "mrp_bom_product_tmpl_id_fkey"
DETAIL: Key (product_tmpl_id)=(47342) is not present in table "product_template".

It looks like the product is not created yet. I debugged the code, the id after creating the product is set. I don't get why on one installation this is working an not on the other.

Do you guys have any idea?

Sven Petersen
On 5/13/15, 7:24 AM

because the product id is not the product template id: product_tmpl_id': product.id}) ?

On 5/13/15, 4:25 AM

Anyone? I rewrote the module using v8 api, same error.

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)


Asked: 5/11/15, 3:23 AM
Seen: 731 times
Last updated: 5/13/15, 9:18 AM