[FIX+IMP] account_chart_update: Add consistency method

With this, we prevent lock due to infinite loop if children taxes are matched, but
not the parent one and it's marked to be created.

Closes #912
This commit is contained in:
Pedro M. Baeza
2020-03-17 20:00:09 +01:00
parent a696148b4c
commit e2750be00b

View File

@@ -299,9 +299,36 @@ class WizardUpdateChartsAccounts(models.TransientModel):
self.state = 'ready'
return self._reopen()
def _check_consistency(self):
"""Method for assuring consistency in operations before performing
them. For now, implemented:
- If a parent tax is tried to be created, children taxes must be
also included to be created.
TODO:
- Check that needed accounts in taxes/FPs are created at the same time.
- Check that needed taxes in FPs are created at the same time.
"""
taxes2create = self.tax_ids.filtered(lambda x: x.type == 'new')
parents2create = taxes2create.filtered(
lambda x: x.tax_id.children_tax_ids)
for parent in parents2create:
if bool(
parent.tax_id.children_tax_ids - taxes2create.mapped('tax_id')
): # some children taxes are not included to be added
raise exceptions.UserError(_(
"You have at least one parent tax template (%s) whose "
"children taxes are not going to be created. Aborting "
"as this will provoke an infinite loop. Please check "
"if children have been matched, but not the parent one."
) % parent.tax_id.name)
@api.multi
def action_update_records(self):
"""Action that creates/updates/deletes the selected elements."""
self._check_consistency()
self = self.with_context(lang=self.lang)
self.rejected_new_account_number = 0
self.rejected_updated_account_number = 0