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>

Tuesday, August 19, 2014

Some useful postgresql commands

Login to Postgresql
sudo -u postgres psql [db_name]

Get PostgreSQL Version information
postgres=# SELECT version();

Create a new role with password and assign it as a supper role
postgres=# CREATE USER openerp WITH PASSWORD 'openerp';

Change the password for users
ALTER USER davide WITH PASSWORD 'hu8jmn3';

Grant a PostgreSQL user as a super user:
postgres=# ALTER USER openerp WITH SUPERUSER;








Linux command to create postgresql user with super database user role:
# sudo -u postgres createuser openerp -s

Create a new database with UTF-8 encoding
sudo -u postgres createdb mydb -E UTF-8 -T template0

Backup a db
sudo -u postgres pg_dump -o db_name > bk_name

Restore a db
psql db_name < bk_name

Drop a database
postgres=# DROP DATABASE db_name;

Change database owner
postgres=# ALTER DATABASE target_database OWNER TO new_onwer;

List all databases
postgres=# \l

List all postgresql users
postgres=#\du

COMMAND LINE: Clone a database
# sudo -u postgres createdb -O ownername -T originaldb newdb


Access Postgresql database with Postgres user without password:
# sudo -u postgres psql postgres


Sunday, August 17, 2014

Debug Odoo / OpenERP on Linux

Debug Python Program by PDB - POPULAR COMMANDSet break point by inserting this python line among python program: import pdb; pdb.set_trace()

View current code area, in pdb console
l (enter)

Run the current statement and move to next statement
n (enter)

Jump into function, in pdb consle
s (enter)

Debug again, in pdb console 
q (enter)

Explore variable, in pdb console
print var_name

Start OpenERP in debug mode:
./openerp-server.py --debug --config ./openerp-server.conf

Group with aggregation, Sort and Filter on Function Field in OpenERP

For OpenERP Version 6, we could not sorting and filtering on function field. Also we could not have group by with aggregation (Sum) on Function fields in OpenERP.

So the work around here we need 1 more field, this is not function field, but its a real field. We add this real field to Tree view, and invisible the function field.
When we calculating the function field, we update the real field = function field value, so that we can have the Tree view sorted by a function field.

I have an example here:


Let say we have the function field: last_check_out_calc which is calculated by function "get_last_check_out", beside this field we add one more real field: "last_check_out", so in the funtion "get_last_check_out" we calculate for field "last_check_out_calc" and we update "last_check_out_calc" value for "last_check_out".

Save the value into OpenERP Database by using write ORM function!
self.pool.get('project.task').write(cr, uid, [item_id], {'last_check_out': item_checkout_time})

Then we can order by "last_check_out".
We have to "last_check_out_calc" on the Tree view, but should keep it be invisible.