Regarding (1): when you do a search for 'openerp create module', there are various sites (including youtube) which show and help you to create a new module. Although many of them say it is for V6 or V6.1, it also works for V7.
Regarding (2): What do you mean by this question?
Regarding (3): within the module, you can use API-like things like
model_id = model.search([('fieldname', '=', some_value')])
if there is no result, model_id will be [], otherwise [<id>]
It is not clear to me what you mean by the last sentence, but I think you want to use the openERP ORM, from script(s), without logging in into openERP. In that case, I use openerplib, a module you can install 'openerplib'. This allows you to hide the XML-RPC like code, to get some nicer looking code. Next week I can post how to install this library and an example, how to make a script using this library.
#openerplib
I use Ubuntu, so if you are using Windows, change the commands to Windows commands.
To install openerplib, you need to download and install setup_tools:
wget https://pypi.python.org/packages/2.7/s/setuptools/setuptools-0.6c11-py2.7.egg
sudo ./setuptools-0.6c11-py2.7.egg
now you can openerplib:
sudo easy_install openerp-client-lib
usage of openerplib in a script
import openerplib
h = 'localhost'
db = 'myDB'
u = 'admin'
pw = 'verySecurePassword!'
connection = openerplib.get_connection(
hostname=h, database=db, login=u, password=p)
#now you have a connection to the DB and can you do some things
#first get an object of your model
user_obj = connection.get_model('res.model')
# use this object to execute some action, in this case, search for user(s)
# with John in the name, but also Johnny....
user_id = user_obj.search([('name', 'in', 'John')])
if user_id == []:
print 'No user found who has John in his name'
else:
#now read all the users whose IDs are in user_id
users = user_bj.read(user_id)
print 'There are %s user(s) with John in the name' %(len(user_id)
for u in users:
print 'User %s has userID %s' %(u['name'], u['id'])
#close the connection nicely
connection.close()