How to create a module in OpenERP ?


It is very easy to create a module in OpenERP.

Find the below displayed screens. We will code to result this output.

Tree View

Form View

Few files needs to be created compulsory. We will take an example let say – “test_module”

First of all, we will see the architecture of a typical OpenERP module.

  1. __openerp__.py
  2. __init__.py
  3. Python files
  4. XMLFiles
    1. Actions
    2. Menu Entries
    3. Reports
    4. Wizards

All the modules are located in server/addons directory.

The following steps are necessary to create a new module “test_module”:

– create a subdirectory in the server/addons directory having module name test_module.

– create a module description file: __openerp__.py

– create the Python file containing the objects.

– create .xml files that download the data (views, menu entries, demo data, …).

– optionally create reports, wizards or workflows.

We will see each files introduction one by one.

The __init__.py file:

The __init__.py file is, like any Python module, executed at the start of the program. It needs to import the Python files that need to be loaded.

So, if you create a “test_module.py” file, containing the description of your objects, you have to write one line in __init__.py:

import test_module.py

The __openerp__.py file

In the created module directory, you must add a __openerp__.py file. This file, which must be in Python format, is responsible to

  1. determine the XML files that will be parsed during the initialization of the server, and also to
  2. determine the dependencies of the created module.

This file must contain a Python dictionary with the following values:

{
"name" : "Test Module",
"version" : "1.1",
"author" : "Open",
"category" : "Test Base/Test Base",
"depends" : ["base"],
"init_xml" : [],
"demo_xml" : [],
"update_xml" : ["test_view.xml"],
"installable": True,
"active": True
}

The test_module.py file

from osv import osv

from osv import fields

class test_base(osv.osv):

    ”’Test Base Class”’

    _name=‘test.base’

    _columns={

            ‘name’:fields.char(“Name”,size=128,),

            ‘code’:fields.char(Code,size=64)

    }

test_base()

The text_view.xml file

<?xml version=“1.0” encoding=“utf-8”?>

<openerp>

    <data>

       <record model=“ir.ui.view” id=“test_base_form”>

           <field name=“name”>test.base.form</field>

               <field name=“model”>test.base</field>

               <field name=“type”>form</field>

               <field name=“arch” type=“xml”>

                   <form string=“Test Base”>

                       <field name=“name”/>

                       <field name=“code”/>

                   </form>

              </field>

        </record>

        <record model=“ir.ui.view” id=“test_base_tree”>

            <field name=“name”>test.base.tree</field>

            <field name=“model”>test.base</field>

            <field name=“type”>tree</field>

            <field name=“arch” type=“xml”>

                <tree string=“Test Base”>

                    <field name=“name”/>

                    <field name=“code”/>

                </tree>

            </field>

        </record>

        <record model=“ir.actions.act_window” id=“action_test_seq”>

            <field name=“name”>Test Base</field>

            <field name=“res_model”>test.base</field>

            <field name=“view_type”>form</field>

            <field name=“view_mode”>tree,form</field>

        </record>

        <menuitem id=“menu_test_base_main” name=“Test Base”/>

        <menuitem id=“menu_test_base” parent=“menu_test_base_main”

                  name=“Test Base” action=“action_test_seq”/>

    </data>

</openerp>

How to backup and restore OpenERP database ?


There are two methods to perform backup and restore operation for OpenERP database.

Lets go through step by step:

Method 1: Using GUI

Follow the steps to create backup and restoring database.

1) Goto Login page,
2) Click on Manage Databases,
3) There are various options available on left side bar.
4) Follow the screens displayed below.

OpenERP database backup
OpenERP database backup
OpenERP database restore
OpenERP database restore

Method 2: Using command prompt (Using PostgreSQL)

It is advisable that if backup has been taken from command prompt then restoring should be from command prompt only.

Follow the screen steps for creating backup and restore.

1) Executing following command will create a blank database.
Command: createdb –encoding=UTF-8 testdb

Create blank database
Create blank database

2) Executing following command will create a backup of database : openerp_61
Command: pg_dump -f backup_openerp_61 openerp_61

OpenERP database backup from command prompt
OpenERP database backup from command prompt

3) Execute following command will restore your db into blank database created in step 1.
Command: psql testdb < backup_openerp_61

OpenERP restore database from command prompt
OpenERP restore database from command prompt

Problem during restoring from command prompt :

Upto here, assume that everything is working in the same PC. Now let say, someone is trying to restore database using command prompt for which, the database has been backed up from another PC.

Please check following screenshots.

OpenERP database backup process
OpenERP backup database process

In above case, You can see the error message `role “john” does not exist`. It means that database has been backed up from another PC having name is ‘john’.

So now, in this case there are two solutions to restore this database as follows.

1) Either you can open dump file, and change the role name wherever you find name ‘john’ as your role displayed in following screen. Here I have changed name as ‘navrang’ in place of ‘john’.

OpenERP restore database process
OpenERP restore database process

2) Another option is, if dump file is too long to change role/owner name, then you can create a user in your PC named ‘john’ so it will work as it is.

And this way we can restore our database.

How to convert *.pyc to *.py files ?


Before few weeks I required to convert *.pyc to *.py files for one of my python project so thought to share with others.

Here is the steps to follow:

– Download plugin from below link,
https://github.com/wibiti/uncompyle2/downloads
– extract the ZIP file.
– Goto command prompt,

$ sudo python setup.py install
$ uncompyle2 -h (will give you help to process further)

I want add here is, its working on for python 2.7 only.

How to make pgAdmin connection with PostgreSQL ?


I would like to discuss regarding pgAdmin connection with PostgreSQL.

We will go with screenshots one by one.

In first screen, I have opened pgAdmin, and clicked on “Connect” icon.

When we click on “Connect” button, following window will get appear in which we have to enter postgresql information.

Press “OK” button when done with information. You will get below error message because of PostgreSQL user authentication.

Now, lets solve this error by using following commands.

Once you completed this process from command line, do the same process for entering PostgreSQL information.

You will see the following screen with connection in pgadmin.