Wednesday, February 18, 2015

Run OpenERP server on any port (than port 8069) and Upgrade OpenERP custom modules/Addons using external script.


Note: By default, OpenERP runs on 8069 port.

It is suggested that while developing your custom OpenERP addons, it is a good practice to keep custom addons in a different directory (let say 'addons_custom' -->you can give any name to this directory) than to keep it in the OpenERP main addons without disturbing their main functionality.


Following snapshot shows the steps to Run OpenERP server on any port (than 8069 port) and Upgrade OpenERP custom modules/Addons.










Explanation:
Create a bash file i.e. Executebale file. e.g. test.sh
1) #!/bin/bash
--> Executes the file using sh, the Bourne shell, or a compatible shell
2) path='home/ujwala/openerp/'
--> Provide openerp path in any variable, here variable used is 'path'
Here openerp is placed in /home/ujwala directory so path is '/home/ujwala/openerp/'
3) openerp_path=$path'openerp/'
--> Provide openerp internal folder path using another variable let say 'openerp_path'
which will be a path till openerp (i.e. path='home/ujwala/openerp/') and then internal openerp folder so 'openerp_path' variable will contain $path'openerp/'
4) addons_path=$openerp_path'addons',$openerp_path'addons_custom'
In openerp 'addons' are in the internal openerp folder or else you can create 'addons_custom' folder in the internal openerp folder.
5) port=6100
-->Provide any port number, here I have used 6100 port.
Note: its not mandatory to provide a port in the script. If you don't give port no then default port 8069 will be used.
6) cd $path --> It will change the directory to given path.
7) ./openerp-server --addons-path $addons_path --xmlrpc-port $port -u hr_customs
--> this command will run the openerp server with upgradation of given custom addons at given port number.

Save this file and run it through terminal using 'sh test.sh' command.

Monday, February 9, 2015

How to format a date while printing in rml or in openoffice report in OpenERP (Odoo)


a) Default Date format on the form is:
e.g. 09-02-2015 i.e. dd-mm-YYYY

b) Default Date format while printing in reports is:
e.g. 2015-02-09 i.e. YYYY-mm-dd

and Your Desired Format to be shown in the reports,
1) As it is there in the form i.e. 09-02-2015 (dd-mm-YYYY)
2) or 09-FEB-2015 (dd-Month-YYYY)

Following is the simple method to format a date while printing in rml or in openoffice report in OpenERP (Odoo):

1) Write following code in reports .py file
import time
from datetime import datetime
#Add this line in self.localcontext.update dictionary
self.localcontext.update {
'get_date_ddmmyyyy': self.get_date_ddmmyyyy,
'get_date_ddmonthyyyy': self.get_date_ddmonthyyyy ,
}

2) #code to format date in dd-mm-YYYY
def get_date_ddmmyyyy(self, datec):
     return datetime.strptime(datec, "%Y-%m-%d").strftime("%d-%m-%Y")

3) #code to format date in dd-Month-YYYY
def get_date_ddmonthyyyy(self, datec):
     return time.strftime('%d') + '-' + datetime.strptime(datec, '%Y-%m-%d').strftime('%b').upper() + '-' + time.strftime('%Y')

4) Now Call any of this method (as per your required date format) from your reports .rml file i.e.
<para style="P2"> [[ get_date_ddmmyyyy(your_date) ]] </para>
<para style="P2"> [[ get_date_ddmonthyyyy(your_date) ]] </para>

And you are done.

Thanks,
Ujwala H. Pawade

Wednesday, January 28, 2015

Run OpenERP server and Upgrade custom modules/Addons through Command Line/Terminal

1) Change your directory to openerp.

For Example:

My openerp folder is placed in the home directory i.e. /home/ujwala/ ,

cd /home/ujwala/openerp

Normally, for running openerp server we only provide openerp-server command.

2) Now for Running the server and upgrading the custom addons in one go use the following command:

./openerp-server --addons-path=/home/ujwala/openerp/addons -u custom_module_name

here,
'--addons-path' is nothing but the total path till addons i.e. /home/ujwala/openerp/addons/,

'-u custom_module_name' used to upgrade the specified custom module

3) Also to upgrade a custom module for a specific database, use the following command:

./openerp-server –addons-path=/home/ujwala/openerp/addons -u custom_module_name -d dbname

'-d dbname' used for upgrading the module for a given database name.

Thats it.

Normally, for upgrading the modules through browser we usually go to settings-->Installed Modules then delete the “Installed” filter in the search box, search for the module and then upgrade it. Which is usually the longest process.

Whereas above commands will save your time and you can upgrade the modules by hitting a single command.

Note: For upgrading more than one custom addons/modules provide module names being comma separated i.e. -u custom_module1,custom_module2
(Dont give a space after comma.)