~camptocamp/account-financial-report/7.0-fix-1253659

« back to all changes in this revision

Viewing changes to account_financial_report/report/parser.py

[MERGE] Now the Consolidating Accounts are show in a more smart way
when asking the whole chart of account. Before this change if you ask for the trial Balance and include
Some consolidation account the balance shows incorrect numbers, now the parser filter correctly this
Considering the algorithm itself for this report, is not only jump the Type, we need clear correctly the list of ids
to compute efficiently the report.

Show diffs side-by-side

added added

removed removed

Lines of Context:
440
440
                                                ('view', 'consolidation'))]))
441
441
 
442
442
        account_not_black_ids = account_obj.search(self.cr, self.uid, ([('id', 'in', [
443
 
                                                   i[0] for i in all_account_ids]), ('type', 'in', ('view', 'consolidation'))]))
 
443
                                                   i[0] for i in all_account_ids]),('type', '=', 'view')]))
 
444
 
 
445
        acc_cons_ids = account_obj.search(self.cr, self.uid, ([('id', 'in', [
 
446
                                                   i[0] for i in all_account_ids]), ('type', 'in', ('consolidation',))]))
 
447
 
 
448
        account_consol_ids = acc_cons_ids and account_obj._get_children_and_consol(
 
449
                                self.cr, self.uid, acc_cons_ids) or []
 
450
 
 
451
        account_black_ids += account_obj.search(self.cr, self.uid, (
 
452
                                               [('id', 'in', account_consol_ids ),
 
453
                                                ('type', 'not in',
 
454
                                                ('view', 'consolidation'))]))
 
455
 
 
456
        account_black_ids = list(set(account_black_ids))
 
457
 
 
458
        c_account_not_black_ids = account_obj.search(self.cr, self.uid, ([
 
459
                                                   ('id', 'in', account_consol_ids),
 
460
                                                   ('type', '=', 'view')]))
 
461
        delete_cons = False
 
462
        if c_account_not_black_ids:
 
463
            delete_cons = set(account_not_black_ids) & set(c_account_not_black_ids) and True or False
 
464
            account_not_black_ids = list(set(account_not_black_ids) - set(c_account_not_black_ids))
444
465
 
445
466
        # This could be done quickly with a sql sentence
446
467
        account_not_black = account_obj.browse(
449
470
        account_not_black.reverse()
450
471
        account_not_black_ids = [i.id for i in account_not_black]
451
472
 
 
473
        c_account_not_black = account_obj.browse(
 
474
            self.cr, self.uid, c_account_not_black_ids)
 
475
        c_account_not_black.sort(key=lambda x: x.level)
 
476
        c_account_not_black.reverse()
 
477
        c_account_not_black_ids = [i.id for i in c_account_not_black]
 
478
 
 
479
        if delete_cons:
 
480
            account_not_black_ids = c_account_not_black_ids + account_not_black_ids
 
481
            account_not_black = c_account_not_black + account_not_black
 
482
        else:
 
483
            acc_cons_brw = account_obj.browse(
 
484
                self.cr, self.uid, acc_cons_ids)
 
485
            acc_cons_brw.sort(key=lambda x: x.level)
 
486
            acc_cons_brw.reverse()
 
487
            acc_cons_ids = [i.id for i in acc_cons_brw]
 
488
 
 
489
            account_not_black_ids = c_account_not_black_ids + acc_cons_ids + account_not_black_ids
 
490
            account_not_black = c_account_not_black + acc_cons_brw + account_not_black
 
491
 
452
492
        all_account_period = {}  # All accounts per period 
453
493
        
454
494
        # Iteration limit depending on the number of columns
514
554
            )  #It makes a copy because they modify 
515
555
 
516
556
            for acc_id in account_not_black_ids:
517
 
                acc_childs = dict_not_black.get(acc_id).get('obj').child_id
 
557
                acc_childs = dict_not_black.get(acc_id).get('obj').type=='view' \
 
558
                and dict_not_black.get(acc_id).get('obj').child_id \
 
559
                or dict_not_black.get(acc_id).get('obj').child_consol_ids
518
560
                for child_id in acc_childs:
 
561
                    if child_id.type == 'consolidation' and delete_cons:
 
562
                        continue
519
563
                    dict_not_black.get(acc_id)['debit'] += all_account.get(
520
564
                        child_id.id).get('debit')
521
565
                    dict_not_black.get(acc_id)['credit'] += all_account.get(
542
586
 
543
587
        for aa_id in account_ids:
544
588
            id = aa_id[0]
545
 
 
 
589
            if aa_id[3].type == 'consolidation' and delete_cons:
 
590
                continue
546
591
            #
547
592
            # Check if we need to include this level
548
593
            #