In this step we will continue with 'clinic.patient' object and
- add country field
- add phone field with validation function
- edit tree view
To add phone number and country fields we have to go to 'clinic.patient' object and add them with validation function as bellow
country_id = fields.Many2one('res.country', string="Country")
phone = fields.Char(string="Phone")
@api.constrains('phone')
def phone_validation(self):
"""
function to validate phone data for patient
"""
phone_prefix = [1,9]
phone_type = [0,1,2,6,9]
check_value = 0
if self.phone and self.country_id:
if self.country_id.code == 'SD':
phone = self.phone
if len(phone) != 9:
raise ValidationError(_("Wrong phone number , it length is not true"))
if len(phone) == 9:
for index in range(0,len(phone_prefix)):
if phone[0] == str(phone_prefix[index]):
check_value = 1
if check_value == 0:
raise ValidationError(_("Wrong phone number , it start with wrong key number"))
check_value = 0
for index in range(0,len(phone_type)):
if phone[1] == str(phone_type[index]):
check_value = 1
if check_value == 0:
raise ValidationError(_("Wrong phone number , it not of real phone number"))
check_value = 0
for index in range(0,len(phone)):
check_value = 0
for number in range(0,10):
if phone[index] == str(number):
check_value = 1
if check_value == 0:
raise ValidationError(_("Wrong phone number , it must not contain charactors"))
Then we have to add it to the view in 'clinic_patient_view.xml' file inside the first group to be as
<group colspan="4" col="4">
<field name="gender"/>
<field name="birth_day"/>
<field name="country_id" />
<field name="phone"/>
<field name="met_doctor"/>
<field name="last_meeting" attrs="{'invisible': [('met_doctor','=',False)],'required':[('met_doctor','=',True)]}"/>
</group>
Then we will edit the tree view to show the important fields for the patient (name, phone, gender, age'years') so it will be as ...
<record id="clinic_patient_tree_view" model="ir.ui.view">
<field name="name">clinic.patient.tree</field>
<field name="model">clinic.patient</field>
<field name="arch" type="xml">
<tree string="Patients">
<field name="name"/>
<field name="gender"/>
<field name="phone"/>
<field name="age_year"/>
</tree>
</field>
</record>
Watch On YouTube
PREVIOUS STEP NEXT STEP
country_id = fields.Many2one('res.country', string="Country")
phone = fields.Char(string="Phone")
@api.constrains('phone')
def phone_validation(self):
"""
function to validate phone data for patient
"""
phone_prefix = [1,9]
phone_type = [0,1,2,6,9]
check_value = 0
if self.phone and self.country_id:
if self.country_id.code == 'SD':
phone = self.phone
if len(phone) != 9:
raise ValidationError(_("Wrong phone number , it length is not true"))
if len(phone) == 9:
for index in range(0,len(phone_prefix)):
if phone[0] == str(phone_prefix[index]):
check_value = 1
if check_value == 0:
raise ValidationError(_("Wrong phone number , it start with wrong key number"))
check_value = 0
for index in range(0,len(phone_type)):
if phone[1] == str(phone_type[index]):
check_value = 1
if check_value == 0:
raise ValidationError(_("Wrong phone number , it not of real phone number"))
check_value = 0
for index in range(0,len(phone)):
check_value = 0
for number in range(0,10):
if phone[index] == str(number):
check_value = 1
if check_value == 0:
raise ValidationError(_("Wrong phone number , it must not contain charactors"))
Then we have to add it to the view in 'clinic_patient_view.xml' file inside the first group to be as
<group colspan="4" col="4">
<field name="gender"/>
<field name="birth_day"/>
<field name="country_id" />
<field name="phone"/>
<field name="met_doctor"/>
<field name="last_meeting" attrs="{'invisible': [('met_doctor','=',False)],'required':[('met_doctor','=',True)]}"/>
</group>
Then we will edit the tree view to show the important fields for the patient (name, phone, gender, age'years') so it will be as ...
<record id="clinic_patient_tree_view" model="ir.ui.view">
<field name="name">clinic.patient.tree</field>
<field name="model">clinic.patient</field>
<field name="arch" type="xml">
<tree string="Patients">
<field name="name"/>
<field name="gender"/>
<field name="phone"/>
<field name="age_year"/>
</tree>
</field>
</record>
Watch On YouTube
PREVIOUS STEP NEXT STEP
res.country
ReplyDeleteده موديول ولا شنو
قصدي object of model
Delete