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

Getting a tuple index out of range, after using % using inside the query?

By
Vikram
on 10/4/13, 2:33 AM 2,110 views
def get_data(self, form):
    total=0
    res = {}
    """
   Write sql or orm queries to get detail as a list of dict
    """
    where_sql = []
    where_sql_2=[]
    if form['partner_ids']:
        for ids5 in form['partner_ids']:
            where_sql.append("r.id=%s"%(ids5))
    if form['sale_mans_ids']:
        for idd in form['sale_mans_ids']:
            where_sql.append("u.id=%s"%(idd))
    if form['branch_ids']:
        for ide in form['branch_ids']:
            where_sql.append("ss.id=%s"%(ide))
    if where_sql:
        #~ where_sql = ' and ( '+' or '.join(where_sql)+')'
        where_sql = ' and '+' and '.join(where_sql)
    else:
        where_sql=''
    print where_sql,"SWLL LL LL LL LL LL L"
    ws = " sp.name like '%return%' "
    self.cr.execute('''select sp.name as ref,
                            sp.date as rdate,part.name as partner,
                            sp.origin as origin,
                            sp.date_done as ref_dt,
                            prod.name_template as product,
                            sm.product_qty as qty 
                    from 
                            stock_picking sp join stock_move sm on (sm.picking_id = sp.id)
                    join 
                            res_partner part on (part.id = sm.partner_id)
                    join 
                            product_product prod on (prod.id = sm.product_id)
                    where 
                            sp.name like '%return%'
                    and 
                            sp.type='in' 
                    and 
                            sp.date >=%s 
                    and 
                            sp.date <=%s '''+ where_sql+''' 
                    ''' , (form['date_from'],form['date_to']))
    data=self.cr.dictfetchall()
    return data

please refere the query satetement cr.execute(), i want to print a return products from incoming shipment. So i use reference of table stock.picking for search a string with 'return', For that i am using like '%return' when using this one give a error message as tuple out of range..

I want a return products from stock move.

please suggest any solution for that problem?

Write above query in a variable & then in the next line print the variable so you will come to know where exactly the problem is. And then pass that variable in execute().

Acespritech
on 10/4/13, 3:31 AM

Thanks i got solution.

Vikram
on 10/4/13, 3:58 AM
0
Vikram
On 10/4/13, 4:01 AM

I got a solution, Instead of using like, i use regular expression to accomplish that task, [i.e]

rather using, name like '%return', use name ~* 'return'. It works.

Thanks,

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

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

Question tools

0 follower(s)

Stats

Asked: 10/4/13, 2:33 AM
Seen: 2110 times
Last updated: 3/16/15, 8:10 AM