Python 如何将上下文从向导传递到控制器,并在Odoo 12中的控制器中获取该上下文的值?

Python 如何将上下文从向导传递到控制器,并在Odoo 12中的控制器中获取该上下文的值?,python,python-requests,odoo,odoo-12,Python,Python Requests,Odoo,Odoo 12,我有一个向导,选择一个部门,然后调用一个调用控制器的操作(用xml定义)。我还设置(定义)了我的自定义上下文,并在上下文中传递了所选的部门id。我想在调用将控制器加载到控制器的操作时传递此上下文。在控制器中,我需要访问传递的上下文的值。这是我在控制器中设置上下文并返回带有上下文的操作的代码: @api.multi def action_select_department(self): ctx = dict(self._context) if self.department_id:

我有一个向导,选择一个部门,然后调用一个调用控制器的操作(用xml定义)。我还设置(定义)了我的自定义上下文,并在上下文中传递了所选的部门id。我想在调用将控制器加载到控制器的操作时传递此上下文。在控制器中,我需要访问传递的上下文的值。这是我在控制器中设置上下文并返回带有上下文的操作的代码:

@api.multi
def action_select_department(self):
    ctx = dict(self._context)
    if self.department_id:
        self.state = 'display'
        ctx.update({'dep_id': self.department_id.id})
        print('Dept id:::::::::::::::::::', self.department_id.id, ctx)
        return {
            'name': _('Website Next Patient Screen'),
            'type': 'ir.actions.act_url',
            'context': ctx,
            'url': '/next_patient',
            'target': 'self'
        }
这是我想要获取上下文的控制器代码:

 -*- coding: utf-8 -*-

from odoo import http
from odoo.http import request
from odoo.tools.translate import _


class hms_next_patient_screen(http.Controller):
    @http.route(['/next_patient'], type='http', auth="public", website=True)
    def next_patient(self, **kw):
        ctx = request.env.context.copy()
        dept = http.request.evn['nl_hms_next_patient.next.patiend.screen.wizard']
        print('DEPT:::::::::::::::::::::::::::::::', dept)
        print (">>>>>>>>>>>>>>>", ctx, self, kw)
        app_obj = request.env['hms.appointment']
        one = app_obj.sudo().search([('state', '=', 'in_consultation')], limit=1)
        next = app_obj.sudo().search([('state', '=', 'waiting')])
        two = three = four = app_obj
        if len(next)>=1:
            two = next[0]
        if len(next)>=2:
            three = next[1]
        if len(next)>=3:
            four = next[2]
        return request.render("acs_hms_next_patient_screen.next_patient_view",{'one':one,'two':two,'three':three,'four':four})

向导中的方法工作正常,在加载控制器时调用该操作。但是,我无法访问控制器中的上下文值。如何传递自定义上下文并在控制器中访问它?

您不必将详细信息作为上下文传递给控制器。您可以通过url传递它。 请试试这个

在向导中

 return {
      'name': _('Website Next Patient Screen'),
      'type': 'ir.actions.act_url',
      'url': '/next_patient?dep_id=%s' % self.department_id.id
      'target': 'self'
   }
您可以从controller中的
kw
参数获取在url中传递的详细信息

在控制器中

  department_id = kw.get('dep_id')

你有没有想过为department\u id使用URL参数?实际上没有,我只是想传递一个department\u id的上下文,我没有考虑这个案例。