Odoo Help

0

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

By
Renzo Meister
on 6/10/15, 1:46 AM 567 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. 

0

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()

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

Register

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)

Stats

Asked: 6/10/15, 1:46 AM
Seen: 567 times
Last updated: 8/28/15, 4:35 AM