Odoo Help

Welcome!

This community 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.

0

Integrity Error while creating a bom manually

By
Patrik
on 5/11/15, 3:23 AM 592 views

Hi


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?

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

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


0
Patrik
On 5/13/15, 4:25 AM

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

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

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