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

Append data - what I'm doing wrong ?

By
Dr Obx
on 1/11/16, 5:56 AM 555 views

Browsing data: - gathering product_id and qty in selected period of time (last 6 months) in location 'production'

  for obj in self.browse(cr, uid, ids):

days = obj.nod

weeks = obj.now

months = obj.nom

cr.execute(""" select product_id, sum(qty) from stock_quant where write_date ::date>=to_date('%s', 'YYYY-MM-DD') and

write_date ::date<= to_date('%s', 'YYYY-MM-DD') and location_id =%s group by product_id;""" %(obj.st_date, obj.en_date, obj.location_id.id))

toty = cr.fetchall()

Browsing data and appending in_stock: -  gathering qty for product in other locations except 'production'

for prod in toty:

cr.execute(""" select sum(qty) from stock_quant where product_id = %s and location_id != 7;""" %(int(prod[0])))

in_stock = cr.fetchall()

tot_qty.append([prod[0], prod[1], in_stock[0][0]])

Browsing again and appending lmsq to the existing one: - gathering qty in selected period of time (last 1 month) in location 'production'

for prod in toty:

cr.execute(""" select sum(qty) from stock_quant where product_id = %s and write_date ::date>=to_date('%s', 'YYYY-MM-DD') and

write_date ::date<= to_date('%s', 'YYYY-MM-DD') and location_id = 7;""" %(int(prod[0]), obj.mt_date, obj.en_date))

lmsq = cr.fetchall()

print 'LMSQ ',lmsq

# joining lists

print 'PROD ',tot_qty, prod

tot_qty.append([prod[0], prod[1], in_stock[0][0]], lmsq[0][0]) 

What I'm doing wrong ?

ERROR:

File "/usr/lib/python2.7/dist-packages/openerp/addons/iProdLoc/iprodloc.py", line 124, in moves_get

tot_qty.append([prod[0], prod[1], in_stock[0][0]], lmsq[0][0])

TypeError: append() takes exactly one argument (2 given)

0

Pawan

--Pawan--
1267
| 4 3 5
Hyderabad, India
--Pawan--


Pawan
On 1/12/16, 12:45 AM

Rob,
Your way of appending Imsq to the already creating list is not correct.

As you already have a list created after creating in_stock, and then you are trying to add imsq to that samelist for that same [product, qty, in_stock] combination which will not work like the way you are trying to do it....

Keep both the fetchings under one loop only:

for prod in toty:

    Browsing data and appending in_stock: -  gathering qty for product in other locations except 'production'

    cr.execute(""" select sum(qty) from stock_quant where product_id = %s and location_id != 7;""" %(int(prod[0])))

    in_stock = cr.fetchall()

    Browsing again and appending lmsq to the existing one: - gathering qty in selected period of time (last 1 month) in location 'production'

    cr.execute(""" select sum(qty) from stock_quant where product_id = %s and write_date ::date>=to_date('%s', 'YYYY-MM-DD') and write_date ::date<= to_date('%s', 'YYYY-MM-DD') and location_id = 7;""" %(int(prod[0]), obj.mt_date, obj.en_date))

    lmsq = cr.fetchall() 

    #Now finally after retrieving all data, form a list and append to tot_qty..

    tot_qty.append([prod[0], prod[1], in_stock[0][0]], lmsq[0][0])

HOPE IT HELPS ;)

Hehehe Hi Pawan, Already sorted it. It works beautifully :) However, I have a question for you my friend. Once I create a list of products and I would like to put it into email. Would you help me with it ? Its easy if I'm adding only one product and sending email but I can't make it work for more than one ....

Dr Obx
on 1/12/16, 10:22 AM

Or how to add data from another object. For example, stock_check is creating a list then list is passed to product_data. How can I get those data and use it in email ? Browse product_data, create another list inside the def mailing .... ?

Dr Obx
on 1/12/16, 10:29 AM

Rob, you can use current object field only to loop on in an email template, as template works on one object at a time, like if you are having any one2many or many2many then you can use
  % for row in object.[one2many/many2one FIELD]:
 ${row.[FIELD] or ""}
 ${row.[FIELD] or ''}
 ${object.[FIELD] or ''}
 %endfor
This will print all the records from the [one2many/many2one FIELD] under that object...
OTHERWISE
You can format your string for body of email at your logic(.py) only and then replace the templates body with your string before sending
Regards!

Pawan
on 1/13/16, 1:30 AM
0
Swapnesh
On 1/11/16, 10:06 AM

Hello,

Please use 

tot_qty.append([prod[0], prod[1], in_stock[0][0], lmsq[0][0]]) 

instead of 

tot_qty.append([prod[0], prod[1], in_stock[0][0]], lmsq[0][0]) 

Thanks

Problem solved :)

Dr Obx
on 1/12/16, 10:23 AM

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

1 follower(s)

Stats

Asked: 1/11/16, 5:56 AM
Seen: 555 times
Last updated: 1/12/16, 12:45 AM