Hello,
In some countries it is necessary to have totals at the end of the general
ledger
report, in fact three kinds, one for the total of previous period,
one for the current period and a final general total.
To do this we have to add the following code in account.py file of account
module:
(*after line number 1189 - For version 3.2.1*)
### Add totals in General Ledger
######################################
# find the current period and create the filters
MoveLine = pool.get('account.move.line')
current_periods = [item for item in periods if item not in
start_periods]
clause_end_period = [
('account', 'in', [a.id for a in accounts]),
('period', 'in', [p.id for p in end_periods]),
('state', '!=', 'draft'),
]
clause_start_period = [
('account', 'in', [a.id for a in accounts]),
('period', 'in', [p.id for p in start_periods]),
('state', '!=', 'draft'),
]
clause_current_period = [
('account', 'in', [a.id for a in accounts]),
('period', 'in', [p.id for p in current_periods]),
('state', '!=', 'draft'),
]
if data['posted']:
clause_end_period.append(('move.state', '=', 'posted'))
clause_start_period.append(('move.state', '=', 'posted'))
clause_current_period.append(('move.state', '=', 'posted'))
# find the lines
total_end_lines = MoveLine.search(clause_end_period,
order=[
('account', 'ASC'),
('date', 'ASC'),
])
total_start_lines = MoveLine.search(clause_start_period,
order=[
('account', 'ASC'),
('date', 'ASC'),
])
total_current_lines = MoveLine.search(clause_current_period,
order=[
('account', 'ASC'),
('date', 'ASC'),
])
# create the placeholders
localcontext['total_start_debit'] = sum((x['debit'] if
start_period.id != 1 else 0 for x in total_start_lines))
localcontext['total_start_credit'] = sum((x['credit'] if
start_period.id != 1 else 0 for x in total_start_lines))
localcontext['total_current_debit'] = sum((x['debit'] for x in
total_current_lines) )
localcontext['total_current_credit'] = sum((x['credit'] for x in
total_current_lines) )
localcontext['total_end_debit'] = sum((x['debit'] for x in
total_end_lines))
localcontext['total_end_credit'] = sum((x['credit'] for x in
total_end_lines))
#### End Add Totals
###################################################
In general_ledger.odt template add a table (table4) with 8 columns and 3
rows.Merge the first two columns
in all rows.Set right align for the entire table,set center align
Liberation Serif 12 and Bold for the first column
and add the follow in the first four columns:
Total Balance | <formatLang(total_start_debit,user.language)> |
<formatLang(total_start_credit,user.language)> |
<formatLang(total_start_debit-total_start_credit,user.language)>
Total Period | <formatLang(total_current_debit,user.language)> |
<formatLang(total_current_credit,user.language)> |
<formatLang(total_current_debit-total_current_credit,user.language)>
General Total | <formatLang(total_end_debit,user.language)> |
<formatLang(total_end_credit,user.language)> |
<formatLang(total_end_debit-total_end_credit,user.language)>
At the end of the report you 'll have the totals.