Wednesday, November 26, 2014

Process events, functions in Background in Odoo / OpenERP by using cron

In Odoo / OpenERP, sometime we have to wait for a while when we press on a button. We have to wait after all processes completed. Like a Send Mail button, after pressing Send Mail button we have to wait program to send out the email, as long as work is in not done the openerp UI is blocked.
We can escape this waitting. In Odoo / OpenERP, we can have our processes run in background, by using ir.cron of OpenERP like this way:

Example:
In function _let_process_in_backrgound which is invoked by our button, we use a cron task, the cron task will call method:  'function': 'do_something', of model: 'model': 'hr_timesheet_sheet.sheet' (for example), agurments are:


def _let_process_in_backrgound(self, cr, uid, data, context = {}):
    timesheet_id = 1
    str_now = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
    nextcall = parser.parse(str_now) + datetime.timedelta(seconds = 60)
    pool.get('ir.cron').create(cr, uid, {
                'name': 'Cron job to do something that take very long time',
                'user_id': uid,
                'model': 'hr_timesheet_sheet.sheet',
                'function': 'do_something',
                'nextcall': nextcall,
                'args': repr([timesheet_id])
            })
    return {}


In Odoo / OpenERP, we have the method do_something like this:

def do_something(self, cr, uid, timesheet_id):
    ....
    ....
    return True

By this way we created a cron task in OpenERP to be executed at nextcall time.

Tuesday, November 11, 2014

Automatic start Xen guests after Dom0 reboot

We can start virtual machines using "xm create". However after rebooting the xen host machine, the virtual machines (xen guests) are not started automatically. 
We can make a xen guest start automatically after xen host reboot. 
Let's say the configuration for the virtual machine is in /etc/xen/XenGuest1.cfg

So we can do like this:

mkdir -p /etc/xen/auto
cd /etc/xen/auto
ln -s /etc/xen/XenGuest1.cfg .
cd -

This creates a link to autostart the virtual machine.
and "XenGuest1.cfg" file must contain the following entries:

on_xend_stop  = 'shutdown'
on_xend_start = 'start'

Thursday, October 30, 2014

Make field readonly / display or hide a field in Odoo / OpenERP conditionally

Make a field read-only or visible based on another field value in Odoo / Openerp
Ex1: Hide field field1 when field2 has no data

<field name="field1" attrs="{'invisible':[('field2', '!=', False)]}"/>

Ex2: Hide field field1 when field2 has no data:
<field name="field1" attrs="{'readonly':[('field2', '!=', False)]}"/>


Wednesday, October 15, 2014

Create new OpenERP database, and get DataError: new encoding (UTF8) is incompatible


Create new OpenERP database, and get DataError: new encoding (UTF8) is incompatible with the encoding of the template database (SQL_ASCII)
HINT: Use the same encoding as in the template database, or use template0 as template

1.1 - ERROR ? openerp.sql_db: bad query: CREATE DATABASE ENCODING 'unicode' TEMPLATE "template1" Traceback (most recent call last):

Fix steps:
Login to Postgresql:
# sudo -u postgres psql

Then execute these statements:
postgres=# UPDATE pg_database SET datistemplate = FALSE WHERE datname = 'template1';
postgres=# DROP DATABASE template1;
postgres=# CREATE DATABASE template1 WITH TEMPLATE = template0 ENCODING = ‘UNICODE’;
postgres=# UPDATE pg_database SET datistemplate = TRUE WHERE datname = 'template1'
postgres=# \c template1
psql (8.4.13)
You are now connected to database “template1″.
template1=# VACUUM FREEZE;

Then you just have to \q to quit. and rerun the openerp server + run the database creation.

Monday, September 8, 2014

Winscp to Debian / Ubuntu The server rejected SFTP connection, but it listens for FTP connections.

winscp to Debian/ubuntu:
The server rejected SFTP connection, but it listens for FTP connections.
Well the port 22 is for SSH service. So you can probably try installing openssh-server in your Debian / Ubuntu by typing
sudo apt-get install openssh-server
and then try connecting with the following details:
protocol: SSH
hostname: [IP Address of the computer]
port: 22
username: [username]
password: [password]
Hopefully this should work.

Thursday, August 21, 2014

OPENERP Technics - How to auto reload/refresh openerp GTK views each period of time?

OPENERP Technics - How to auto reload/refresh openerp GTK views each period of time?

By using attribute "auto_refresh" in definitions of model  "ir.actions.act_window"
The following example will used to reload/refresh the view related with the action_window each 10 seconds:
<record id="your_object_auto_refresh_dashboard" model="ir.actions.act_window">
        <field name="name">Your Object Dashboard</field>
        <field name="res_model">board.board</field>
        <field name="view_type">form</field>
        <field name="view_mode">form</field>
        <field name="auto_refresh">10</field>
        <field name="usage">menu</field>
        <field name="view_id" ref="board_your_object_auto_refresh_form"/>
    </record>

Wednesday, August 20, 2014

Change colors for Tree view in OpenERP 6

We can do this by inheriting the tree view, maybe our tree view has some color settings, but we can override  tree view attribute to have another color settings like this example:


The code like this will help:

<record model="ir.ui.view" id="project_workitem_task_tree_view">
            <field name="name">Project Task Tracker Tree</field>
            <field name="model">project.task</field>
            <field name="inherit_id" ref="project.view_task_tree2" />
            <field name="type">tree</field>
            <field name="arch" type="xml">
            <tree position="attributes">
   <attribute name="colors">red:project_workitem_action=='Check-in';black:project_workitem_action=='Check-out'</attribute>
</tree>
            <field name="name" position="before">
<button name="%(action_check_in_out_task)d" type='action' string='Check in / Check out' icon="terp-project" attrs="{'invisible':[('state','!=','open')]}"/>
<field name="project_workitem_action"></field>
                    <field name="last_check_out" widget="date"></field>
                <field name="last_check_out_calc" invisible="1"></field>  
</field>
</field>
       </record>