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

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

By
Renzo Meister
on 6/10/15, 1:46 AM 488 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 community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

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