关于selection字段的context用法的问题?
-
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为什么方法不生效,请问有什么错误的地方?
-
是谁跟你说可以通过context来动态决定Selection字段的可选项的?