four-digit name
Some organizations ask to create four-digit name for it's employees when we enter the data for them , and to do that we have to create the four-digit name as bellow as in the image bellow
- create five char fields in the employee model which are
first_name , second_name , third_name , fourth_name and the complete name which is contain all the other names and defined theme as bellow
name = fields.Char("Name", required=True, compute='get_full_name')
first_name = fields.Char("First Name", required=True)
second_name = fields.Char("Second Name", required=True)
third_name = fields.Char("Third Name", required=True)
fourth_name = fields.Char("Fourth Name", required=True)
first_name = fields.Char("First Name", required=True)
second_name = fields.Char("Second Name", required=True)
third_name = fields.Char("Third Name", required=True)
fourth_name = fields.Char("Fourth Name", required=True)
the get_full_name() function use to concatenate the complete name for the employee and it must be as bellow
@api.one
@api.depends('first_name','second_name','third_name','fourth_name')
def get_full_name(self):
"""
the method compute the full name for the employee
"""
if self.first_name and self.second_name and self.third_name and self.fourth_name:
self.name = self.first_name+" "+self.second_name+" "+self.third_name+" "+self.fourth_name
@api.depends('first_name','second_name','third_name','fourth_name')
def get_full_name(self):
"""
the method compute the full name for the employee
"""
if self.first_name and self.second_name and self.third_name and self.fourth_name:
self.name = self.first_name+" "+self.second_name+" "+self.third_name+" "+self.fourth_name
- create the view as bellow
<group colspan="2" col="2">
<field name="name" style="font-size:30px;color:#7c7bad;"/>
</group>
<group colspan="12" col="12">
<field name="first_name" nolabel="1" placeholder="First Name" attrs="{'readonly':[('state','!=','draft')]}"/>
<field name="second_name" nolabel="1" placeholder="Second Name" attrs="{'readonly':[('state','!=','draft')]}"/>
<field name="third_name" nolabel="1" placeholder="Third Name" attrs="{'readonly':[('state','!=','draft')]}"/>
<field name="fourth_name" nolabel="1" placeholder="Fourth Name" attrs="{'readonly':[('state','!=','draft')]}"/>
</group>
<field name="name" style="font-size:30px;color:#7c7bad;"/>
</group>
<group colspan="12" col="12">
<field name="first_name" nolabel="1" placeholder="First Name" attrs="{'readonly':[('state','!=','draft')]}"/>
<field name="second_name" nolabel="1" placeholder="Second Name" attrs="{'readonly':[('state','!=','draft')]}"/>
<field name="third_name" nolabel="1" placeholder="Third Name" attrs="{'readonly':[('state','!=','draft')]}"/>
<field name="fourth_name" nolabel="1" placeholder="Fourth Name" attrs="{'readonly':[('state','!=','draft')]}"/>
</group>
No comments:
Post a Comment