Odoo Help


Product Category creation on unit test does not set parent_left / parent_right

Renzo Meister
on 6/10/15, 1:46 AM 945 views

 I create some product categories in SetUp method for my unit tests: 

self.product_category1 = self.env['product.category'].create({ 
'name': 'Product Category 1', }) self.product_category1_1 = self.env['product.category'].create({ 'name': 'Product Category 1.1', 'parent_id': self.product_category1.id, )
Then I try to access the parent_left / parent_right fields either directly on self.product_category1.parent_left, or with a self.env['product_category'].browse(self.product_category1.id).parent_left, but the fields value is always 0. The same problem exists with partner tags hierarchy. 

These are my first steps with unit tests on newest API so I am not sure if there is a bug or if I make something wrong. 


Hi Renzo,

during the install the compute of the parent_store (left/right) is deferred at the end. And the unit test is run before the compute, you must compute yourself 

categ = self.env['product.category']
self.product_category1 = categ.create({
    'name': 'Product Category 1'}) self.product_category1_1 = categ.create({ 'name': 'Product Category 1.1', 'parent_id': self.product_category1.id})

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: 6/10/15, 1:46 AM
Seen: 945 times
Last updated: 8/28/15, 4:35 AM