Odoo Help

1

how to show distict data in many to one filed

By
Anuradha
on 8/29/13, 5:20 AM 1,711 views
i want remove repetition from my select box .my code is
    def _sel_func(self, cr, uid,context=None):
        cr.execute("select distinct on(caller) id,caller  FROM calldata1 order by caller")
        result  =  cr.fetchall()
         lst = []
     for r in result:
         dct = {}
         dct['id'] = r[o]
         dct['name']  = r[1]
         lst.append(dct)
    res_ids = [(r['id'], r['name']) for r in lst]
    return res_ids

 _columns = {
        'date_start': fields.date('Date Start', required=True),
        'date_end': fields.date('Date End', required=True),
        'caller_id':fields.many2one(
        'calldata1',
        'Caller',
         selection=_sel_func,
   )
}
but it shows all the data in select box and shows error " ValidateError

The value "7172" for the field "calldata_print_report_wiz.caller_id" is not in the selection "
when selecting this and clicking print. How to show only the data from query in select box .Any one please help?
0

Akhil P Sivan

--Akhil P Sivan--
4035
| 5 3 7
Kochi, India
--Akhil P Sivan--

Interested in exploring Odoo both technically & functionality wise.

email-id : akhilpsivan01@gmail.com

Akhil P Sivan
On 10/5/15, 7:42 AM

Hi,

Please try the "_sel_function" like this to return list containing distinct values:

def _sel_func(self, cr, uid,context=None):
cr.execute("select distinct on(caller) id,caller FROM calldata1 order by caller")
result = cr.fetchall()
lst = []
new_lst = []
for r in result:
dct = {}
dct['id'] = r[o]
dct['name'] = r[1]
lst.append(dct)
new_lst = {v['id']:v for v in lst}.values()
res_ids = [(r['id'], r['name']) for r in new_lst]
return res_ids

But you can use a functional field with type "many2one", right? Please tell me the details of what you exactly need to do?

About This Community

This platform 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.

Register

Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

0 follower(s)

Stats

Asked: 8/29/13, 5:20 AM
Seen: 1711 times
Last updated: 10/5/15, 7:54 AM