* Change the way that the General Ledger is calcaulated.
Now grou by account and aprty and always print all necesary lines even
the party is not required and is set or not set and is required. In this
cases set the header in red to control the bad moves.

Task: #162395

* Update translations.

Task: #162395

* Fix and make some improvements.

Tasks: #162395

---------

Co-authored-by: Bernat Brunet <bernat@nan-tic.com>
This commit is contained in:
nan-tic-dev 2023-10-16 22:19:16 +02:00 committed by Bernat Brunet
parent fa94dafbe3
commit 4aa59755a2
7 changed files with 41 additions and 114 deletions

View File

@ -68,13 +68,13 @@ class Account(metaclass=PoolMeta):
cursor = transaction.connection.cursor()
move_join = 'INNER' if with_moves else 'LEFT'
if not accounts:
domain = [
accounts = Account.search([
('company', '=', company),
]
if final_accounts:
domain.append(('childs', '=', None))
accounts = Account.search(domain)
account_ids = [a.id for a in accounts]
])
if final_accounts:
account_ids = [a.id for a in accounts if not a.childs]
else:
account_ids = [a.id for a in accounts]
group_by = (table_a.id,)
columns = (group_by + (Sum(Coalesce(line.debit, 0)).as_('debit'),
Sum(Coalesce(line.credit, 0)).as_('credit'),

View File

@ -245,22 +245,9 @@ class GeneralLedgerReport(HTMLReport):
BankLine = None
def _get_key(currentKey):
account_code = currentKey[0].code or currentKey[0].name
if len(currentKey) > 1:
if currentKey[1]:
key = '%s %s' % (account_code, currentKey[1].name)
else:
key = account_code
else:
if currentKey[0].code:
key = '%s %s' % (account_code, currentKey[0].name)
else:
key = currentKey[0].name
return key
def _get_key_id(currentKey):
key = currentKey[0].id
return key
party = (currentKey[1].name if len(currentKey) > 1
and currentKey[1] else 'None')
return (currentKey[0].code, party)
fiscalyear = (FiscalYear(data['fiscalyear']) if data.get('fiscalyear')
else None)
@ -383,32 +370,26 @@ class GeneralLedgerReport(HTMLReport):
parties, accounts, company)
init_parties = set([p for a, av in init_party_values.items()
for p, pv in av.items()])
records = {}
parties_general_ledger = set()
lastKey = None
sequence = 0
accounts_w_moves = []
# Add the asked period/date lines in records
for group_lines in grouped_slice(line_ids):
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
or line.account.party_required) and line.party):
currentKey = (line.account, line.party)
else:
currentKey = (line.account,)
currentKey = (line.account, line.party)
if lastKey != currentKey:
lastKey = currentKey
account_id = currentKey[0].id
if len(currentKey) > 1:
party_id = currentKey[1].id if currentKey[1] else None
parties_general_ledger.add(party_id)
balance = init_party_values.get(account_id,
{}).get(party_id, {}).get('balance', Decimal(0))
else:
balance = init_values.get(account_id, {}).get(
'balance', Decimal(0))
party_id = (currentKey[1].id if len(currentKey) > 1
and currentKey[1] else None)
parties_general_ledger.add(party_id)
balance = init_party_values.get(account_id,
{}).get(party_id, {}).get('balance', Decimal(0))
credit = line.credit
debit = line.debit
balance += line.debit - line.credit
@ -438,7 +419,7 @@ class GeneralLedgerReport(HTMLReport):
else:
ref = cls._ref_origin(line)
# If we dont fill the party in a party_required account, try
# If we don't fill the party in a party_required account, try
# get the party field in the line
if line.account.party_required and not party:
party = line.party
@ -453,7 +434,7 @@ class GeneralLedgerReport(HTMLReport):
'party': party
}
key = _get_key_id(currentKey)
key = _get_key(currentKey)
if records.get(key):
records[key]['lines'].append(rline)
records[key]['total_debit'] += debit
@ -480,9 +461,9 @@ class GeneralLedgerReport(HTMLReport):
for k, v in init_party_values.items():
account = accounts[k]
for p, z in v.items():
if not p or p not in missing_init_parties:
if p not in missing_init_parties:
continue
party = Party(p)
party = Party(p) if p else None
currentKey = (account, party)
credit = z.get('credit', Decimal(0))
debit = z.get('debit', Decimal(0))
@ -499,7 +480,7 @@ class GeneralLedgerReport(HTMLReport):
'balance': balance,
'party': party
}
key = _get_key_id(currentKey)
key = _get_key(currentKey)
if records.get(key):
records[key]['lines'].append(rline)
records[key]['total_debit'] += debit
@ -528,7 +509,8 @@ class GeneralLedgerReport(HTMLReport):
if balance == 0:
continue
key = account.id
currentKey = (account,)
key = _get_key(currentKey)
if records.get(key):
records[key]['total_debit'] += debit
records[key]['total_credit'] += credit
@ -536,6 +518,7 @@ class GeneralLedgerReport(HTMLReport):
records[key] = {
'account': account.name,
'code': account.code or str(account.id),
'party': None,
'party_required': account.party_required,
'lines': [],
'previous_balance': (balance + credit - debit),
@ -555,10 +538,7 @@ class GeneralLedgerReport(HTMLReport):
if p in parties_general_ledger:
continue
party = parties[p]
if account.type.receivable or account.type.payable:
currentKey = (account, party)
else:
currentKey = (account,)
currentKey = (account, party)
sequence += 1
credit = z.get('credit', Decimal(0))
debit = z.get('debit', Decimal(0))
@ -573,21 +553,14 @@ class GeneralLedgerReport(HTMLReport):
'account': account.name,
'code': account.code or str(account.id),
'lines': [],
'party': party.name if party else None,
'party_required': account.party_required,
'previous_balance': (balance + credit - debit),
'total_debit': debit,
'total_credit': credit,
}
accounts = {}
for record in records.keys():
accounts[records[record]['code']
+ ' ' + records[record]['account']] = record
sorted_records = {}
for account in dict(sorted(accounts.items())).values():
sorted_records[account] = records[account]
return sorted_records, parameters
return dict(sorted(records.items())), parameters
@classmethod
def execute(cls, ids, data):

View File

@ -1,49 +1,5 @@
{% set show_description = data['parameters']['show_description'] %}
{% if record.lines and record.party_required %}
{% for party, lines in record.lines|groupby('party') %}
{% set ns = namespace(total_debit=0, total_credit=0) %}
{% set previous_balance = lines[0].balance + lines[0].credit - lines[0].debit %}
{% set line_in_lines = True if lines[0].line else False %}
<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 and line_in_lines %}{{ _('Previous balance...') }}{% endif %}</td>
<td style="text-align: right;">{% if record.lines and line_in_lines %} {{ previous_balance|render }}{% endif %}</td>
</tr>{% for l in lines %}
{% if l.line %}
<tr>
<td>{{ l.line.date and l.line.date|render }}</td>
<td>{% if l.line.move.post_number %}{{ l.line.move.post_number }}{% else %}{{ l.line.move.move_number }}{{ l.line.party and l.line.party.name }}{% endif %}</td>
<td>{% if l.ref %}{{ l.ref }}{% endif %}{% if l.ref and l.line and (l.line.description or l.line.move_description) %} // {% endif %}{% if l.line and l.line.description %} {{ l.line.description }} {% elif l.line and l.line.move_description %} {{ l.line.move_description }} {% endif %}</td>
<td style="text-align: right;" class="no-wrap">{{ l.debit|render }} {% set ns.total_debit = ns.total_debit + l.debit %}</td>
<td style="text-align: right;" class="no-wrap">{{ l.credit|render }} {% set ns.total_credit = ns.total_credit + l.credit %}</td>
<td style="text-align: right;" class="no-wrap">{{ l.balance|render }}</td>
</tr>
{% else %}
<tr>
<td></td>
<td>-</td>
<td>{{ _('Previous balance') }}</td>
<td style="text-align: right;" class="no-wrap">{{ l.debit|render }} {% set ns.total_debit = ns.total_debit + l.debit %}</td>
<td style="text-align: right;" class="no-wrap">{{ l.credit|render }} {% set ns.total_credit = ns.total_credit + l.credit %}</td>
<td style="text-align: right;" class="no-wrap">{{ l.balance|render }}</td>
</tr>
{% endif %}
{% endfor %}
<tr class="bold">
<td colspan="3" class="right">{{ _('Total Fiscal Year') }}</td>
<td style="text-align: right;" class="no-wrap">{{ ns.total_debit|render }}</td>
<td style="text-align: right;" class="no-wrap">{{ ns.total_credit|render }}</td>
<td style="text-align: right;" class="no-wrap">{{ (ns.total_debit - ns.total_credit)|render }}</td>
</tr>
<tr class="bold bottom">
<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;">{{ (previous_balance + ns.total_debit - ns.total_credit)|render }}</td>
</tr>
{% endfor %}
{% elif record.lines %}
{% if record.lines %}
{% for l in record.lines %}
{% if l.line %}
<tr>

View File

@ -8,14 +8,12 @@
<th style="text-align: right;">{{ _('Balance') }}</th>
</tr>
{% for k, record in records.items() %}
{% if not record.party_required %}
<tr>
<td colspan="2" class="bold">{{ record.code }}</td>
<td class="bold">{{ record.account }}</td>
<td colspan="2" style="text-align: right;">{% if record.lines %}{{ _('Previous balance...') }}{% endif %}</td>
<td style="text-align: right;">{% if record.lines %}{{ record.previous_balance|render }}{% endif %}</td>
</tr>
{% endif %}
<tr>
<td colspan="2" class="bold">{{ record.code }}</td>
<td class="bold">{% if record.party %}{{ record.party }}{% else %}{{ record.account }}{% endif %}</td>
<td colspan="2" style="text-align: right;">{% if record.lines %}{{ _('Previous balance...') }}{% endif %}</td>
<td style="text-align: right;">{% if record.lines %}{{ record.previous_balance|render }}{% endif %}</td>
</tr>
{{ show_detail_lines(record) }}
@ -28,7 +26,7 @@
<tr class="bold bottom">
<td colspan="2" class="bold">{{ record.code }}</td>
<td class="bold">{{ record.account }}</td>
<td class="bold">{% if record.party %}{{ record.party }}{% else %}{{ record.account }}{% endif %}</td>
<td colspan="2" class="left">{{ _('Total') }}</td>
<td style="text-align: right;" class="no-wrap">{{ (record.previous_balance + record.total_debit - record.total_credit)|render }}</td>
</tr>

View File

@ -51,7 +51,7 @@ header {
</tr>
<tr>
<td>
<p>{{ _("When the Move number is between '()' means it hasn't Post Number and the shown number is the provisional one.") }}</p>
<p>{{ _("When move number is between parentheses it means that it has no post number and the number shown is the provisional one.") }}<br/>
</td>
</tr>
</tbody>

View File

@ -279,8 +279,8 @@ msgstr "NIF"
msgctxt "report:account_reports.general_ledger:"
msgid ""
"When the Move number is between '()' means it hasn't Post Number and the "
"shown number is the provisional one."
"When move number is between parentheses it means that it has no post number "
"and the number shown is the provisional one."
msgstr ""
"Si el número d'assentament apareix entre parèntesis indica que no té número "
"confirmat i el número que es mostra és el provisional."

View File

@ -279,8 +279,8 @@ msgstr "NIF"
msgctxt "report:account_reports.general_ledger:"
msgid ""
"When the Move number is between '()' means it hasn't Post Number and the "
"shown number is the provisional one."
"When move number is between parentheses it means that it has no post number "
"and the number shown is the provisional one."
msgstr ""
"Si el número de asiento aparece entre paréntesis indica que no tiene número "
"confirmado y el número que se muestra es el provisional."