Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

OpenERP 7 How to null check ? [Closed]

By
priyankahdp
on 4/19/13, 1:00 AM 2,089 views

The Question has been closed

by
priyankahdp
on 04/22/2013 04:53:52

below shows my source code fragment.i need to check if null values returns from both functions.?

1.when i use fresh DB then bpl_worker will empty & then its return getitem error.i added coalesce keyword also but result same (function 1)

2.when i use fresh DB then bpl.company.define table will empty and its also return error.how to check null in that type function.? (function 2)

i tried with below code.but result same

if no_define_object_no[0].current_no :

please advice me on this.all times when i use new DB i have to face that issue

def _max_reg_no(self, cr, uid, context=None):
    cr.execute("""
    select coalesce(register_no, 'W00001') as reg_no
    from bpl_worker
    where id in (select max(id) from bpl_worker)
    """)
    if cr:
        res = cr.fetchone()[0]
        emp_no = str(res)
        emp_int = emp_no[1:6]
        emp_no_int = int(emp_int)
        result = 'W' + (str(emp_no_int + 1).zfill(4))
        return result

def on_change_division(self, cr, uid, ids, division_id, context=None):
    if division_id:
        division_object = self.pool.get('bpl.division.n.registration')
        division_browse = division_object.browse(cr, uid, division_id, context=context)
        result_division_id = division_browse.id
        search_condition = [
                          ('department_id', '=', result_division_id)
                          ]
        no_define_object = self.pool.get('bpl.company.define')
        no_define_id = no_define_object.search(cr, uid, search_condition, context=context)
        no_define_object_no = no_define_object.browse(cr, uid, no_define_id, context=context)
        return {'value': {'emp_no': no_define_object_no[0].current_no }}
4

Sudhir Arya (SA)

--Sudhir Arya (SA)--
10150
| 6 8 8
Ahmedabad, India
--Sudhir Arya (SA)--

Working as an OpenERP/Odoo developer and a Team Leader 

Top 5 Odoo contributor On Stackoverflow

LinkedIn

Blog

Stackoverflow

Sudhir Arya (SA)
On 4/19/13, 3:10 AM

Try this code:

emp_no = no_define_object_no and no_define_object_no[0].current_no or False
return {'value': {'emp_no':  emp_no}}

thanks Arya its worked.wat about sql query null checking.? (my 1st function.)

priyankahdp
on 4/19/13, 5:03 AM

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

0 follower(s)

Stats

Asked: 4/19/13, 1:00 AM
Seen: 2089 times
Last updated: 3/16/15, 8:10 AM