I am trying to simulate a session in my module using context, but so far, all my attempts have been in vain.
Here is what I did so far.
In the first view I set up a tree field that has a button for each entry. The button sets values from this model in the context.
<field name="block_pattern_ids">
<tree string="Block patterns">
<field name="block_pattern_id"/>
<button name="action_shorten_block" string="Shorten" class="oe_highlight" type="object" context="{'shorten_block_id': id, 'block_id': block_pattern_id}"/>
</tree>
</field>
these values are processed in the action which calls a wizard view
@api.multi
def action_shorten_block(self):
self.ensure_one()
view = self.env.ref('traffic.block_patterns_form_wizard_view', False)
bpid = self._context['shorten_block_id']
id = self._context['block_id']
ctx = self.env['traffic.departure.in.block'].with_context(shorten_block_id=bpid)._context
v = view.id
return {
'name': "Split block",
'type': 'ir.actions.act_window',
'view_type': 'form',
'view_mode': 'form',
'res_model': 'traffic.block.pattern',
'res_id': id,
'view_id': v,
'target': 'new',
'context': ctx,
}
Everything works as expected up to this point and the wizard is opened properly.
in that wizard I put another button which is supposed to retrieve the data from context and call an action.
<field name="departure_ids">
<tree>
<field name="name">
<button name="action_unlink_from_this" string="Unlink from this" class="oe_highlight" type="object" context="{'shorten_block_id': context.get('shorten_block_id', False)}"/>
</tree>
</field>
But in the action the variable returns False, and the context only has default values.
I have tried overriding default_get, fields_view_get, read, name_get in my wizard class, but as far as I was able to see, the context gets lost before these functions are called.
For clarity purposes, both buttons are in m2m tree views
How should I go about resolving this issue? Also, where can I learn more about context? Everything I have found so far is very scarce.