How, to resolve an issue while executing the code in which i need to show an selection field depending on another field where patients age is coming in years.
The dependent field would show up only when age is between 18 to 35 yrs. To make the issue more clear to you, I am specifying you the code:
date_of_birth = fields.Date('Date of Birth', help="YY/MM/DD")
patient_female_age = fields.Function(fields.Integer('Patient Female Age'),
'on_change_with_patient_female_age')
doctor_talked_about_diabetes_pregnancy_is = fields.Selection(
[
(None, ''),
('yes', 'Yes'),
('no', 'No'),
('not_known', 'Not Known')
], """đ±.Has your doctor talked to you
about diabetes and pregnancy?""",
sort=False, help="Select Perfect One",
states={'readonly': (Eval('patient_female_age', 0) >= 18) & (
Eval('patient_female_age', 0) <= 35),
}, depends=['on_change_with_patient_female_age'])
@fields.depends('date_of_birth')
def on_change_with_patient_female_age(self, name=None):
now = datetime.now()
diff = relativedelta.relativedelta(now, self.date_of_birth)
years = diff.years
months = diff.months
days = diff.days
date_str = '{} years {} months {} days'.format(years, months, days)
date_str = (int(str(date_str)[:2]))
return date_str
@staticmethod
def default_patient_female_age():
return 0
Assuming that âon_change_with_patient_female_ageâ is returning the correct age, I think that you should modify the states and the depends of the âdoctor_talked_about_diabetes_pregnancy_isâ field to something like:
If it doesnât solve the problem, can you specify if the problem is due to the functional field or if itâs returning an error, can you show us the traceback?