It is currently Mon May 21, 2012 7:42 pm

All times are UTC + 2 hours




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Code to create a record (instance) of an object
PostPosted: Sat Aug 20, 2011 5:39 am 
Offline

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
 Profile  
 
 Post subject: Re: Code to create a record (instance) of an object
PostPosted: Mon Aug 22, 2011 2:06 pm 
Offline

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
 Profile  
 
 Post subject: Re: Code to create a record (instance) of an object
PostPosted: Wed Aug 24, 2011 11:31 pm 
Offline

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
 Profile  
 
 Post subject: Re: Code to create a record (instance) of an object
PostPosted: Thu Aug 25, 2011 10:02 am 
Offline

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
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC + 2 hours


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

Search for:

Protected by Anti-Spam ACP