Odoo Help

0

Odoo 8 - wizard not showing one2many elements

By
Salim Rahal
on 11/16/16, 10:35 AM 755 views

I'm trying to populate a one2many relationship in a Wizard, the wizard contains a reference one2many to product categories(a Model). The Scenario is when I open the Wizard and I hit on a button (fill_product_category) it fill the list of product category in the tree view.

Hitting the button will build a list of product category in Backend and then assign it to the Wizard

The result is that only the first element of product category list is rendered in the wizard, whereas the others are not rendered. My code shows two static product categories but only the first one is rendered.

I need to show all the list what I should do?

thank you

1- The Wizard includs one2many relationship

<pre>

  class wizard(models.TransientModel):

    _name = 'simulator.wizard'

    y_product_category_disc_ids = fields.One2many("category.model", "id",string="Product Category")

  class CategoryModel(models.Model):

       _name = "category.model"

        y_product = fields.Char(string="Product Cat",readonly=True)

</pre>

2- Snippet of the Wizard Data file

       <field name="y_product_category_disc_ids"> <tree string="Product Category Tree"> <field name="y_product"/> </tree>

       </field> <button name="fill_product_category" string="Fill product category" type="object" />

3- function that handle the button fill_product_category

@api.multi def fill_one2many(self):

    self.ensure_one()

    res_record1 = self.env["purchase.product.categorydisc"].\

create({"y_product": p1 })

res_record2 = self.env["purchase.product.categorydisc"].\

create({"y_product": p2 })

listProdIds.append(res_record1.id)

listProdIds.append(res_record2.id)

self.y_product_category_disc_ids = listProdIds

return {

'context': self.env.context,

'view_type': 'form',

'view_mode': 'form',

'res_model': 'simulator.wizard',

'res_id': self.id, 'view_id': False,

'type': 'ir.actions.act_window',

'target': 'new',

}


p1 and p2 are variables or string values?

Axel Mendoza
on 11/16/16, 2:44 PM

p1 and p2 are String

Salim Rahal
on 11/16/16, 3:57 PM
1
Axel Mendoza
On 11/16/16, 2:41 PM

You need to use a Many2many field because One2many fields need a Many2one relation field to the current model in the target model of the One2many. With Many2Many fields you remove that contraints  

yes it works with many2many relation and the tree view of the sub elements is rendered. note that I couldn't define the two way references of many2one and one2many because a Model (e.g. CategoryModel) cannot define a reference to a Tranient Model, but a transient model can do it. any way thank you @Axel

Salim Rahal
on 11/16/16, 4:46 PM

Please then upvote the answer to help others

Axel Mendoza
on 11/16/16, 5:36 PM

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: 11/16/16, 10:35 AM
Seen: 755 times
Last updated: 11/16/16, 4:46 PM