def action(self, **kw): params, data = TinyDict.split(kw) id = params.id or False ids = params.selection or [] context = params.context or {} action = {} if data.get('datas'): action = eval(data.get('datas')) type = action.get('type') act_id = params.action if not ids and id: ids = [id] if not id and ids: id = ids[0] domain = params.domain or [] if not params.selection and not params.id: raise common.message(_('You must save this record to use the sidebar button!')) if not act_id: return self.do_action('client_action_multi', datas=kw) if type is None: action_type = rpc.RPCProxy('ir.actions.actions').read(act_id, ['type'], rpc.session.context)['type'] action = rpc.session.execute('object', 'execute', action_type, 'read', act_id, False, rpc.session.context) action['domain'] = domain or [] action['context'] = context or {} from openerp.controllers import actions return actions.execute(action, model=params.model, id=id, ids=ids, report_type='pdf')
def action(self, **kw): params, data = TinyDict.split(kw) id = params.id or False ids = params.selection or [] if not ids and id: ids = [id] if not id and ids: id = ids[0] domain = params.domain or [] context = params.context or {} context.update(rpc.session.context.copy()) context.update({'active_id': rpc.session.active_id, 'active_ids': [rpc.session.active_id]}) if not params.selection and not params.id: raise common.message(_('You must save this record to use the sidebar button!')) if not params.action: return self.do_action('client_action_multi', datas=kw) action_type = rpc.RPCProxy('ir.actions.actions').read(params.action, ['type'], context)['type'] action = rpc.session.execute('object', 'execute', action_type, 'read', params.action, False, context) action['domain'] = domain or [] action['context'] = context or {} from openerp.controllers import actions return actions.execute(action, model=params.model, id=id, ids=ids, report_type='pdf')
def action(self, **kw): params, data = TinyDict.split(kw) action = params.data if not action: return self.do_action('tree_but_action', datas=kw) from openerp.controllers import actions ids = params.selection or [] id = (ids or False) and ids[0] return actions.execute(action, model=params.model, id=id, ids=ids, report_type='pdf')
def action(self, **kw): params, data = TinyDict.split(kw) action = params.data if not action: return self.do_action('tree_but_action', datas=kw) from openerp.controllers import actions ids = params.selection or [] id = (ids or False) and ids[0] return actions.execute(action, model=params.model, id=id, ids=ids, report_type='pdf')
def index(self, domain, context, view_id, search_domain='[]', action_id=None): context = ast.literal_eval(context) if not action_id: # This should not be needed anymore, but just in case users are # running the module with an older version of the web client... # to remove soon-ish action_id = rpc.RPCProxy('ir.actions.act_window').search( [('view_id', '=', int(view_id))], context=context) if not action_id: return "" action_id = action_id[0] domain = ast.literal_eval(domain) domain.extend(ast.literal_eval(search_domain)) share_model = 'share.wizard' scheme, netloc, _, _, _ = urlparse.urlsplit(cherrypy.request.base) share_root_url = urlparse.urlunsplit( (scheme, netloc, '/openerp/login', 'db=%(dbname)s&user=%(login)s&password=%(password)s', '')) share_wiz_id = rpc.RPCProxy('ir.ui.menu').search([('name', '=', 'Share Wizard')]) context.update(active_ids=share_wiz_id, active_id=share_wiz_id[0], _terp_view_name='Share Wizard', share_root_url=share_root_url) sharing_view_id = rpc.RPCProxy(share_model).create( { 'domain': str(domain), 'action_id': action_id and int(action_id) }, context) return actions.execute(rpc.session.execute('object', 'execute', share_model, 'go_step_1', [sharing_view_id], context), ids=[sharing_view_id], context=context)
def action(self, **kw): params, data = TinyDict.split(kw) id = params.id or False ids = params.selection or [] context = params.context or {} action = {} if data.get('datas'): action = eval(data.get('datas')) type = action.get('type') act_id = params.action if not ids and id: ids = [id] if not id and ids: id = ids[0] domain = params.domain or [] if not params.selection and not params.id: raise common.message( _('You must save this record to use the sidebar button!')) if not act_id: return self.do_action('client_action_multi', datas=kw) if type is None: action_type = rpc.RPCProxy('ir.actions.actions').read( act_id, ['type'], rpc.session.context)['type'] action = rpc.session.execute('object', 'execute', action_type, 'read', act_id, False, rpc.session.context) action['domain'] = domain or [] action['context'] = context or {} from openerp.controllers import actions return actions.execute(action, model=params.model, id=id, ids=ids, report_type='pdf')
def index(self, model, id): id = int(id) if id: ctx = {} ctx.update(rpc.session.context.copy()) action = rpc.session.execute('object', 'execute', 'ir.attachment', 'action_get', ctx) action['domain'] = [('res_model', '=', model), ('res_id', '=', id)] ctx['default_res_model'] = model ctx['default_res_id'] = id action['context'] = ctx return actions.execute(action) else: raise common.message(_('No record selected! You can only attach to existing record...')) return True
def index(self, domain, context, view_id, search_domain='[]', action_id=None): context = ast.literal_eval(context) if not action_id: # This should not be needed anymore, but just in case users are # running the module with an older version of the web client... # to remove soon-ish action_id = rpc.RPCProxy('ir.actions.act_window').search( [('view_id','=',int(view_id))], context=context) if not action_id: return "" action_id = action_id[0] domain = ast.literal_eval(domain) domain.extend(ast.literal_eval(search_domain)) share_model = 'share.wizard' scheme, netloc, _, _, _ = urlparse.urlsplit(cherrypy.request.base) share_root_url = urlparse.urlunsplit(( scheme, netloc, '/openerp/login', 'db=%(dbname)s&user=%(login)s&password=%(password)s', '')) share_wiz_id = rpc.RPCProxy('ir.ui.menu').search( [('name','=', 'Share Wizard')]) context.update( active_ids=share_wiz_id, active_id=share_wiz_id[0], _terp_view_name='Share Wizard', share_root_url=share_root_url) sharing_view_id = rpc.RPCProxy(share_model).create({ 'domain': str(domain), 'action_id': action_id and int(action_id) }, context) return actions.execute( rpc.session.execute('object', 'execute', share_model, 'go_step_1', [sharing_view_id], context), ids=[sharing_view_id], context=context)
def index(self, model, id): id = int(id) if id: ctx = {} ctx.update(rpc.session.context.copy()) action = rpc.session.execute('object', 'execute', 'ir.attachment', 'action_get', ctx) action['domain'] = [('res_model', '=', model), ('res_id', '=', id)] ctx['default_res_model'] = model ctx['default_res_id'] = id action['context'] = ctx return actions.execute(action) else: raise common.message( _('No record selected! You can only attach to existing record...' )) return True
def execute(self, params): action = params.name model = params.model state = params.state datas = params.datas form = None buttons = [] if model: action = model.replace('wizard.', '', 1) else: model = 'wizard.' + action params.name = action params.model = model params.view_mode = [] if 'form' not in datas: datas['form'] = {} wiz_id = params.wiz_id or rpc.session.execute('wizard', 'create', action) while state != 'end': ctx = rpc.session.context.copy() ctx.update(datas.get('context' or {}) or {}) res = rpc.session.execute('wizard', 'execute', wiz_id, datas, state, ctx) if 'datas' in res: datas['form'].update(res['datas']) else: res['datas'] = {} if res['type']=='form': fields = res['fields'] form_values = {} for f in fields: if 'value' in fields[f]: form_values[f] = fields[f]['value'] if f in datas['form'] and fields[f]['type'] == "one2many": datas['form'][f] = [(1, d, {}) for d in datas['form'][f]] form_values.update(datas['form']) datas['form'] = form_values res['datas'].update(datas['form']) params.is_wizard = True params.view_mode = ['form'] params.view_type = 'form' params.views = {'form': res} # keep track of datas and some other required information params.hidden_fields = [tw.form.Hidden(name='_terp_datas', default=ustr(datas)), tw.form.Hidden(name='_terp_state2', default=state), tw.form.Hidden(name='_terp_wiz_id', default=wiz_id)] form = tw.form_view.ViewForm(params, name="view_form", action="/wizard/action") buttons = [] for x in res.get('state', []): x = list(x) x[1] = re.sub('_(?!_)', '', x[1]) # remove mnemonic if len(x) >= 3: x[2] = icons.get_icon(x[2]) buttons.append(tuple(x)) params.state = state target = getattr(cherrypy.request, '_terp_view_target', None) return dict(form=form, buttons=buttons, show_header_footer=target!='new') elif res['type']=='action': from openerp.controllers import actions act_res = actions.execute(res['action'], **datas) if act_res: return act_res state = res['state'] elif res['type']=='print': from openerp.controllers import actions datas['report_id'] = res.get('report_id', False) if res.get('get_id_from_action', False): backup_ids = datas['ids'] datas['ids'] = datas['form']['ids'] return actions.execute_report(res['report'], **datas) elif res['type']=='state': state = res['state'] raise redirect('/wizard/end')
def add(self): return actions.execute( openobject.rpc.RPCProxy('res.widget.wizard').action_get({}) )
def execute(self, params): action = params.name model = params.model state = params.state datas = params.datas form = None buttons = [] if model: action = model.replace('wizard.', '', 1) else: model = 'wizard.' + action params.name = action params.model = model params.view_mode = [] if 'form' not in datas: datas['form'] = {} wiz_id = params.wiz_id or rpc.session.execute('wizard', 'create', action) while state != 'end': ctx = rpc.session.context.copy() ctx.update(datas.get('context' or {}) or {}) res = rpc.session.execute('wizard', 'execute', wiz_id, datas, state, ctx) if 'datas' in res: datas['form'].update(res['datas']) else: res['datas'] = {} if res['type'] == 'form': fields = res['fields'] form_values = {} for f in fields: if 'value' in fields[f]: form_values[f] = fields[f]['value'] if f in datas['form'] and fields[f]['type'] == "one2many": datas['form'][f] = [(1, d, {}) for d in datas['form'][f]] form_values.update(datas['form']) datas['form'] = form_values res['datas'].update(datas['form']) params.is_wizard = True params.view_mode = ['form'] params.view_type = 'form' params.views = {'form': res} # keep track of datas and some other required information params.hidden_fields = [ tw.form.Hidden(name='_terp_datas', default=ustr(datas)), tw.form.Hidden(name='_terp_state2', default=state), tw.form.Hidden(name='_terp_wiz_id', default=wiz_id) ] form = tw.form_view.ViewForm(params, name="view_form", action="/wizard/action") buttons = [] for x in res.get('state', []): x = list(x) x[1] = re.sub('_(?!_)', '', x[1]) # remove mnemonic if len(x) >= 3: x[2] = icons.get_icon(x[2]) buttons.append(tuple(x)) params.state = state target = getattr(cherrypy.request, '_terp_view_target', None) return dict(form=form, buttons=buttons, show_header_footer=target != 'new') elif res['type'] == 'action': from openerp.controllers import actions act_res = actions.execute(res['action'], **datas) if act_res: return act_res state = res['state'] elif res['type'] == 'print': from openerp.controllers import actions datas['report_id'] = res.get('report_id', False) if res.get('get_id_from_action', False): backup_ids = datas['ids'] datas['ids'] = datas['form']['ids'] return actions.execute_report(res['report'], **datas) elif res['type'] == 'state': state = res['state'] raise redirect('/wizard/end')
def default(self): vid = rpc.RPCProxy('unifield.version').create({}) return actions.execute( rpc.RPCProxy('ir.actions.act_window')\ .for_xml_id('msf_profile', 'action_unifield_version_form_view'), domain=('id', '=', vid) )
def default(self): ids, total = self.my() return actions.execute( rpc.RPCProxy('ir.actions.act_window')\ .for_xml_id('base', 'res_request-act'), domain=('id', 'in', ids) )
def add(self): return actions.execute( openerp.utils.rpc.RPCProxy('res.widget.wizard').action_get({}) )
def button_action(self, params): button = params.button name = ustr(button.name) name = name.rsplit('/', 1)[-1] btype = button.btype model = button.model id = button.id or params.id id = (id or False) and int(id) ids = (id or []) and [id] ctx = (params.context or {}).copy() ctx.update(rpc.session.context.copy()) ctx.update(button.context or {}) if btype == 'cancel': if name: button.btype = "object" params.id = False res = self.button_action(params) if res: return res return """<html> <head> <script type="text/javascript"> window.onload = function(evt){ if (window.opener) { window.opener.setTimeout("window.location.reload()", 0); window.close(); } else { window.location.href = '/'; } } </script> </head> <body></body> </html>""" elif btype == 'save': params.id = False elif btype == 'workflow': res = rpc.session.execute('object', 'exec_workflow', model, name, id) if isinstance(res, dict): from openerp.controllers import actions return actions.execute(res, ids=[id]) elif btype == 'object': res = rpc.session.execute('object', 'execute', model, name, ids, ctx) if isinstance(res, dict): from openerp.controllers import actions return actions.execute(res, ids=[id]) elif btype == 'action': from openerp.controllers import actions action_id = int(name) action_type = actions.get_action_type(action_id) if action_type == 'ir.actions.wizard': cherrypy.session['wizard_parent_form'] = self.path cherrypy.session['wizard_parent_params'] = params.parent_params or params res = actions.execute_by_id(action_id, type=action_type, model=model, id=id, ids=ids, context=ctx or {}) if res: return res else: raise common.warning(_('Invalid button type')) params.button = None
def default(self): ids, total = self.my() return actions.execute( rpc.RPCProxy('ir.actions.act_window')\ .for_xml_id('base', 'res_request-act'), domain=('id', 'in', ids) )
def action(self, **kw): params, data = TinyDict.split(kw) from openerp.controllers import actions return actions.execute(params.action, **params.data)
def button_action(self, params): button = params.button name = ustr(button.name) name = name.rsplit('/', 1)[-1] btype = button.btype model = button.model id = button.id or params.id id = (id or False) and int(id) ids = (id or []) and [id] ctx = (params.context or {}).copy() ctx.update(rpc.session.context.copy()) ctx.update(button.context or {}) if btype == 'cancel': if name: button.btype = "object" params.id = False res = self.button_action(params) if res: return res return """<html> <head> <script type="text/javascript"> window.onload = function(evt){ if (window.opener) { window.opener.setTimeout("window.location.reload()", 0); window.close(); } else { window.location.href = '/'; } } </script> </head> <body></body> </html>""" elif btype == 'save': params.id = False elif btype == 'workflow': res = rpc.session.execute('object', 'exec_workflow', model, name, id) if isinstance(res, dict): from openerp.controllers import actions return actions.execute(res, ids=[id]) elif btype == 'object': res = rpc.session.execute('object', 'execute', model, name, ids, ctx) if isinstance(res, dict): from openerp.controllers import actions result = actions.execute(res, ids=[id]) if result is None or type(result) == type({}): return """<html> <head> <script type="text/javascript"> window.onload = function(evt){ if (window.opener) { window.opener.setTimeout("window.location.reload()", 0); window.close(); } else { window.location.href = '/'; } } </script> </head> <body></body> </html>""" else: return result elif btype == 'action': from openerp.controllers import actions action_id = int(name) action_type = actions.get_action_type(action_id) if action_type == 'ir.actions.wizard': cherrypy.session['wizard_parent_form'] = self.path cherrypy.session[ 'wizard_parent_params'] = params.parent_params or params res = actions.execute_by_id(action_id, type=action_type, model=model, id=id, ids=ids, context=ctx or {}) if res: return res else: raise common.warning(_('Invalid button type')) params.button = None