Hi, For some times, I'm thinking about a better design for wizards. The goals are:
- Better self validation by using object instead of dict
- More expressive
- Less magic tricks
So here is the result, it is just some snipet code that has no meaning but
just show the design principles:
class Button(object):
state = ''
label = ''
icon = ''
default = False
class State(object):
pass
class StateForm(State):
model = None
buttons = []
default = '' #method name: func()
class StateChoice(State):
next_state = '' # method name: func()
class StateAction(StateChoice):
action = '' #method name: func()
class Session(ModelSQL):
'Store data of running wizard'
_name = 'ir.wizard.session'
data = fields.Binary() # Store the Form data
class Example(Wizard):
start = 'init'
end = 'end'
init = StateForm('account.invoice', buttons=[Button('Cancel'), Button('ok',
'step2')],
default='default_invoice')
step2 = StateAction('action_step2', 'next_step2')
def default_invoice(self):
return {
'code': 'ABC',
}
def action_step2(self):
party_obj = Pool().get('party.party')
# self.init.party is a BrowseRecord for the party filled in init Form
party_obj.write(self.init.party.id, {'invoiced': True})
def next_step2(self):
return 'end'
--
Cédric Krier
B2CK SPRL
Rue de Rotterdam, 4
4000 Liège
Belgium
Tel: +32 472 54 46 59
Email/Jabber: [email protected]
Website: http://www.b2ck.com/
pgpN1zbSDw3wL.pgp
Description: PGP signature
