Showing posts with label openerp. Show all posts
Showing posts with label openerp. Show all posts

Tuesday, 29 September 2015

Domain in Odoo

In this article, we will see some theory of domain.

A domain is a list of criteria, each criteria being a triple (either a list or a tuple) of (field_name, operator, value).

Where,

 - field_name:

         It's string type and must be from the current model or any relational traversal field through the Many2one field using membership (.) dot operator.

 - operator:

         It's for comparing field's value with passed value.
Valid operator list (>, >=, <, <=, =, !=, =?, ilike, like =like, =ilike, not like, not ilike, childs_of, in, not in)

 - value:

         It's for comparing with field's value.

Multiple criteria can be joined with three logical operators. Logical AND, logical OR, logical NOT.

Let's take a real inputs example:

Suppose we have 10 records like:

Record 1: Openerp

Record 2: openerp

Record 3: Opensource

Record 4: opensource

Record 5: Open

Record 6: open

Record 7: Odoo

Record 8: odoo

Record 9: Odooopenerp

Record 10: OdooOpenerp

OUTPUT:

'like':

[('input', 'like', 'open')] -  Returns case sensitive (wildcards - '%open%') search.

O/p: open, opensource, openerp, Odooopenerp

'not like':

[('input', 'not like', 'open')] -  Returns results not matched with case sensitive (wildcards - '%open%') search.

O/p: Openerp, Opensource, Open, Odoo, odoo, OdooOpenerp

'=like':

[('name', '=like', 'open')] - Returns exact (=  'open') case sensitive search.

O/p: open

'ilike':


[('name', 'ilike', 'open')] - Returns exact case insensitive (wildcards - '%open%') search.

O/p: Openerp, openerp, Opensource, opensource, Open, open, Odooopenerp, OdooOpenerp

'not ilike': [('name', 'not ilike', 'open')] - Returns results not matched with exact case insensitive (wildcards - '%open%') search.

O/p: Odoo, odoo

'=ilike':

[('name', '=ilike', 'open')] - Returns exact (=  'open' or 'Open') case insensitive search.

O/p: Open, open

'=?': 

name = 'odoo'
parent_id = False
[('name', 'like', name), ('parent_id', '=?', parent_id)] - Returns name domain result & True

name = 'odoo'
parent_id = 'openerp'
[('name', 'like', name), ('parent_id', '=?', parent_id)] - Returns name domain result & parent_id domain result

'=?' is a short-circuit that makes the term TRUE if right is None or False, '=?' behaves like '=' in other cases

'in':

[('value1', 'in', ['value1', 'value2'])] - in operator will check the value1 is present or not in list of right term

'not in':

[('value1', 'not in', ['value2'])] - not in operator will check the value1 is not present in list of right term
While these 'in' and 'not in' works with list/tuple of values, the latter
'=' and '!=' works with string

'=':

value = 10
[('value','=',value)] - term left side has 10 in db and term right our value 10 will match

'!=':


value = 15
[('value','!=',value)] - term left side has 10 in db and term right our value 10 will not match

'child_of':


parent_id = '1' #Agrolait
'child_of':
[('partner_id', 'child_of', parent_id)]
- return left and right list of partner_id for given parent_id

'<=', '<', '>', '>=':

These operators are largely used in openerp for comparing dates - [('date', '>=', date_begin), ('date', '<=', date_end)]. You can use these operators to compare int or float also.



For details/reference visit domains in Odoo

I hope you like this article. Share your views to improve content. Happy Learning !!!

Sunday, 27 September 2015

Email validation in Odoo

This article will help us to validate Email field on Partner form.

First of all, we need to understand argument of _constraints.

    _constraint has list of arguments in which

          1. Method is name,

          2. Warning/Error message and

          3. List of field name.

Method will be fire based on, change of field value given as third argument in _constraint.

Now we need to set constraint for Email field.

Here is code for constraint.
  
    _constraints = [
        (_validate_email, 'Please enter a valid email address.', ['email']),
    ]

Here is code for method.

    @api.multi
    def _validate_email(self):
        for partner in self:
            if re.match("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$", partner.email) == None:
                return False
        return True

NOTE:

         Warning/Error message will be populate, only when method will return False.

I hope you like this article. Share your views to improve content. Happy Learning !!!

Monday, 17 August 2015

one2many, many2many, many2one field in openerp


In OpenERP/Odoo, we have one2many and many2many datatype field. For add, update, delete we have some trick to link with record, which are listed below.

1. (0, 0,  { values })    link to a new record that needs to be created with the given values dictionary

2. (1, ID, { values })    update the linked record with id = ID (write *values* on it)

3. (2, ID)                     remove and delete the linked record with id = ID (calls unlink on ID, that will delete the object completely, and the link to it as well)

4. (3, ID)                     cut the link to the linked record with id = ID (delete the relationship between the two objects but does not delete the target object itself)

5. (4, ID)                     link to existing record with id = ID (adds a relationship)

6. (5)                          unlink all (like using (3,ID) for all linked records)

7. (6, 0, [IDs])             replace the list of linked IDs (like using (5) then (4,ID) for each ID in the list of IDs)


one2mnay we will use 1,2,3 points and for many2many we will use all the points.

For many2one field we only need to set record ID.


For more details, Please visit Odoo documentation

Youtube Video 

Friday, 31 July 2015

Odoo 8 release notes


Here is reference link for more details.

Key improvements of version 8 include, by order of priority:
  • Usability & productivity improvements: Odoo 8 is faster, easier to use and configure 
  • Improvement of existing apps: 732 tasks covering most applications
  • New website builder and CMS 
  • New apps: Point of sales with full hardware support, marketing apps, a new WMS and a CMS,
  • The frontend to every app: online jobs offers, booking of events, quotation builder and electronic signature, etc.
  • Technical improvements: refactoring of the framework (new API)
  • Removed modules / features

Thursday, 28 May 2015

How to set default value in Odoo ?

When User open a form view at that time default value display and than after save record it will display value based on our requirement.

Here is char type field example which will display a string before save record default and than it will show different string.

We will use function filed for that. This field will not take input from the user click that will only used for information purpose.

Here is code example:

def _default_get(self, cr, uid, context=None):
    print " This function called before new record create "
    res = 'bhavesh'
    return res     

def _set_value(self, cr, uid, ids, name, args, context=None):
    print " This function called at time of saving record and form view load "
    res = {}
    for i in self.browse(cr, uid, ids, context=context):
        res[i.id] = 'odedra'
    return res

_columns = {
    'value': fields.function(_set_value, type='char', string='Value'),
}

_defaults = {
    'value': _default_get,
}

I hope you like this article. Share your views to improve content. Happy Learning !!! 

Monday, 20 April 2015

How to start Libreoffice Server and Telnet Server in Ubuntu?

In Odoo/OpenERP, when we are generating a Aeroo report, we must start these below two server.
  1. Libreoffice Server and
  2. Telnet Server
If Libreoffice is not install in Ubuntu than first install with these command.

    sudo apt-get update
    sudo apt-get upgrade
    sudo apt-get install libreoffice

Start Libreoffice with these command.

cd /usr/lib/libreoffice/program/ #to move to the libreoffice:

./soffice -nologo -nofirststartwizard -headless -norestore -invisible "-accept=socket,host=localhost,port=8100,tcpNoDelay=1;urp;" #Open Libreoffice server

If Telnet Server is not install in Ubuntu than visit Telnet installation guidance

Don't stop Libreoffice server and open another terminal for test localhost with Telnet Server
 
    telnet localhost 8100

And than Go to Settings/ Modules / Update module list : Search for 'ooo' , you will find 'report_aeroo_ooo'. Install that module.

And Finally, Configure OpenOffice.org connection from Setting/Technical/Configure OpenOffice.org co. and press connect.


I hope you like this article. Share your views to improve content. Happy Learning !!!

Monday, 9 February 2015

How related field work in Odoo 8, 9, and 10?


Let's take an example of Sale Order Line. Scenario is like when we add Product in sale order line at time, the Product Category name should be fill up. For that we need to do two  things.

  1. add related field in 'sale.order.line' and give it in view at proper place
  2. need to override onchange of product, if we don't want to override the onchange than at the time of record save it will also save the product category name.

Here is .py code:

Old API:

class sale_order_line(osv.Model):
    _inherit = 'sale.order.line'

    _columns = {
        'product_categ_name': fields.related('product_id', 'categ_id', 'name', type='char', string='Product Category', store=True, readonly=True),
}

New API:

from openerp import api, fields, models, _

class SaleOrderLine(models.Model)
    _inherit = 'sale.order.line'

    product_categ_name = fields.Char(related='product_id.categ_id.name', string='Product Category', store=True, readonly=True)

Here is .xml file

<?xml version="1.0" encoding="utf-8"?>
<openerp>
    <data>
   
        <record id="view_product_category_related_sale_line" model="ir.ui.view">
            <field name="name">view.product.category.related.sale.line</field>
            <field name="model">sale.order</field>
            <field name="inherit_id" ref="sale.view_order_form" />
            <field name="arch" type="xml">
                <xpath expr="//field[@name='order_line']/form/group/group/field[@name='product_id']" position="after">
                    <field name="product_categ_name"/>
                </xpath>
            </field>
        </record>

    </data>
</openerp>


Here is screen shot of it


More about on related field, take a look here

I hope you like this article. Share your views to improve content. Happy Learning !!!

Youtubde Video 

Friday, 23 January 2015

How to replace kanban image using XPATH in Odoo?

We take an example for Partner Object like either partner has checked with Is a Company than we will show the different image or already uploaded image will show.

In Customer Form has field  " " based on it, we will show image in kanban view.

For that we only need to put .xml code.

Here is code:

<record model="ir.ui.view" id="res_partner_kanban_view_extened">
    <field name="name">res.partner.kanban.view.extened</field>
    <field name="inherit_id" ref="base.res_partner_kanban_view"/>
    <field name="model">res.partner</field>
    <field name="arch" type="xml">
        <xpath expr='//kanban/templates/t/div/a/t/t[@t-if="record.is_company.raw_value === true"]' position="replace">
        <!-- check condition weather IS A COMPANY is checked or not -->
            <t t-if="record.is_company.raw_value === true">
                <img  src="custom_patht_of_image" class="oe_kanban_image"/>
            </t>
        </xpath>
    </field>
</record>

I hope you like this article. Share your views to improve content. Happy Learning !!!

Youtube Video 

Monday, 5 January 2015

How to change "Powered by Odoo" footer in Odoo?



First go to your Odoo web module and open below file.

    addons => web => views => webclient_templates.xml

Now find this tag <div class="oe_footer">

<div class="oe_footer">
   Powered by <a href="http://www.openerp.com" target="_blank"><span>Odoo</span></a>
</div>

We can change anything like your company name or else. Now I change with "Odedra" save it and restart your server and upgrade your web module form GUI and you will got your changes.

<div class="oe_footer">
   Powered by <a href="http://www.openerp.com" target="_blank"><span>Odedra</span></a>
</div>
 


I hope you like this article. Share your views to improve content. Happy Learning !!!

Youtube Video



Saturday, 20 December 2014

How to display custom header and footer in all page in RML report in OpenERP 7?

Here is page template tag that may used it for display custom header and footer in all pages.

According to the report view, we need to change x and y co-ordinates. 

<pageTemplate id="first">
  <frame id="first" x1="30.0" y1="27.0" width="508" height="815"/>
    <pageGraphics>
        <image x="1.3cm" y="26.0cm" height="90.0">
              [[company.logo or removeParentNode('image')]]</image>
        <place x="16.6cm" y="25.3cm" height="1.8cm" width="15.0cm">
        <para fontSize="7.0" fontName="Helvetica" >
              [[ display_address(company.partner_id) or  '' ]]</para>
        </place>
        <lines>1.3cm 24.9cm 19.9cm 24.9cm</lines>
    </pageGraphics>
</pageTemplate>

I hope you like this article. Share your views to improve content. Happy Learning !!!  

Youtube Video 

Saturday, 13 December 2014

How to hide small edit button beside many2one field in Odoo?


Here is Purchase order form view.


For that we need to Active debug mode from the right hand side and click to the Admin and than About Odoo.


Click to the Active the Active Developer mode.


Now select Edit Formview from the Debugview.


Edit this attribute to partner_id field => options='{"no_open": True}'


Save it and Refresh the browse or press F5. We may see it now navigate menu is hide from there.



I hope you like this article. Share your views to improve content. Happy Learning !!!

Youtube Video 

How to create recurring invoice in Odoo?

First install "Recurring Documents" module.
 

Now follow this path. Settings => Technical => Automation => Recurring Types and create record with name should be any thing and object must be Invoice.


Settings => Technical => Automation => Recurring Documents and create document for invoice. In Source Document, we may select which invoice we need to create recurring.

 
Save this record and click on red button called "Process"


We can see that Cron Job is created.



Documents Created tab is empty because currently no invoice is created.


 After Scheduler run the document is created. (NOTE: I have changed interval unit from Months to Days so next interval can match and create invoice instantly. Otherwise it will create once on monthly basis.)
 
 
Cron Job look like.


Below image is a old invoice which is we select in Source Document.


 
Here is new Invoice which is created from cron job. 
 


I hope you like this article. Share your views to improve content. Happy Learning !!! 

Youtube Video 

Friday, 12 December 2014

XML-RPC web services in OpenERP

XML-RPC is known as a web service. Let's understand how's work in OpenERP.


import xmlrpclib

username = 'admin' #the login user name
pwd = 'admin'      #the password of the user
dbname = 'my_db'    #the database name

# Connection String ........

sock_common = xmlrpclib.ServerProxy('http://localhost:8069/xmlrpc/common')
uid = sock_common.login(dbname, username, pwd)
sock = xmlrpclib.ServerProxy('http://localhost:8069/xmlrpc/object')

#create partner record

partner = {
   'name': 'Odedra',
   'lang': 'en_US',
}

partner_id = sock.execute(dbname, uid, pwd, 'res.partner', 'create', partner) #partner is created

print "\n\n===Partner Create id => ", partner_id

#how to update partner record?

vals = {'street': 'Chhaya Road',
   'zip': '360575',
   'city': 'Porbandar',
   'phone': '+2244202',
   'fax': '+2244202222',
}

update_data = sock.execute(dbname, uid, pwd, 'res.partner', 'write', partner_id, vals) #record update successfully

print "\n\n===Is Partner updated? => ", update_data

#how to read partner record?

fields = ['name', 'city', 'zip']

read_data = sock.execute(dbname, uid, pwd, 'res.partner', 'read', partner_id, fields) #read data successfully

print "\n\n===Yes, Here is value for Partner record => ", read_data

#how to search a partner record?

query = [('name', 'ilike', 'Odedra')] #query clause
ids = sock.execute(dbname, uid, pwd, 'res.partner', 'search', query) #give the id of searched record otherwise it's return empty list

print "\n\n===how many partner founds? => ", len(ids)
print "\n\n===What their id? => ", ids

#how to call method?
#NOTE: First we have too method on res.partner object than and than we can call that method

res = sock.execute(dbname, uid, pwd, 'res.partner', 'method_name', [partner_id])

print "\n\n===Is method called? => ", res

#how to delete partner record?

result = sock.execute(dbname, uid, pwd, 'res.partner', 'unlink', partner_id) #delete the partner

print "\n\n===Is Partner deleted ? => ", result

print "\n\nGoodBye...."

I hope you like this article. Share your views to improve content. Happy Learning !!!

Youtube Video

Wednesday, 10 December 2014

How to create constraints in OpenERP v7, Odoo 8,9, and 10 ?

This will help you to create a constraints in OpenERP.

_constraint is a pre-define field in OpenERP. It is used for adding a constraint on the object.

It takes list of tuple as its argument. The tuple inside the list contains three parameter.
  1. Method (to check the constraint)
  2. The Message (Pop-up message for End User)
  3. List of Fields (fields to apply the constraint)
_constraint will fire if the condition returns False on creation and updation of the record and display the message.

Here is an example of integer data-type. It's fire a constraint if length is not positive.

Here is .py side code:

Old API:
 
from openerp.osv import fields, osv
class res_partner(osv.Model):
    _inherit = 'res.partner'

    _columns = {       
        'length': fields.integer('Length', size=64),
    }

    def _check_number(self, cr, uid, ids, context=None):
        for partner in self.browse(cr, uid, ids, context=context):
            if partner.length < 0:
                return False
        return True    
   
    _constraints = [
        (_check_length, 'Length must be Positive.', ['length'])
    ]

New API:

from openerp.exceptions import ValidationError
from openerp import api, fields, models, _

class Partner(models.Model):
    _inherit = 'res.partner'

    @api.one
    @api.constrains('length')
    def _check_length(self):
        if self.length < 0:
            raise ValidationError("Length must be Positive.")

    length = fields.integer('Length', size=64)

Here is .xml side code:

<?xml version="1.0"?>
<openerp>
    <data>
        <!-- res partner form view-->
        <record id="view_res_partner_extended_form" model="ir.ui.view">
            <field name="name">res.partner.extended.form.view</field>
            <field name="model">res.partner</field>
            <field name="inherit_id" ref="base.view_partner_form"/>
            <field name="arch" type="xml">
                <field name="email" position="after">
                    <field name="length"/>
                </field>
            </field>
        </record>
    </data>
</openerp>


I hope you like this article. Share your views to improve content. Happy Learning !!!

Youtube Video 

Tuesday, 9 December 2014

How to install Wkhtmltopdf package in Odoo?

This will help for Ubuntu system.
 
Once we install Odoo v8 and try to print report. WE may see notice at right hand side in black box with message.

You should upgrade your version of Wkhtmltopdf to at least 0.12.0 in order to get a correct display of headers and footers as well as support for table-breaking between pages.
   
That means Odoo v8 support the 0.12.0 or greater  than version of Wkhtmltopdf. So need to just follow the below steps:

cd /tmp
wget http://sourceforge.net/projects/wkhtmltopdf/files/archive/0.12.0/wkhtmltox-linux-amd64_0.12.0-03c001d.tar.xz

tar -xvf wkhtmltox-linux-amd64_0.12.0-03c001d.tar.xz
cd wkhtmltox
cd bin/
mv wkhtmltopdf /usr/bin/

mv wkhtmltoimage /usr/bin/
cd ..
cd lib/
mv libwkhtmltox.so.0 /lib64
mv libwkhtmltox.so.0.12 /lib64
mv libwkhtmltox.so.0.12.0 /lib64

cd /usr/bin/
sudo chown root:root wkhtmlto*
cd /lib64
sudo chown root:root libwkhtmlto*
sudo chown -h root:root libwkhtmlto*

Now reboot the system using this command.

sudo reboot

After than we need to start the Odoo server, Login in database and follow the below GUI step:

Configuration -> Parameter -> Parameters Systems
Create a new record like :

    Tipe : webkit_path
    Value : /usr/bin/wkhtmltopdf
   
If you show above record in your Odoo System that means now everything is fine.

I hope you like this article. Share your views to improve content. Happy Learning !!!

Youtube Video

Monday, 8 December 2014

ImportError: No module named pooler

In odoo, Many people have problem with pooler import. So here is trackback and below is solution for that.

   Traceback (most recent call last): File "/usr/bin/openerp-server", line 10, in <module> openerp.cli.main()

    File "/usr/lib/pymodules/python2.7/openerp/cli/__init__.py", line 51, in main __import__(m)
    File "/usr/lib/pymodules/python2.7/openerp/modules/module.py", line 133, in load_module mod = imp.load_module('openerp.addons.' + module_part, f, path, descr)
    File "/usr/lib/pymodules/python2.7/openerp/addons/account_test/__init__.py", line 1, in <module> import account_test
    File "/usr/lib/pymodules/python2.7/openerp/addons/account_test/account_test.py", line 32, in <module> import pooler
    ImportError: No module named pooler

Solution:-
 
First go to path location /usr/lib/pymodules/python2.7/openerp/addons/account_test/account_test.py and line number 32

Now replace
    import pooler
to
    from openerp import pooler  
  
Now restart the server.

I hope you like this article. Share your views to improve content. Happy Learning !!!

How to install OpenERP/Odoo from Github?


I would like to share with you, how to Install Odoo(formerly OpenERP) from github on Ubuntu system.

Odoo Github

1. First we need to install git in our Ubuntu system, for that open our terminal or or hit Ctrl+Alt+t

 a) First we need to update apt source list
  
     sudo apt-get update

 b) Upgrade apt source package

     sudo apt-get upgrade

c) Now install git

    sudo apt-get install git

2. Install Python packages  which required for Odoo installation

sudo apt-get install graphviz ghostscript postgresql-client \
python-dateutil python-feedparser python-matplotlib \
python-ldap python-libxslt1 python-lxml python-mako \
python-openid python-psycopg2 python-pybabel python-pychart \
python-pydot python-pyparsing python-reportlab python-simplejson \
python-tz python-vatnumber python-vobject python-webdav \
python-werkzeug python-xlwt python-yaml python-imaging


sudo apt-get install gcc python-dev mc bzr python-setuptools python-babel \
python-feedparser python-reportlab-accel python-zsi python-openssl \
python-egenix-mxdatetime python-jinja2 python-unittest2 python-mock \
python-docutils lptools make python-psutil python-paramiko poppler-utils \
python-pdftools antiword postgresql


3. Install PostgreSQL database

    sudo apt-get install postgresql

4. Install Pgadmin

    sudo apt-get install pgadmin

5. Create User into Postgres Database Odoo

    sudo -u postgres createuser -s odoo

6. Download Odoo from Github to your system

a) make directory in home

    sudo mkdir home/openerp-v8

b) move to  directory

    cd home/openerp-v8

c) Download odoo from Github

    sudo git clone https://github.com/odoo/odoo.git

7. Once finish a download need to run odoo server 

a) Go to oddo path

   cd home/openerp-v8/odoo

b) Run a odoo server

./openerp-server


8. To check Odoo installation is perfectly work  on your system so for that  just open browser type http://localhost:8069

9. Odoo login screen. Currently it will show below screen because first time we don't have database. 

Odoo Database Manager

I hope you like this article. Share your views to improve content. Happy Learning !!!

ModuleNotFoundError: No module named 'psycopg2'

  Odoo 18:  Traceback (most recent call last): File "/home/bodedra/odoo18/demo/src/odoo/./odoo-bin", line 5, in ...