I have one form with fields,
Name :
First Name:
Second Name:
Last Name:
I have written create function, when we enter first name, second name, last name, it will set the name
First Name: Test First
Second Name: Test Second
Last Name: Test Third
it will generate
Name : Test First Test Second Test Third
This is because of create function.
@api.model
def create(self, vals):
child = vals.get('child_first_name')
child_middle = vals.get('child_middle_name') or ' '
child_last = vals.get('child_last_name') or ' '
if child:
vals['name'] = self.env['ir.sequence'].next_by_code('application_form')
vals['child_name'] = child + ' ' + child_middle + ' ' + child_last
return super(application_form, self).create(vals)
When I edit any of these fields
First Name
Second Name
Last Name
It should set the name again.
Kindly suggest one write function with good way.
In the same Way:
Question 2 :
There is one boolean field.
For Reference:
I have written sequence Number to be generated in create method. If I uncheck that boolean fields, other set of Sequence number to be generated.
Kindly suggest write function for both.
For Writing the above question
@api.multi
def write(self, vals):
application = self.browse(self.id)
if vals.has_key('child_first_name'):
fname = vals.get('child_first_name') or ' '
else :
fname = application.child_first_name
if vals.has_key('child_middle_name'):
mname = vals.get('child_middle_name') or ' '
else :
mname = application.child_middle_name
if vals.has_key('child_last_name'):
lname = vals.get('child_last_name') or ' '
else :
lname = application.child_last_name
full_name = fname + ' ' + mname + ' ' + lname
vals.update({'child_name':full_name})
return super(application_form, self).write(vals)