Skip to Content
Menu
This question has been flagged
1 Reply
2974 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. 

Avatar
Discard
Best Answer

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})
categ._parent_store_compute()
Avatar
Discard
Related Posts Replies Views Activity
0
Oct 23
356
0
Oct 23
485
0
Nov 20
2245
1
May 17
4595
2
Nov 24
248