Thursday, 13 October 2016

Odoo(OpenERP) : Menu badge count


Steps to add Menu badge as shown in 'Next Activities' menu in Sales Module:
1) Inherit ('ir.needaction_mixin) class in your  the class as shown below.

          class YourClass(models.Model):
                   _name = "your.class"
                   _inherit = ['ir.needaction_mixin']

2) Add '_needaction_domain_get' function in your class as shown below code.Here we have to give domain filter based on which the count is calculatated and displayed in the menu.

         @api.model
         def _needaction_domain_get(self):
                  return [('state', '=', 'on_going')]



Monday, 3 October 2016

Odoo Python Tips : change unicode list into normat list format


The following code is useful to change the unicode string list format into normal list
-------------
employee_list = [int(i) for i in self.employee_list.strip('[]').split(',')]
-------------

Odoo Python Date Range : Find out the date range as list using two date.


Step 1 : Create a file as validations.py and put the below code
-------------------
def get_date_range(date_from, date_to):
    date_from_year = date_from[:4]
    date_from_month = date_from[5:7]
    date_from_date = date_from[8:11]
   
    date_to_year = date_to[:4]
    date_to_month = date_to[5:7]
    date_to_date = date_to[8:11]
   
    d1 = date(int(date_from_year), int(date_from_month), int(date_from_date))
    d2 = date(int(date_to_year), int(date_to_month), int(date_to_date))
    delta = d2 - d1
    date_range_list = []
    for i in range(delta.days + 1):
        r_date = d1 + td(days=i)
        date_range_list.append(str(r_date))
    return date_range_list
--------------------

Step 2 : Use the following code in wherever you want to find out the date range and to return in list format.
--------------------
date_list = validations.get_date_range(date_from, date_to)
--------------------

FUI:
you can separate the date as year, month, date using below code too.
date_from_year = date_from[:4]
    date_from_month = date_from[5:7]
    date_from_date = date_from[8:11]