Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
2 Trả lời
4955 Lượt xem

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?

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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


Ảnh đại diện
Huỷ bỏ
Tác giả Câu trả lời hay nhất

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

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
Cost Break Up Đã xử lý
2
thg 5 24
1205
3
thg 1 24
1478
0
thg 9 23
1587
1
thg 5 23
2486
0
thg 7 19
2638