[FIX] account: Reload chart_template button unexpected unlink

Reload button appeared when no chart_template was set which
could make Odoo delete important data if clicked.
We restrict appearance of the reload button to avoid this situation.
Also adds a short description on the button to notify user of the
irreversability of the action.

Steps to reproduce:
1. Create a company (do not use the default one that has Generic CoA set) with a country set.
2. Create accounts : income, receivable and payable.
3. Create a sale journal with the income account.
4. Go to a partner detail (e.g. Deco addict), tab Accounting and set its receivable/payable accounts to the ones created above.
5. Create an invoice for that partner.
6. Go in Accounting Settings and click the reload button.
=> The invoice is deleted.

Task-3488427
OPW-3448881

closes odoo/odoo#134028

X-original-commit: a636b9386f297f9f08a38689911ca111fe597ec3
Signed-off-by: William André (wan) <wan@odoo.com>
Signed-off-by: Claire Bretton (clbr) <clbr@odoo.com>
This commit is contained in:
Claire Bretton (clbr)
2023-09-04 08:03:43 +00:00
parent 68909e389e
commit 05978d603b
2 changed files with 4 additions and 2 deletions
+1 -1
View File
@@ -172,7 +172,7 @@ class AccountChartTemplate(models.AbstractModel):
reload_template = template_code == company.chart_template
company.chart_template = template_code
if not reload_template:
if not reload_template and (not company._existing_accounting() or self.env.ref('base.module_account').demo):
for model in ('account.move',) + TEMPLATE_MODELS[::-1]:
if not company.parent_id:
self.env[model].sudo().search([('company_id', 'child_of', company.id)]).with_context({MODULE_UNINSTALL_FLAG: True}).unlink()
@@ -33,7 +33,9 @@
<field name="chart_template" readonly="has_accounting_entries" required="chart_template"/>
</div>
<div class="mt16">
<button name="reload_template" type="object" string="Reload" class="btn-secondary ps-2 w-100" icon="fa-refresh" invisible="not has_accounting_entries"/>
<button name="reload_template" type="object" string="Reload" class="btn-secondary ps-2 w-100" icon="fa-refresh"
title="Reload accounting data (taxes, accounts, ...) if you notice inconsistencies. This action is irreversible."
invisible="not has_accounting_entries or not chart_template"/>
</div>
</div>
</div>