428
###############################################################
429
# Calculations of credit, debit and balance,
430
# without repeating operations.
431
###############################################################
433
account_black_ids = account_obj.search(self.cr, self.uid, (
434
[('id', 'in', [i[0] for i in all_account_ids]),
436
('view', 'consolidation'))]))
438
account_not_black_ids = account_obj.search(self.cr, self.uid, ([('id', 'in', [
439
i[0] for i in all_account_ids]), ('type', 'in', ('view', 'consolidation'))]))
441
# This could be done quickly with a sql sentence
442
account_not_black = account_obj.browse(
443
self.cr, self.uid, account_not_black_ids)
444
account_not_black.sort(key=lambda x: x.level)
445
account_not_black.reverse()
446
account_not_black_ids = [i.id for i in account_not_black]
448
all_account_period = {} # All accounts per period
450
# Iteration limit depending on the number of columns
451
if form['columns'] == 'thirteen':
453
elif form['columns'] == 'qtr':
458
for p_act in range(limit):
461
form['periods'] = period_ids
463
if form['columns'] == 'thirteen':
464
form['periods'] = [period_ids[p_act]]
465
elif form['columns'] == 'qtr':
466
form['periods'] = p[p_act]
468
if form['inf_type'] == 'IS':
469
ctx_to_use = _ctx_end(self.context.copy())
471
ctx_i = _ctx_init(self.context.copy())
472
ctx_to_use = _ctx_end(self.context.copy())
474
account_black = account_obj.browse(
475
self.cr, self.uid, account_black_ids, ctx_to_use)
477
if form['inf_type'] == 'BS':
478
account_black_init = account_obj.browse(
479
self.cr, self.uid, account_black_ids, ctx_i)
483
for i in account_black:
492
if form['inf_type'] == 'BS':
493
dict_black.get(i.id)['balanceinit'] = 0.0
495
# If the report is a balance sheet
496
# Balanceinit values are added to the dictionary
497
if form['inf_type'] == 'BS':
498
for i in account_black_init:
499
dict_black.get(i.id)['balanceinit'] = i.balance
503
for i in account_not_black:
504
dict_not_black[i.id] = {
505
'obj': i, 'debit': 0.0, 'credit': 0.0, 'balance': 0.0}
506
if form['inf_type'] == 'BS':
507
dict_not_black.get(i.id)['balanceinit'] = 0.0
509
all_account = dict_black.copy(
510
) #It makes a copy because they modify
512
for acc_id in account_not_black_ids:
513
acc_childs = dict_not_black.get(acc_id).get('obj').child_id
514
for child_id in acc_childs:
515
dict_not_black.get(acc_id)['debit'] += all_account.get(
516
child_id.id).get('debit')
517
dict_not_black.get(acc_id)['credit'] += all_account.get(
518
child_id.id).get('credit')
519
dict_not_black.get(acc_id)['balance'] += all_account.get(
520
child_id.id).get('balance')
521
if form['inf_type'] == 'BS':
522
dict_not_black.get(acc_id)['balanceinit'] += all_account.get(
523
child_id.id).get('balanceinit')
524
all_account[acc_id] = dict_not_black[acc_id]
527
all_account_period['all'] = all_account
529
if form['columns'] == 'thirteen':
530
all_account_period[p_act] = all_account
531
elif form['columns'] == 'qtr':
532
all_account_period[p_act] = all_account
534
###############################################################
535
# End of the calculations of credit, debit and balance
537
###############################################################
435
539
for aa_id in account_ids:
454
558
if form['columns'] == 'qtr':
457
form['periods'] = p_id
459
ctx_init = _ctx_init(self.context.copy())
460
aa_brw_init = account_obj.browse(
461
self.cr, self.uid, id, ctx_init)
463
ctx_end = _ctx_end(self.context.copy())
464
aa_brw_end = account_obj.browse(
465
self.cr, self.uid, id, ctx_end)
559
for pn in range(1, 5):
467
561
if form['inf_type'] == 'IS':
468
562
d, c, b = map(z, [
469
aa_brw_end.debit, aa_brw_end.credit, aa_brw_end.balance])
563
all_account_period.get(pn-1).get(id).get('debit', 0.0), all_account_period.get(pn-1).get(id).get('credit', 0.0), all_account_period.get(pn-1).get(id).get('balance', 0.0)])
471
565
'dbr%s' % pn: self.exchange(d),
472
566
'cdr%s' % pn: self.exchange(c),
482
576
'bal%s' % pn: self.exchange(b),
487
form['periods'] = period_ids
489
ctx_init = _ctx_init(self.context.copy())
490
aa_brw_init = account_obj.browse(
491
self.cr, self.uid, id, ctx_init)
493
ctx_end = _ctx_end(self.context.copy())
494
aa_brw_end = account_obj.browse(
495
self.cr, self.uid, id, ctx_end)
497
579
if form['inf_type'] == 'IS':
498
580
d, c, b = map(z, [
499
aa_brw_end.debit, aa_brw_end.credit, aa_brw_end.balance])
581
all_account_period.get('all').get(id).get('debit', 0.0), all_account_period.get('all').get(id).get('credit',0.0), all_account_period.get('all').get(id).get('balance')])
501
583
'dbr5': self.exchange(d),
502
584
'cdr5': self.exchange(c),
515
597
elif form['columns'] == 'thirteen':
517
for p_id in period_ids:
518
form['periods'] = [p_id]
520
ctx_init = _ctx_init(self.context.copy())
521
aa_brw_init = account_obj.browse(
522
self.cr, self.uid, id, ctx_init)
524
ctx_end = _ctx_end(self.context.copy())
525
aa_brw_end = account_obj.browse(
526
self.cr, self.uid, id, ctx_end)
599
for p_num in range(12):
528
601
if form['inf_type'] == 'IS':
529
602
d, c, b = map(z, [
530
aa_brw_end.debit, aa_brw_end.credit, aa_brw_end.balance])
603
all_account_period.get(p_num).get(id).get('debit', 0.0), all_account_period.get(p_num).get(id).get('credit', 0.0), all_account_period.get(p_num).get(id).get('balance', 0.0)])
532
605
'dbr%s' % pn: self.exchange(d),
533
606
'cdr%s' % pn: self.exchange(c),
548
form['periods'] = period_ids
550
ctx_init = _ctx_init(self.context.copy())
551
aa_brw_init = account_obj.browse(
552
self.cr, self.uid, id, ctx_init)
554
ctx_end = _ctx_end(self.context.copy())
555
aa_brw_end = account_obj.browse(
556
self.cr, self.uid, id, ctx_end)
558
621
if form['inf_type'] == 'IS':
559
622
d, c, b = map(z, [
560
aa_brw_end.debit, aa_brw_end.credit, aa_brw_end.balance])
623
all_account_period.get('all').get(id).get('debit', 0.0), all_account_period.get('all').get(id).get('credit', 0.0), all_account_period.get('all').get(id).get('balance', 0.0)])
562
625
'dbr13': self.exchange(d),
563
626
'cdr13': self.exchange(c),
578
aa_brw_init = account_obj.browse(
579
self.cr, self.uid, id, ctx_init)
580
aa_brw_end = account_obj.browse(
581
self.cr, self.uid, id, ctx_end)
583
640
i, d, c = map(z, [
584
aa_brw_init.balance, aa_brw_end.debit, aa_brw_end.credit])
641
all_account_period.get('all').get(id).get('balanceinit', 0.0), all_account_period.get('all').get(id).get('debit', 0.0), all_account_period.get('all').get(id).get('credit', 0.0)])
587
644
'balanceinit': self.exchange(i),