Fix general ledger total balance calculation.
Fix registers calcualtion when party is required. Task: #159087
This commit is contained in:
parent
d863d0ff14
commit
be2b099a97
|
@ -285,9 +285,9 @@ class GeneralLedgerReport(HTMLReport):
|
|||
for line in Line.browse(group_lines):
|
||||
if line.account not in accounts_w_moves:
|
||||
accounts_w_moves.append(line.account.id)
|
||||
if line.account.type.receivable or line.account.type.payable:
|
||||
currentKey = (line.account, line.party and line.party
|
||||
or None)
|
||||
if ((line.account.type.receivable or line.account.type.payable
|
||||
or line.account.party_required) and line.party):
|
||||
currentKey = (line.account, line.party)
|
||||
else:
|
||||
currentKey = (line.account,)
|
||||
if lastKey != currentKey:
|
||||
|
@ -365,7 +365,6 @@ class GeneralLedgerReport(HTMLReport):
|
|||
records[key]['lines'].append(rline)
|
||||
records[key]['total_debit'] += debit
|
||||
records[key]['total_credit'] += credit
|
||||
records[key]['total_balance'] = balance
|
||||
else:
|
||||
records[key] = {
|
||||
'account': line.account.name,
|
||||
|
@ -376,7 +375,6 @@ class GeneralLedgerReport(HTMLReport):
|
|||
'previous_balance': (balance + credit - debit),
|
||||
'total_debit': debit,
|
||||
'total_credit': credit,
|
||||
'total_balance': balance,
|
||||
}
|
||||
|
||||
if data.get('all_accounts', True):
|
||||
|
@ -395,7 +393,6 @@ class GeneralLedgerReport(HTMLReport):
|
|||
if records.get(key):
|
||||
records[key]['total_debit'] += debit
|
||||
records[key]['total_credit'] += credit
|
||||
records[key]['total_balance'] = balance
|
||||
else:
|
||||
records[key] = {
|
||||
'account': account.name,
|
||||
|
@ -405,7 +402,6 @@ class GeneralLedgerReport(HTMLReport):
|
|||
'previous_balance': (balance + credit - debit),
|
||||
'total_debit': debit,
|
||||
'total_credit': credit,
|
||||
'total_balance': balance,
|
||||
}
|
||||
|
||||
if parties:
|
||||
|
@ -433,7 +429,6 @@ class GeneralLedgerReport(HTMLReport):
|
|||
if records.get(key):
|
||||
records[key]['total_debit'] += debit
|
||||
records[key]['total_credit'] += credit
|
||||
records[key]['total_balance'] = balance
|
||||
else:
|
||||
records[key] = {
|
||||
'account': account.name,
|
||||
|
@ -443,7 +438,6 @@ class GeneralLedgerReport(HTMLReport):
|
|||
'previous_balance': (balance + credit - debit),
|
||||
'total_debit': debit,
|
||||
'total_credit': credit,
|
||||
'total_balance': balance,
|
||||
}
|
||||
|
||||
accounts = {}
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
{% if record.lines and record.party_required %}
|
||||
{% for party, lines in record.lines|groupby('party') %}
|
||||
{% set ns = namespace(total_debit=0,total_credit=0,total_balance=0) %}
|
||||
{% set ns = namespace(total_debit=0, total_credit=0) %}
|
||||
{% set previous_balance = lines[0].balance + lines[0].credit - lines[0].debit %}
|
||||
<tr>
|
||||
<td colspan="2" class="bold">{{ record.code }}</td>
|
||||
<td class="bold">{{ party.rec_name }}</td>
|
||||
<td colspan="2" style="text-align: right;">{% if record.lines %}{{ _('Previous balance...') }}{% endif %}</td>
|
||||
<td style="text-align: right;"> {{ (lines[0].balance+lines[0].credit-lines[0].debit)|render }}</td>
|
||||
<td style="text-align: right;"> {{ previous_balance|render }}</td>
|
||||
</tr>{% for l in lines %}
|
||||
<tr>
|
||||
<td>{{ l.line.date and l.line.date|render }}</td>
|
||||
|
@ -26,7 +27,7 @@
|
|||
<td colspan="2" class="bold">{{ record.code }}</td>
|
||||
<td class="bold">{{ party.rec_name }}</td>
|
||||
<td colspan="2" class="left no-wrap">{{ _('Total') }}</td>
|
||||
<td style="text-align: right;">{{ lines[-1].balance|render }}</td>
|
||||
<td style="text-align: right;">{{ (previous_balance + ns.total_debit - ns.total_credit)|render }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
{% elif record.lines %}
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
<td colspan="2" class="bold">{{ record.code }}</td>
|
||||
<td class="bold">{{ record.account }}</td>
|
||||
<td colspan="2" class="left">{{ _('Total') }}</td>
|
||||
<td style="text-align: right;" class="no-wrap">{{ record.total_balance|render }}</td>
|
||||
<td style="text-align: right;" class="no-wrap">{{ (record.previous_balance + record.total_debit - record.total_credit)|render }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</table>
|
||||
|
|
|
@ -410,31 +410,5 @@ class AccountReportsTestCase(CompanyTestMixin, ModuleTestCase):
|
|||
self.assertEqual(debit, Decimal('100.0'))
|
||||
self.assertEqual(True, all([line for k, m in records.items() for line in m['lines'] if line['line'].party]))
|
||||
|
||||
# Check balance of full general_ledger
|
||||
print_general_ledger = PrintGeneralLedger(session_id)
|
||||
print_general_ledger.start.company = company
|
||||
print_general_ledger.start.fiscalyear = fiscalyear
|
||||
print_general_ledger.start.start_period = None
|
||||
print_general_ledger.start.end_period = None
|
||||
print_general_ledger.start.parties = []
|
||||
print_general_ledger.start.accounts = []
|
||||
print_general_ledger.start.output_format = 'pdf'
|
||||
print_general_ledger.start.all_accounts = False
|
||||
_, data = print_general_ledger.do_print_(None)
|
||||
records, parameters = GeneralLedgerReport.prepare(data)
|
||||
self.assertEqual(len(records), 4)
|
||||
# balance = sum([line['balance'] for k, m in records.items() for line in m['lines']])
|
||||
results = [(m['total_balance'], m['account']) for k, m in records.items()]
|
||||
balances = [
|
||||
(Decimal('-100'), 'Main Payable'),
|
||||
(Decimal('500'), 'Main Receivable'),
|
||||
(Decimal('130'), 'Main Expense'),
|
||||
(Decimal('-600'), 'Main Revenue'),
|
||||
(Decimal('-30'), 'Main Payable'),
|
||||
(Decimal('100'), 'Main Receivable'),
|
||||
]
|
||||
for result, balance in zip(results, balances):
|
||||
self.assertEqual(result, balance)
|
||||
|
||||
|
||||
del ModuleTestCase
|
||||
|
|
Loading…
Reference in New Issue