View unanswered posts | View active topics
|
Page 1 of 1
|
[ 4 posts ] |
|
| Author |
Message |
|
anasb079
|
Post subject: Code to create a record (instance) of an object Posted: Sat Aug 20, 2011 5:39 am |
|
Joined: Wed Jun 15, 2011 7:22 pm Posts: 104
|
|
Hello,
I would like to know the code to create a record of an object (I need to do this in a function).
Let me explain what I want to do: I created a module that inherits 'product.product'. In this module, I added a field 'my_supplier' of type many2one ('res.partner') that I put in a view (I created) that inherits from 'product.product.normal.form' . I would like, when entering my field 'my_supplier', to auto-generate the informations of Supplier's tab of my view (the same as 'product.product.normal.form'). So I want to create a record 'product.supplierinfo' in a function that will auto-generate the necessary informations.
Thank you for your help.
|
|
| Top |
|
 |
|
SmartIT
|
Post subject: Re: Code to create a record (instance) of an object Posted: Mon Aug 22, 2011 2:06 pm |
|
Joined: Thu Oct 28, 2010 1:51 pm Posts: 53
|
|
Ok: whateverobject={ 'FIELD': FIELDVALUE, 'FIELD2': FIELD2VALUE, 'FIELD3': FIELD3VALUE }
whatever_id=self.pool.get('whateverobj').create(cr,uid,whateverobject)
#then we can browse it.. (if we wanted to) whatever=self.pool.get('whateverobj').browse(cr,uid,whatever_id) print whatever.FIELD
_________________ Developing OpenERP Modules for what seems like an eternity Smart IT Ltd http://www.smart-ltd.co.uk
|
|
| Top |
|
 |
|
anasb079
|
Post subject: Re: Code to create a record (instance) of an object Posted: Wed Aug 24, 2011 11:31 pm |
|
Joined: Wed Jun 15, 2011 7:22 pm Posts: 104
|
|
Thank your for your answer.
I'm trying your code and I have a question please. If 'FIELD' is a many2one('res.partner',...) field. What could I put in 'FIELDVALUE' ?
|
|
| Top |
|
 |
|
SmartIT
|
Post subject: Re: Code to create a record (instance) of an object Posted: Thu Aug 25, 2011 10:02 am |
|
Joined: Thu Oct 28, 2010 1:51 pm Posts: 53
|
|
The id value of the related object, e.g. if you had an account with id 5 you would put 5, you could do user.id for example if you had a user object.
e.g. partner=self.pool.get('res.partner').browse(cr,uid,1) #just get first account (assuming there is one with id 1)
partner.id # that field is what you need to use
_________________ Developing OpenERP Modules for what seems like an eternity Smart IT Ltd http://www.smart-ltd.co.uk
|
|
| Top |
|
 |
|
Page 1 of 1
|
[ 4 posts ] |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum
|