[IMP] account: fix transaction demo data

The bank statement & transaction demo data has problems:
1. the statement doesn't have a name
2. the creation of the statement lines are postponed causing the opening/closing balances to be invalid (as the order of the statement lines is important)

This is due to the  _load_data method in account, which defers the creation of records to ensure that related records are created before they are referenced in relational fields.

This commit adds a condition to avoid deferring fields that have a list of ORM create commands, and fixes the statement name and balances.

closes odoo/odoo#120975

X-original-commit: 1d219de36944685153a77aeeb72920b06728383e
Signed-off-by: William André (wan) <wan@odoo.com>
Signed-off-by: Ayob Habib (ayh) <ayh@odoo.com>
This commit is contained in:
Habib (ayh)
2023-05-10 08:23:50 +02:00
parent e0e7e3b832
commit 6d420a3324
2 changed files with 21 additions and 14 deletions
+3 -8
View File
@@ -139,20 +139,15 @@ class AccountChartTemplate(models.AbstractModel):
)
return {
'demo_bank_statement_1': {
'journal_id': self.env['account.journal'].search([
('type', '=', 'bank'),
('company_id', '=', cid),
], limit=1).id,
'date': time.strftime('%Y')+'-01-01',
'balance_end_real': 9944.87,
'balance_start': 5103.0,
'name': f'{bnk_journal.name} - {time.strftime("%Y")}-01-01/1',
'balance_end_real': 6378.0,
'balance_start': 0.0,
'line_ids': [
Command.create({
'journal_id': bnk_journal.id,
'payment_ref': 'Initial balance',
'amount': 5103.0,
'date': time.strftime('%Y-01-01'),
'partner_id': 'base.res_partner_12',
}),
Command.create({
'journal_id': bnk_journal.id,
+18 -6
View File
@@ -393,15 +393,27 @@ class AccountChartTemplate(models.AbstractModel):
to_delay = defaultdict(dict)
for xml_id, vals in data.items():
to_be_removed = []
for field_name in vals:
for field_name, field_val in vals.items():
field = self.env[model]._fields.get(field_name, None)
if (field and
field.relational and
field.comodel_name not in created_models and
(field.comodel_name in dict(all_data) or field.comodel_name == model)
if (
field
and field.relational
and field_val
and ( # allow create commands but delay all other related fields
not isinstance(field_val, (list, tuple))
or (
isinstance(field_val[0], (list, tuple))
and {command for command, *dummy in field_val} != {Command.CREATE}
)
)
and field.comodel_name not in created_models
and (
field.comodel_name in dict(all_data)
or field.comodel_name == model
)
):
to_be_removed.append(field_name)
to_delay[xml_id][field_name] = vals.get(field_name)
to_delay[xml_id][field_name] = field_val
for field_name in to_be_removed:
del vals[field_name]
if any(to_delay.values()):