General Ledger: Control if there are some party moves with initial value, but

not values in the current period control moves and must be to set.

Task: #160208
This commit is contained in:
Bernat Brunet 2023-07-11 15:04:03 +02:00
parent 2d881178fc
commit 6a7842e4a9
3 changed files with 95 additions and 23 deletions

View File

@ -51,7 +51,7 @@ class Account(metaclass=PoolMeta):
cls.general_ledger_balance.states['invisible'] = True
@classmethod
def html_read_account_vals(cls, accounts, with_moves=False,
def html_read_account_vals(cls, accounts, company, with_moves=False,
exclude_party_moves=False, final_accounts=False):
pool = Pool()
Account = pool.get('account.account')
@ -69,7 +69,7 @@ class Account(metaclass=PoolMeta):
move_join = 'INNER' if with_moves else 'LEFT'
if not accounts:
domain = [
('company', '=', transaction.context.get('company')),
('company', '=', company),
]
if final_accounts:
domain.append(('childs', '=', None))
@ -91,6 +91,8 @@ class Account(metaclass=PoolMeta):
date = transaction.context.get('date')
if date:
where &= (move.date <= date)
where &= (move.date <= date)
where &= (move.company == company.id)
if exclude_party_moves:
# This "where" not use account kind (before a change use it)
# because there are some companies that the accounts kind and

View File

@ -329,8 +329,7 @@ class GeneralLedgerReport(HTMLReport):
where += "aa.parent is not null "
if start_date:
if company:
where += "and am.company = %s " % company.id
where += "and am.company = %s " % company.id
where += "and am.date >= '%s' " % start_date
where += "and am.date <= '%s' " % end_date
else:
@ -377,11 +376,13 @@ class GeneralLedgerReport(HTMLReport):
with Transaction().set_context(date=initial_balance_date):
init_values = {}
if not parties:
init_values = Account.html_read_account_vals(accounts,
init_values = Account.html_read_account_vals(accounts, company,
with_moves=False, exclude_party_moves=True,
final_accounts=data.get('final_accounts', False))
init_party_values = Party.html_get_account_values_by_party(
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()
@ -469,6 +470,52 @@ class GeneralLedgerReport(HTMLReport):
'total_credit': credit,
}
# Control if there are some party moves with initial value, but not
# values in the current period control moves and must be to set.
missing_init_parties = list(
set(init_parties) - set(parties_general_ledger))
if missing_init_parties:
account_ids = [k for k, _ in init_party_values.items()]
accounts = dict((a.id, a) for a in Account.browse(account_ids))
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:
continue
party = Party(p)
currentKey = (account, party)
credit = z.get('credit', Decimal(0))
debit = z.get('debit', Decimal(0))
balance = z.get('balance', Decimal(0))
if balance == Decimal(0):
continue
sequence += 1
rline = {
'sequence': sequence,
'line': None,
'ref': None,
'credit': credit,
'debit': debit,
'balance': balance,
'party': party
}
key = _get_key_id(currentKey)
if records.get(key):
records[key]['lines'].append(rline)
records[key]['total_debit'] += debit
records[key]['total_credit'] += credit
else:
records[key] = {
'account': account.name,
'code': account.code or str(account.id),
'party': party.name if party else None,
'party_required': account.party_required,
'lines': [rline],
'previous_balance': (balance + credit - debit),
'total_debit': debit,
'total_credit': credit,
}
if data.get('all_accounts', True):
init_values_account_wo_moves = {
k: init_values[k] for k in init_values

View File

@ -2,20 +2,32 @@
{% 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 %}{{ _('Previous balance...') }}{% endif %}</td>
<td style="text-align: right;"> {{ previous_balance|render }}</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 %}
<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>
{% 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>
@ -32,14 +44,25 @@
{% endfor %}
{% elif record.lines %}
{% for l in record.lines %}
<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 show_description and l.line and (l.line.description or l.line.move_description) %} // {% endif %}{% if show_description and l.line and l.line.description %} {{ l.line.description }} {% elif show_description and l.line and l.line.move_description %} {{ l.line.move_description }} {% endif %}</td>
<td style="text-align: right;" class="no-wrap">{{ l.debit|render }}</td>
<td style="text-align: right;" class="no-wrap">{{ l.credit|render }}</td>
<td style="text-align: right;" class="no-wrap">{{ l.balance|render }}</td>
</tr>
{% 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 show_description and l.line and (l.line.description or l.line.move_description) %} // {% endif %}{% if show_description and l.line and l.line.description %} {{ l.line.description }} {% elif show_description and l.line and l.line.move_description %} {{ l.line.move_description }} {% endif %}</td>
<td style="text-align: right;" class="no-wrap">{{ l.debit|render }}</td>
<td style="text-align: right;" class="no-wrap">{{ l.credit|render }}</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 }}</td>
<td style="text-align: right;" class="no-wrap">{{ l.credit|render }}</td>
<td style="text-align: right;" class="no-wrap">{{ l.balance|render }}</td>
</tr>
{% endif %}
{% endfor %}
{% else %}
<tr>