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

How do i return a report with multiple duplicate keys

By
Tarun Behal
on 5/4/14, 11:47 AM 770 views

I've a function which return a pdf report return { 'type': 'ir.actions.report.xml', 'report_name':'hotel.product.label', 'datas': { 'model':'hotel.product', 'ids': pids and pids or [], 'report_type': 'pdf' }, 'nodestroy': True }

pids is list of ids with duplicate keys eg: pids = [1,1,1,2,2,2,2,2,3,3,3]

The function returns a report for only unique ids i.e. [1,2,3] only. I did debugging and saw that werkzeug serving.py line #130 assert type(data) is str, 'applications must write bytes' self.wfile.write(data) self.wfile.flush()

has all keys in data attribute which is last function called before returning the report. Please let me know if to provide more specifications for the issue. Any guidance or help would be highly appreciated.

Regards, Tarun Behal tarunbehal@hotmail.com

0
Tarun Behal
On 6/17/14, 12:16 PM

Hi Lithin,

Appreciate for your response. But this wont work. Let me explain how list and sets work. First of all you need to clear your concepts on sets and lists. Very basic definitions as per usage of sets and lists is below

Sets - collection of unique elements. For eg: sets of number  [1,2,3] where all elements are unique. If you create a set of [1,1,2,3] it will remove duplicate entries and will transform it to [1,2,3]. Sets work in same way as dictionaries in python. So you can think of sets as dictionary with only keys.

Sets work by creating index of each value, so if index of a particular key is already filled, then that value is replaced, thus, eliminating duplicates. This indexing provides better performance in sets just like dictionaries.

 

Lists - collection of elements. For eg: [1,1,2,3]. You can put as many duplicate values you want in the list.

List works by simply storing each value at a address. It doesnt cares about whatever values you are storing in list.

 

Thus your solution wont work as my initial pids ([1,1,1,2,2,2,2,2,3,3,3]) after your set operation will become set of [1,2,3] and further list operation will transform it to list of [1,2,3].

 

let me know if you face any difficulty in understanding.

0
Lithin T
On 5/5/14, 5:16 AM

try

list(set(pids))

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: 5/4/14, 11:47 AM
Seen: 770 times
Last updated: 3/16/15, 8:10 AM