跳转至内容
  • 版块
  • 标签
  • 热门
  • 用户
  • 群组
皮肤
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • 默认(Flatly)
  • 不使用皮肤
折叠

Odoo 中文社区

  1. 主页
  2. 版块
  3. Odoo 新手求助
  4. 关于selection字段的context用法的问题?

关于selection字段的context用法的问题?

已定时 已固定 已锁定 已移动 未解决 Odoo 新手求助
2 帖子 2 发布者 2.1k 浏览
  • 从旧到新
  • 从新到旧
  • 最多赞同
登录后回复
此主题已被删除。只有拥有主题管理权限的用户可以查看。
  • B 离线
    B 离线
    billchen0769
    写于 最后由 编辑
    #1

    first_level = fields.Selection([
    ('regular_checks', '常规检查'),
    ('transmissibility_photo_examination', '透射性检查'),
    ('in_vitro_examination', '体外检查'),
    ('tests_that_reach_into_the_body', '体内检查'),
    ('special_organ_examinations', '五官检查')
    ], string='检查大类')
    second_level = fields.Selection(selection='_get_second_field_options', string='检查分类')

    @api.model
    def _get_second_field_options(self):
    options = []
    context = self.env.context
    if context.get('first_level') == 'Regular_checks':
    options = [('blood_test', '验血'), ('urine_test', '验尿'), ('examination_of_stool', '验便')]
    elif context.get('first_level') == 'Transmissibility_photo_examination':
    options = [('x_ray_dr', 'X光 / DR'), ('ct', 'CT'), ('mri', 'MR 核磁共振')]
    elif context.get('first_level') == 'In_vitro_examination':
    options = [('b_ultrasound', 'B超'), ('electrocardiogram', '心电图')]
    elif context.get('first_level') == 'Tests_that_reach_into_the_body':
    options = [('gastroscope', '胃镜'), ('colonoscopy', '肠镜')]
    elif context.get('first_level') == 'Special_organ_examinations':
    options = [('hearing_test', '听力检查'), ('vision_test', '视力检查')]
    return options

    为什么方法不生效,请问有什么错误的地方?

    1 条回复 最后回复
    0
    • digitalsatoriD 离线
      digitalsatoriD 离线
      digitalsatori 管理员
      写于 最后由 编辑
      #2

      是谁跟你说可以通过context来动态决定Selection字段的可选项的?

      【上海先安科技】(tony AT openerp.cn)

      1 条回复 最后回复
      0

      • 登录

      • 没有帐号? 注册

      • 登录或注册以进行搜索。
      • 第一个帖子
        最后一个帖子
      0
      • 版块
      • 标签
      • 热门
      • 用户
      • 群组