Showing posts with label openerp-8. Show all posts
Showing posts with label openerp-8. 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

ModuleNotFoundError: No module named 'psycopg2'

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