Lets say Wizard_1 opens new window with List view, at the same time sets some important key/value pairs in a context. Then Wizard_2 starts from this window by click on some row in the list ( action is bound to: tree_but_open). Then Wizard_3 can be started from the window opened by Wizard_2 by the same way and so on. Is there way to preserve the context set by Wizard_1 and use values from that context in Wizard_2 (and so on) ?
In the scenario described above in Wizard_2 I'm getting new default context, instead of context set by Wizard_1, I need the context that I've set in Wizard_1. How to achieve that?
UPDATE:
(the example code correcponding to above described scenario):
XML:
================
<?xml version="1.0"?>
<openerp>
<data>
<record id="view_test_but_open" model="ir.ui.view">
<field name="name">test.partners.wizard.form</field>
<field name="model">test.partners.wizard</field>
<field name="arch" type="xml">
<form string="Partners Game" version="7.0">
<separator colspan="4" string="Do you really want to start new game?"/>
<footer>
<button string="New Game" name="test_partners_open_window" type="object" class="oe_highlight"/>
or
<button string="Cancel" class="oe_link" special="cancel"/>
</footer>
</form>
</field>
</record>
<record id="action_test_but_open" model="ir.actions.act_window">
<field name="name">Partners Game</field>
<field name="res_model">test.partners.wizard</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<field name="view_id" ref="view_test_but_open"/>
<field name="target">new</field>
</record>
<menuitem id="test_but_open_main"
name="DEVELOPMENT"
/>
<menuitem id="test_but_open_sub_section"
name="Games"
parent="test_but_open_main"
/>
<menuitem id="test_but_open_sub"
parent="test_but_open_sub_section"
name="Partners Game"
action="action_test_but_open"
/>
<record id="action_partners_game_tree_1" model="ir.actions.act_window">
<field name="name">Partners Game</field>
<field name="res_model">res.partner</field>
<field name="view_type">tree</field>
<field name="view_id" ref="base.view_partner_tree"/>
</record>
<record id="view_test_next_level" model="ir.ui.view">
<field name="name">view.test.next.level.form</field>
<field name="model">test.partners.level.wizard</field>
<field name="arch" type="xml">
<form string="Partners Game - Next Level" version="7.0">
<separator colspan="4" string="Do you really want to go to next level of game?"/>
<footer>
<button string="Next Level" name="next_level" type="object" class="oe_highlight"/>
or
<button string="Cancel" class="oe_link" special="cancel"/>
</footer>
</form>
</field>
</record>
<record id="action_next_level" model="ir.actions.act_window">
<field name="name">Next Level</field>
<field name="res_model">test.partners.level.wizard</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<field name="view_id" ref="view_test_next_level"/>
<field name="target">new</field>
</record>
<record model="ir.values" id="ir_open_next_level">
<field name="key">action</field>
<field name="key2">tree_but_open</field>
<field name="model">res.partner</field>
<field name="name">Next Level</field>
<field name="value" eval="'ir.actions.act_window,%d'%action_next_level"/>
<field name="object" eval="True"/>
</record>
</data>
</openerp>
PYTHON:
================
# -*- coding: utf-8 -*-
from openerp.osv import fields, osv
import random
random.seed()
class test_partners_wizard(osv.osv_memory):
_name = "test.partners.wizard"
_description = "Testing tree_but_open for context durability"
_columns = {
}
_defaults = {
}
def test_partners_open_window(self, cr, uid, ids, context=None):
mod_obj = self.pool.get('ir.model.data')
act_obj = self.pool.get('ir.actions.act_window')
if context is None:
context = {}
result = mod_obj.get_object_reference(cr, uid, 'test_but_open', 'action_partners_game_tree_1')
id = result and result[1] or False
result = act_obj.read(cr, uid, [id], context=context)[0]
important_value = random.randint(1,100)
print '[step1] IMPORTANT_VALUE: %s' %important_value # print the important_vaule...
result['context'] = str({'important_value':important_value})
return result
test_partners_wizard()
class test_partners_level_wizard(osv.osv_memory):
_name = "test.partners.level.wizard"
_description = "Move game to next level"
_columns = {
}
_defaults = {
}
def next_level(self, cr, uid, ids, context=None):
if context == None:
context = {}
print '[step2] IMPORTANT_VALUE: %s' %context.get('important_value',False) # it prints: "[step2] IMPORTANT_VALUE: False", i.e. the important_value is lost for the moment. Any suggestions?
# ....
test_partners_level_wizard()
#
# ....then Wizard3 and stuff like that
#
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
How to carry forward values in a context from the first wizard to the second in above code?