Monday, 9 September 2013

OpenERP XML + ORM Templates for Eclipse

Steps to apply OpenERP XML + ORM Templates for Eclipse

Template for eclipse of openERP code snippets. This snippets are build to help rapid building openERP project with great ease.  
 

1: You may get templates from svn repository.

2: After downloading the repository, start your eclipse and go to menu "Window --> Preferences".

3: To apply template for ORM, in Preferences window, click on "PyDev-->Editor" and go to "Templates" (PyDev-->Editor-->Templates).

    3.1: Click on 'Import' button and then select "templates-openerp.xml" file and press "OK".
4: To apply template for ORM, in Preferences window, click on "XML-->XML Files-->Editor" and go to "Templates" (XML-->XML Files-->Editor-->Templates).

    4.1: Click on 'Import' button and then select "Openerp-eclipse-xml-template.xml" file and press "OK".

5: Now you can use snippets in .py or .xml files.


See Videos

How to apply openERP XML+ORM Templates in eclipse

 How to use openERP XML+ORM Templates in eclipse

Tuesday, 3 September 2013

socket.error: [Errno 98] Address already in use in OpenERP

  
This error mainly raised when another process listening on port 

Solution:

 
Change the port number for OpenERP or kill that running process and restart it again, this two hints will resolve the problem.

There are several process running on your system so first Find the process which uses the port number of OpenERP and list out that process id .For do this open your terminal and type following commend


     ps aux | grep openerp 
    
just verify the process id of that OpenERP process.

address_already_in_use_in_openerp



 

Kill the process which uses the port number of OpenERP by the following command in terminal.

       sudo kill -9 procees id [ex: sudo kill -9 3550 where 3550 is process id]

Then Restart the openerp-server .now error solved .

        sudo /etc/init.d/openerp-server restart
              
If you do not want to kill process than you can also stop OpneERP process by this command.it will also resolved this error

        sudo /etc/init.d/openerp-server stop


Thanks

Sonu Chaudhary

Wednesday, 28 August 2013

How to create a module in OpenERP ?

Creating a module in OpenERP is a very simple process. All modules are located in addons folder
To create a module go to Server-->  OpenERP-->  Addons then right click on addons and create a new folder with the name of your module..
         
 For instance create a demo_module.
Follow these simple steps:
  1. create  '__init.py__' file which helps to load the class.
  2. The '__openerp__.py' file which is needed to load the module
  3. The '.py' file in which you will be able to create class methods and all the programming.
  4. '.xml file' – In this you will create the view of the module, you can define fields menu and front view of module.
  5. The __init__.py file in this init file you have to import all .py file which is used in that particular module.
           

Example :
import demo
__openerp__.py file
This file is the descriptor file in which all the description about the module is written
1.    Determine the XML files during the initialization of the server, and also
2.    Determine the Dependencies of the created module.
This OpenERP file has the following values:
name: The  name of the module.

version: The version of the module in 2 digits (1.2 or 2.0).

description: The module description (text) including documentation on how to use your module.

author: The author of the module.

website: The website of the module.

license: The license of the module .

depends: List of modules on which this module depends. The base module must always be added in the dependencies because some necessary data for the views, reports,..are included in the base module.
init : List of .xml files to load when the server is launched with the "--init=module" argument. File paths must be relative to the directory where the module is. OpenERP XML File Format is detailed in this section.

data : List of .xml files to load when the server is launched with the "--update=module" launched. File paths must be relative to the directory where the module is. OpenERP XML File Format is detailed in this section.

demo : List of .xml files to provide demo data. File paths must be relative to the directory where the module is. OpenERP XML File Format is detailed in this section.

installable : True or False. Determines if the module is install able or not.

images : List of .png files to provide screenshots.

active : True or False (default: False). Determines the modules that are installed on the database creation.

test  : List of .yml files to provide YML tests.
The XML file :-
In this , we create the view of the module and we can also customize it.
There are 4 sections..
     1.  Creating the view i.e. form,tree,kanban and graph
  1. Defining the fields
  2. Creating the action for menu
  3. Creating the menu item.
How to install module on server:-

First open the terminal and go to the server directory and type the command.

 Syntax: . /openerp-server -u [module_name] -d [database name]

For Example: ./openerp-server -u  demo_module   -d demo
Then open the server on the browser using your local host and in the setting section, you can search the module in the search box and install it.

So have fun and start making your own modules.... 

Thanks

Run two or more openerp servers simultaneously

How to work on two different versions of openerp simultaneously

   When you start openerp server by typing on terminal
   ./openerp-server
   it takes
  •    addons path- bin/addons
  •    database port: 5432
  •    run by default on port : 8069
 When you are running single server or single version of openerp  ,no special need to specify port . if u want to work with two or more server at same time , then u need to specify different port


./openerp-server  --xmlrpc-port=2000 --xmlrpcs-port=2001 --netrpc-port=2002

This command will run your server on 2000 port.
To update any module on this you need to use this command.

./openerp-server -u module -d database --xmlrpc-port=2000 --xmlrpcs-port=2001 --netrpc-port=2002



For first time Start OpenERP server like this:

./openerp-server.py --addons-path=~/home/workspace/stable/addons

The bin/addons will be considered as default addons directory which can be overriden by the ~/home/workspace/stable/addons. That is if an addon exists in bin/addons as well as ~/home/workspace/stable/addons (custom path) the later one will be given preference over the bin/addons (default path).

Two configuration files are available:
  • one for the client: ~/.openerprc
  • one for the server: ~/.openerp_serverrc
"openerprc" file  stores default information for client including default addons path.

Thanks

Sonu Chaudhary

Monday, 26 August 2013

Creating Views Dynamically in OpenERP



Normally the views are written in .xml file. At times, we are not familiar with the exact view of form, the total number of fields to be displayed or properties of fields. It may be dependent on user’s choice. This is where Dynamic Views comes into picture.
The function used to achieve dynamic view is fields_view_get() which can be inherited in any class. 




Syntax:
def fields_view_get(self, cr, uid, view_id=None, view_type=’form’, context=None, toolbar=False, submenu=False)
If we only want to alter propeties of fields,then  fields_view_get also provide scope for that.
You can change “onchange”  function or readonly ,required property of a particular field.
Example-
Overriding predefined function fields_view_get ,which also calls predefined function for the class “reception” in the line “result = super(reception, self).fields_view_get(cr, uid, view_id, view_type, context, toolbar, submenu)”.
 Generating fields for the 'Form' view on the basis of 'User' clicks Buttons.
            If 'User' clicks 'receive' Button then 3 fields with the name user_id ,vehicle_no and receiving lines are added.
            If 'User' clicks 'cancel' Button then 2 fields with the name user_id  and receiving lines  are added . Here Form name also printed according to the 'Button' clicked.
      
Process-

      1.  First add fields
                        ex-_moves_fields = result['fields']
                            _moves_fields.update({ "user_id" : {'string': 'Checked By','type': 'many2one','relation':'res.users','readonly':True},})
  1. Now add view, accordingly you want .You can add groups ,separators and apply properties like- 'readonly','required' or colspan etc..
ex-_moves_arch_lst = """<form string=" "%s" Products">
                               """% (context.get('button'))
_moves_arch_lst += """<field name="user_id"    />  ''''''
  1. Now update fields and views into returning dictionary  and return dictionary
ex- result['fields'] = _moves_fields
      result['arch'] = _moves_arch_lst
return result
1.       
def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False):       
        result = super(reception, self).fields_view_get(cr, uid, view_id, view_type, context, toolbar, submenu)
        incm_id = context.get('active_ids', False)
            if view_type=='form':
                _moves_fields = result['fields']
            if context.get('button') == 'receive':
                        _moves_arch_lst = """<form string=" "%s" Products">
                               """% (context.get('button'))
                        _moves_fields.update({
                        "user_id" : {'string': 'Checked By','type': 'many2one','relation':'res.users','readonly':True},
                        "vehicle_no" : {'string': 'Vehicle No','type': 'char','required':True},
                                    "receiving lines" : {'string': 'Receiving Moves','type': 'one2many','relation':'receiving.point'},                                   
                                    })
                        _moves_arch_lst += """<field name="user_id"    />
                                      <field name="vehicle_no"/>
                                                      <field name="receiving lines" colspan="6" nolabel="1">
                                                            <button name="cancel receiving" string="Cancel Quantity" colspan="1" icon="gtk-apply" type="object"/> """
               if context.get('button') == 'cancel':
                        _moves_arch_lst = """<form string=" "%s" Products">
                               """% (context.get('button'))
                _moves_fields.update({"user_id" : {'string': 'Checked By','type': 'many2one','relation':'res.users','readonly':True},
                                    "receiving lines" : {'string': 'Receiving Moves','type': 'one2many','relation':'receiving.point'},                                   
                                    })
                        _moves_arch_lst += """<field name="receiving_lines" colspan="6" nolabel="1">
                                                            <button name="receiving" string="Recieve Products" colspan="1" icon="gtk-go-forward" type="object"/> """
                _moves_arch_lst += """ </form>"""
             result['fields'] = _moves_fields
             result['arch'] = _moves_arch_lst
         return result

This wizard opens in case , when we click “Cancel” Button--





This wizard gets open in case,when we click “Receive” Button ---
Note -In the above example we have added lesser field ,because of length of code, any no of field can be added and on the same time we can generate view for the added fields 





Thanks
Sonu Chaudhary

How to create scheduler in OpenERP

A Scheduler helps to identify the necessary task, assigns a logical sequence to these tasks and monitor their execution. The main purpose of Scheduler is to identify tasks are on time.


There are two ways to create scheduler in ERP

a.      Functionally

b.       Technically


 
a.      Creating Scheduler Functionally
           

            Firstly simply go to Settings ->  scheduler -> scheduler_action.
Now create new Scheduler here give value in interval number and interval unit on Information page.
  1.  On Technical Data page write object name in Object field and method name (which you want to call after an interval of time) in Method field.
     2. Save the record.
b. Creating Scheduler Technically
        Simply write it in .xml (view file)
       <record id="ir_cron_mail_gateway_action" model="ir.cron">
            <field name="name">Fetchmail JKP</field>
            <field name="interval_number">3</field>
            <field name="interval_type">minutes</field>
            <field name="numbercall">-1</field>
            <field name="doall" eval="False"/>
            <field name="model">mail.compose.message</field>
            <field name="function">send_script_mail</field>
            <field name="args">()</field>
        </record>
Description of used terms: 
"scheduler_id" : is a unique xml record id
"scheduler_name" : any desirable name
"active" :  True or False determines whether the scheduler is active or not..
"user_id" : refers the user who owns the scheduler
"interval_number" : number of times the scheduler is to be called based on the "interval_type"

"interval_type" 
: it can be days, hours, minutes etc
"numbercall" : Number of time the function is called. negative number indicates no limit
"doall" : booelan field. A 'True' enables it to execute missed occurrences as soon as the server is restarts

 "model" : Name of object whose function will be called when this scheduler will run. e.g. 'res.partner'
"function" : Name of the method to be called on the object when this scheduler is executed.
 "args" : Arguments to be passed to the method. e.g. (uid,)
Thanks