Context from One2many not updating

323 views Asked by At

I'm kinda new to Odoo (working on Odoo 8), I made a wizard that has a one2many field, referring to another Transient Model

I added a button inside the tree view that's supposed to display details of the line (each line has its button)

when i get the details for a line at the first time i do get the data i passed on the context, however the data doesn't update when i click details for another line, it displays the context i passed at first

any way i can fix this please ?

1

There are 1 answers

1
Kenly On BEST ANSWER

The first time Odoo calls the button, the action context is a list holding the button context attribute as a string:

Array [ "{'default_title':title, 'default_qty':qty}" ]

The next time it is called (without refreshing the page), the context is evaluated as a compound context and the evaluation context is wrong because it uses the values of the first record and this is why the default values did not change.

If you alter the evaluation context in the handle_button, Odoo should load the correct default values

Example:

if (action.context && action.context.__contexts) {
    action.context.__eval_context = this.records.get(id).toContext();
}

Solution

Instead of using the button context to set the default values, you can use directly the action context

Example:

@api.multi 
def open_details(self): 
    self.ensure_one()
    return {
        'name': "Details", 
        'view_type': 'form', 
        'view_mode': 'form', 
        'view_id': False, 
        'res_model': 'accommodation.details', 
        'type': 'ir.actions.act_window', 
        'target': 'new', 
        'context': {'default_title': self.title, 'default_qty': self.qty}
    }