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