This question has been flagged
2 Replies
2844 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

Avatar
Discard
Best Answer

try

list(set(pids))

Avatar
Discard
Author Best Answer

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.

Avatar
Discard