~unifield-team/unifield-web/uf-2264

« back to all changes in this revision

Viewing changes to addons/openerp/controllers/impex.py

  • Committer: Sebastien Alix
  • Date: 2014-01-08 14:35:26 UTC
  • Revision ID: sebastien.alix@osiell.com-20140108143526-d756ww38nex4a8rq
UF-2264 [FIX] Export issue - when using group by, export all data (recursively), not only top line information.

Show diffs side-by-side

added added

removed removed

Lines of Context:
451
451
            flds = fields_to_read[:]
452
452
            params.fields2 = fields_to_read[:]
453
453
 
454
 
            result = self.get_grp_data(rpc_obj.read_group(domain, flds, group_by, 0, 0, ctx), flds)
 
454
            data = rpc_obj.read_group(domain, flds, group_by, 0, 0, ctx)
 
455
 
 
456
            result_tmp = []  # List of processed data lines (dictionaries)
 
457
            # Closure to recursively prepare and insert lines in 'result_tmp'
 
458
            # (as much as the number of 'group_by' levels)
 
459
            def process_data(line):
 
460
                domain_line = line.get('__domain', [])
 
461
                grp_by_line = line.get('__context', {}).get('group_by', [])
 
462
                # If there is a 'group_by', we fetch data one level deeper
 
463
                if grp_by_line:
 
464
                    data = rpc_obj.read_group(domain_line, flds, grp_by_line, 0, 0, ctx)
 
465
                    for line2 in data:
 
466
                        line_copy = line.copy()
 
467
                        line_copy.update(line2)
 
468
                        process_data(line_copy)
 
469
                # If 'group_by' is empty, this means we were at the last level
 
470
                # so we insert the line in the final result
 
471
                else:
 
472
                    result_tmp.append(line)
 
473
            # Prepare recursively the data to export (inserted in 'result_tmp')
 
474
            for data_line in data:
 
475
                process_data(data_line)
 
476
            result = self.get_grp_data(result_tmp, flds)
455
477
 
456
478
            if export_format == "excel":
457
479
                return self.export_html(params.fields2, result, view_name)