I'm trying to validate an editable input defined in an object with many2many relationship with a Wizard, but the new value is not received when I have one item in the list. Whereas when the list is more then one item, all new values are received in backend except the last item!
The Scenario is:
case-1: when I have ONE item in list
1- when I open the Wizard and I hit on a button (fill_product_category) it fills the list of product category in the tree view
2- insert data in the new_price (editable input)
3- hit the compute_result button
4- the updated parameter is not received in the backend, the id of the item is kept normally
5- the wizard is not refreshed with the new value for editable input (it's normal since it's not sent at first submit)
case-2: when I have MORE than one item in the list of products:
- After inserting values in the editable fields and hitting compute_result-> all updated values are received except the last item
Explanation:
-Hitting the button will build a list of product category in Backend and then assign it to the Wizard-Hitting the compute_result will call the backend function and retrieve the list of product-inside this function I iterate thru products and fetch the new_price, I need to know how to edit and submit accordingly an input in wizard
thank you,
1- The Wizard includs one2many relationship
class wizard(models.TransientModel):
_name = 'simulator.wizard'
y_product_category_disc_ids = fields.many2many("category.model", "id",string="Product Category")
class CategoryModel(models.Model):
_name = "category.model"
y_product = fields.Char(string="Product Cat",readonly=True)
new_price= fields.Integer(string="New Price")
2- Snippet of the Wizard Data file
<field name="y_product_category_disc_ids">
<tree string="Product Category Tree" editable="true">
<field name="y_product"/> <field name="new_price"/> </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_product_category(self):
self.ensure_one()
res_record1 = self.env["purchase.product.categorydisc"].\
create({"y_product": p1,"new_price":0 })
listProdIds.append(res_record1.id)
#adding the second product can be omitted in order to add only one item to wizard
res_record2 = self.env["purchase.product.categorydisc"].\
create({"y_product": p2, "new_price":0})
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',
}
4- function that receives the new prices per items and make computation, where new_price is not received for first item
@api.multi def compute_result(self):
self.ensure_one()
product_category_disc_ids = self.y_product_category_disc_ids
for prod in product_category_disc_ids:
print("compute_result prod category={} new price={}").format(prod.y_product, prod.new_price)
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',
}