This question has been flagged
6 Replies
26395 Views

Where can I find examples of creating new models (tables) online? Or perhaps I should look in the source code. Do you have any suggestions as to where I should start looking?

I'm especially interested in following the proper method of relating the project model one2many new items.

Avatar
Discard
Best Answer

Hi,

Creating Models in OpenERP is a fairly straightforward process, and can be done in two ways, depending on the context.

1) Create a dedicated module for OpenERP that installs your model when the module is installed.
2) Create a new model directly in your OpenERP database using the user interface.

Option 1 is good if you plan on distributing your model to other people. It is also safer because if, for whatever reason, you need to create a new database or want to deploy a second version of OpenERP, all you have to do is re-deploy the module - all your hard work is backed up. Open 1 does, however, require some technical programming knowledge. You also get full access to the OpenERP API and the python programming language.

Option 2 is good if you are the only person who will use the model, and if it is a small, simple project. They are stored directly in the database. It is easier to do, and requires no programming knowledge, however you will be limited to very simple data in / data out functionality. Good for, for example, storing a bunch of text notes with dates etc.

For option 1, there are lots of articles on the web. I would start out by reading the OpenERP module development article. This article describes the anatomy of an OpenERP module, followed by more in-depth usage instructions for each aspect.

For option 2, you can start out by going directly to the Settings > Technical > Database Structure > Models section of OpenERP (version 7) while logged in as the administrator. From there, you can create models like any other record in OpenERP! Don't forget that your model will need a Menu Item so you can manage the records (Notice the handy "Create a Menu" button on the model form view). You might also want to make custom Views to display your records.

Specifically for one2many Documentation for one2many fields can be found here. This will be especially useful if using option 1 (creating a module) but will also help you understand how relational fields are used within OpenERP.

Good luck!

Avatar
Discard

Module development did probably not change much between 6.1 and 7.0, right? Anyway, it would be nice to have the example updated to the latest release, including usage of the new web interface. Is there any complete example for 7.0 available? Thanks in advance!

You are right - module development has not really changed between 6.1 and 7.0. Nevertheless, I have found this link: http://doc.openerp.com/trunk/developers/server/03_module_dev/ which seems to be a more up to date version of the OpenERP module development article linked above - I have updated my answer.

I have created the model through code see this http://codeimplementer.blogspot.in/2013/10/how-to-create-new-model-in-existing.html

Is it possible to create a model for existing tables? (sale_order_tax doesn't have)