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

i redefined copy_data function in my class, when i want to get nContrat value from the object and increment it after duplicated it, my code give me an error, can someone have any idea how to slove it ??

def copy_data(self, cr, uid, id, default=None, context=None): if default is None: default = {}

res = 1                                              <---------------------
res += default.get('nContrat')                       <---------------------
default['nContrat'] = res                            <---------------------

return super(io_assurance, self).copy_data( cr, uid, id, default=res, context=context)

when i use my code i get this error ( TypeError: unsupported operand type(s) for +=: 'int' and 'NoneType' ) anyone havy any idea how to slove this problem ???

Аватар
Отменить
Лучший ответ

The problem is in default.get(nContrat). It gives None because default does not have any key, value pair of nContrat.

To avoid such error you can use: res += default.get('nContrat', 0).

If you want data from your original record you can browse it using id.

self.browse(cr, uid, id, context=context).nContrat

Hope this will help you.

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