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?
p1 and p2 are String