Odoo Help


how to get value from object with copy_data function and incriment it, and duplicate the object ??

on 4/17/14, 10:44 AM 1,017 views

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 ???


Sudhir Arya (ERP Harbor Consulting Services)

--Sudhir Arya (ERP Harbor Consulting Services)--
| 6 8 8
Ahmedabad, India
--Sudhir Arya (ERP Harbor Consulting Services)--

• Co-Founder & Co-Owner at ERP Harbor Consulting Services

• ERP Consultant / ERP Customization / TechnoFunctional Expert

• Sound knowledge in Python, Odoo (Open ERP), XML, PostgreSQL

• Domain knowledge of Sale Management, Purchase Management, Warehouse Management, Manufacturing, Multi Company Configuration & Management, HR Management, Medical Management, Construction Management, Education Management, Point of Sale, Third Party Integrations

• Positive attitude and quick Learner

• Good analytical skill, quick bug and issue tracing and find the solution

• Good knowledge and experience in payment gateway integration with Odoo

• Ready to accept new challenges

• Active Memeber On Stackoverflow 




Sudhir Arya
ERP Harbor Consulting Services
Sudhir Arya (ERP Harbor Consulting Services)
On 4/17/14, 4:22 PM

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.

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

0 follower(s)


Asked: 4/17/14, 10:44 AM
Seen: 1017 times
Last updated: 3/16/15, 8:10 AM