PageRenderTime 145ms CodeModel.GetById 9ms RepoModel.GetById 1ms app.codeStats 0ms

/extra addons/extra addons/extra-trunk/base_create_menu/wizard/menu_wizard.py

http://hornerp.googlecode.com/
Python | 221 lines | 198 code | 3 blank | 20 comment | 0 complexity | cec4d410c49497e5ca930adfc11ee82a MD5 | raw file
Possible License(s): MIT, MPL-2.0-no-copyleft-exception, GPL-2.0, GPL-3.0
  1. # -*- encoding: utf-8 -*-
  2. ##############################################################################
  3. #
  4. # OpenERP, Open Source Management Solution
  5. # Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
  6. #
  7. # This program is free software: you can redistribute it and/or modify
  8. # it under the terms of the GNU Affero General Public License as
  9. # published by the Free Software Foundation, either version 3 of the
  10. # License, or (at your option) any later version.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU Affero General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU Affero General Public License
  18. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. #
  20. ##############################################################################
  21. import wizard
  22. import osv
  23. import pooler
  24. icons = map(lambda x: (x,x), ['STOCK_ABOUT', 'STOCK_ADD', 'STOCK_APPLY', 'STOCK_BOLD',
  25. 'STOCK_CANCEL', 'STOCK_CDROM', 'STOCK_CLEAR', 'STOCK_CLOSE', 'STOCK_COLOR_PICKER',
  26. 'STOCK_CONNECT', 'STOCK_CONVERT', 'STOCK_COPY', 'STOCK_CUT', 'STOCK_DELETE',
  27. 'STOCK_DIALOG_AUTHENTICATION', 'STOCK_DIALOG_ERROR', 'STOCK_DIALOG_INFO',
  28. 'STOCK_DIALOG_QUESTION', 'STOCK_DIALOG_WARNING', 'STOCK_DIRECTORY', 'STOCK_DISCONNECT',
  29. 'STOCK_DND', 'STOCK_DND_MULTIPLE', 'STOCK_EDIT', 'STOCK_EXECUTE', 'STOCK_FILE',
  30. 'STOCK_FIND', 'STOCK_FIND_AND_REPLACE', 'STOCK_FLOPPY', 'STOCK_GOTO_BOTTOM',
  31. 'STOCK_GOTO_FIRST', 'STOCK_GOTO_LAST', 'STOCK_GOTO_TOP', 'STOCK_GO_BACK',
  32. 'STOCK_GO_DOWN', 'STOCK_GO_FORWARD', 'STOCK_GO_UP', 'STOCK_HARDDISK',
  33. 'STOCK_HELP', 'STOCK_HOME', 'STOCK_INDENT', 'STOCK_INDEX', 'STOCK_ITALIC',
  34. 'STOCK_JUMP_TO', 'STOCK_JUSTIFY_CENTER', 'STOCK_JUSTIFY_FILL',
  35. 'STOCK_JUSTIFY_LEFT', 'STOCK_JUSTIFY_RIGHT', 'STOCK_MEDIA_FORWARD',
  36. 'STOCK_MEDIA_NEXT', 'STOCK_MEDIA_PAUSE', 'STOCK_MEDIA_PLAY',
  37. 'STOCK_MEDIA_PREVIOUS', 'STOCK_MEDIA_RECORD', 'STOCK_MEDIA_REWIND',
  38. 'STOCK_MEDIA_STOP', 'STOCK_MISSING_IMAGE', 'STOCK_NETWORK', 'STOCK_NEW',
  39. 'STOCK_NO', 'STOCK_OK', 'STOCK_OPEN', 'STOCK_PASTE', 'STOCK_PREFERENCES',
  40. 'STOCK_PRINT', 'STOCK_PRINT_PREVIEW', 'STOCK_PROPERTIES', 'STOCK_QUIT',
  41. 'STOCK_REDO', 'STOCK_REFRESH', 'STOCK_REMOVE', 'STOCK_REVERT_TO_SAVED',
  42. 'STOCK_SAVE', 'STOCK_SAVE_AS', 'STOCK_SELECT_COLOR', 'STOCK_SELECT_FONT',
  43. 'STOCK_SORT_ASCENDING', 'STOCK_SORT_DESCENDING', 'STOCK_SPELL_CHECK',
  44. 'STOCK_STOP', 'STOCK_STRIKETHROUGH', 'STOCK_UNDELETE', 'STOCK_UNDERLINE',
  45. 'STOCK_UNDO', 'STOCK_UNINDENT', 'STOCK_YES', 'STOCK_ZOOM_100',
  46. 'STOCK_ZOOM_FIT', 'STOCK_ZOOM_IN', 'STOCK_ZOOM_OUT',
  47. 'terp-account', 'terp-crm', 'terp-mrp', 'terp-product', 'terp-purchase',
  48. 'terp-sale', 'terp-tools', 'terp-administration', 'terp-hr', 'terp-partner',
  49. 'terp-project', 'terp-report', 'terp-stock', 'terp-calendar', 'terp-graph',
  50. ])
  51. main_form = '''<?xml version="1.0"?>
  52. <form string="Select Appropriate Model">
  53. <field name="model_name"/>
  54. </form>'''
  55. main_fields = {
  56. 'model_name': {'string':'Model Name', 'type':'many2one', 'relation':'ir.model','required':True},
  57. }
  58. def _cheak_context(self, cr, uid, data, context):
  59. # context['model']='res.partner'
  60. if context.has_key('model'):
  61. if context['model']:
  62. return 'secondform'
  63. else:
  64. return 'firstform'
  65. else:
  66. return 'firstform'
  67. def _domain(self, cr, uid, data, context):
  68. if data['form'].has_key('model_name') and data['form']['model_name']:
  69. model = pooler.get_pool(cr.dbname).get('ir.model').read(cr, uid,data['form']['model_name'],['model'])
  70. model_data=model['model']
  71. return {'in_model_name':model_data}
  72. else:
  73. model_data = context['model']
  74. return {'in_model_name':model_data}
  75. second_form = '''<?xml version="1.0"?>
  76. <form string="Select Appropriate Model View">
  77. <separator colspan="4" string="Select view and its Sequence" />
  78. <field name="in_model_name" invisible="True" />
  79. <field name="form_view" domain="[('inherit_id','=',False),('type','=','form'),('model','=',in_model_name)]"/>
  80. <field name="form_seq"/>
  81. <field name="tree_view" domain="[('inherit_id','=',False),('type','=','tree'),('model','=',in_model_name)]"/>
  82. <field name="tree_seq"/>
  83. <field name="graph_view" domain="[('inherit_id','=',False),('type','=','graph'),('model','=',in_model_name)]"/>
  84. <field name="graph_seq"/>
  85. <field name="calander_view" domain="[('inherit_id','=',False),('type','=','calendar'),('model','=',in_model_name)]"/>
  86. <field name="cal_seq"/>
  87. </form>'''
  88. second_fields = {
  89. 'in_model_name':{'string':'View Sequence', 'type':'char','size':64, 'readonly':True},
  90. 'form_view': {'string':'Form View', 'type':'many2one','relation':'ir.ui.view'},
  91. 'tree_view': {'string':'Tree View', 'type':'many2one', 'relation':'ir.ui.view'},
  92. 'graph_view': {'string':'Graph View', 'type':'many2one', 'relation':'ir.ui.view'},
  93. 'calander_view': {'string':'Calander View', 'type':'many2one', 'relation':'ir.ui.view'},
  94. 'form_seq': {'string':'Form Sequence', 'type':'integer','size':32},
  95. 'tree_seq': {'string':'Tree Sequence', 'type':'integer','size':32},
  96. 'graph_seq': {'string':'Graph Sequence', 'type':'integer','size':32},
  97. 'cal_seq': {'string':'Calander Sequence', 'type':'integer','size':32},
  98. }
  99. next_form = '''<?xml version="1.0"?>
  100. <form string="Create Menu">
  101. <field name="menu_name"/>
  102. <field name="partner_menu"/>
  103. <field name="sequence"/>
  104. <field name="icon"/>
  105. <field name="group" colspan="4"/>
  106. </form>'''
  107. next_fields = {
  108. 'menu_name': {'string':'Menu Name', 'type':'char', 'size':64,'required':True},
  109. 'partner_menu': {'string':'Partner Menu', 'type':'many2one', 'relation':'ir.ui.menu','required':True},
  110. 'sequence': {'string':'Sequence', 'type':'integer', 'size':64,'required':True},
  111. 'group': {'string':'Group', 'type':'many2many', 'relation':'res.groups'},
  112. 'icon': {
  113. 'string': 'Icon',
  114. 'type': 'selection',
  115. 'selection':icons ,
  116. 'default' :lambda *b:'STOCK_JUSTIFY_FILL'
  117. },
  118. }
  119. def menu_create1(self, cr, uid, data, context):
  120. # context['model']='res.partner'
  121. view_mode = 'form,tree'
  122. icon_data = data['form']['icon'],
  123. menu_id=pool.get('ir.ui.menu').create(cr, uid, {
  124. 'name': data['form']['menu_name'],
  125. 'parent_id': data['form']['partner_menu'],
  126. 'icon':icon_data[0],
  127. 'sequence':data['form']['sequence'],
  128. 'groups_id':data['form']['group'],
  129. })
  130. if data['form'].has_key('model_name') and data['form']['model_name']:
  131. model = pooler.get_pool(cr.dbname).get('ir.model').read(cr, uid, [data['form']['model_name']],['model'])[0]['model']
  132. else:
  133. model=context['model']
  134. action_id = pooler.get_pool(cr.dbname).get('ir.actions.act_window').create(cr,uid, {
  135. 'name': data['form']['menu_name']+'New',
  136. 'res_model':model,
  137. 'view_type': 'form',
  138. 'view_mode': view_mode,
  139. })
  140. if data['form']['form_view']:
  141. view_action_id = pooler.get_pool(cr.dbname).get('ir.actions.act_window.view').create(cr,uid, {
  142. 'view_mode': 'form',
  143. 'act_window_id':action_id,
  144. 'sequence':data['form']['form_seq'],
  145. 'view_id':data['form']['form_view'],
  146. })
  147. if data['form']['tree_view']:
  148. view_action_id = pooler.get_pool(cr.dbname).get('ir.actions.act_window.view').create(cr,uid, {
  149. 'view_mode': 'tree',
  150. 'act_window_id':action_id,
  151. 'sequence':data['form']['tree_seq'],
  152. 'view_id':data['form']['tree_view'],
  153. })
  154. if data['form']['graph_view']:
  155. view_action_id = pooler.get_pool(cr.dbname).get('ir.actions.act_window.view').create(cr,uid, {
  156. 'view_mode': 'graph',
  157. 'act_window_id':action_id,
  158. 'sequence':data['form']['graph_seq'],
  159. 'view_id':data['form']['graph_view'],
  160. })
  161. if data['form']['calander_view']:
  162. view_action_id = pooler.get_pool(cr.dbname).get('ir.actions.act_window.view').create(cr,uid, {
  163. 'view_mode': 'calendar',
  164. 'act_window_id':action_id,
  165. 'sequence':data['form']['cal_seq'],
  166. 'view_id':data['form']['calander_view'],
  167. })
  168. pooler.get_pool(cr.dbname).get('ir.values').create(cr, uid, {
  169. 'name': 'Open Cases',
  170. 'key2': 'tree_but_open',
  171. 'model': 'ir.ui.menu',
  172. 'res_id': menu_id,
  173. 'value': 'ir.actions.act_window,%d'%action_id,
  174. 'object': True
  175. })
  176. return {}
  177. class wizard_create_menu(wizard.interface):
  178. states = {
  179. 'init': {
  180. 'actions': [],
  181. 'result': {'type':'choice','next_state':_cheak_context}
  182. },
  183. 'firstform': {
  184. 'actions': [],
  185. 'result': {'type':'form', 'arch':main_form, 'fields':main_fields, 'state':[('end','Cancel'),('secondform','Next')]}
  186. },
  187. 'secondform': {
  188. 'actions': [_domain],
  189. 'result': {'type':'form', 'arch':second_form, 'fields':second_fields, 'state':[('end','Cancel'),('next','Next')]}
  190. },
  191. 'next': {
  192. 'actions': [],
  193. 'result': {'type':'form', 'arch':next_form, 'fields':next_fields, 'state':[('end','Cancel'),('create','Create menu')]}
  194. },
  195. 'create': {
  196. 'actions': [menu_create1],
  197. 'result': {'type':'state', 'state':'end'}
  198. }
  199. }
  200. wizard_create_menu('create.menu.wizard')
  201. # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: