Перейти к содержимому
Меню
Чтобы взаимодействовать с сообществом, необходимо зарегистрироваться.
Этот вопрос был отмечен
2 Ответы
6419 Представления

i declared two field 'firstname' and 'secondname' in the rh.employee model and i want to concatenate both of them on the name field.

here is the function that i am declared 


def create(self, cr, uid, vals, context=None):

        new_id = super(HrEmployeePrivate, self).create(cr, uid, vals, context=context)

        names = (vals['Prénom'], vals['Nom'])

        fullname = " ".join([s for s in names if s])

        vals['name'] = fullname

        return new_id


and i call the function in the field name as well 


name = fields.Char(string="Employee Name",compute='create', related='resource_id.name', store=True, readonly=False, tracking=True)


but when i clck save, i get

the operation cannot be completed,

probably due to the following: 

creation/update: a mandatory field is not correctly set


Аватар
Отменить
Автор

thanks, but the field that i want to be filled with the concatenation value is already exist

i replace the vals['full_name'] with vals['name']

and in the field i called the function but the same error shows up 

Лучший ответ

Hi,

Try like this,

@api.model
def create(self, vals):
full_name = ''
if vals.get('firstname'):
full_name += vals['firstname']
if vals.get('secondname'):
full_name += vals['secondname']
vals['full_name'] = full_name
res = super(ResPartner, self).create(vals)
return res

firstname = fields.Char(string="First Name")
secondname = fields.Char(string="Second Name")
full_name = fields.Char(string="Name")

Thanks

Аватар
Отменить
Related Posts Ответы Просмотры Активность
4
мая 24
12706
1
апр. 24
3319
0
нояб. 23
2039
1
сент. 23
2139
2
авг. 23
4529