[FIX] point_of_sale: flattening only group of taxes when creating amls

Revision 89c63096cb fixed the creation
of the taxes applied to account move lines when validating a pos session

The fix though overlooked two things:
- protection against recursivity
(nothing prevents a group of taxes to have a grand-parent as one of its children)
- the fact that when converting a group of taxes into a regular computed one,
the field children_ids is never reset

Those two caveats provoked a "max recursivity error" in python within the right conditions

This commit protects the recursive process from the two issues, and there is no traceback

OPW 816163
This commit is contained in:
Lucas Perais (lpe)
2018-02-15 11:21:21 +01:00
parent 73c2ac451a
commit c1276c154e
+7 -3
View File
@@ -197,10 +197,14 @@ class PosOrder(models.Model):
return InvoiceLine.sudo().create(inv_line)
def _create_account_move_line(self, session=None, move=None):
def _flatten_tax_and_children(taxes):
def _flatten_tax_and_children(taxes, group_done=None):
children = self.env['account.tax']
for tax in taxes:
children |= _flatten_tax_and_children(tax.children_tax_ids)
if group_done is None:
group_done = set()
for tax in taxes.filtered(lambda t: t.amount_type == 'group'):
if tax.id not in group_done:
group_done.add(tax.id)
children |= _flatten_tax_and_children(tax.children_tax_ids, group_done)
return taxes + children
# Tricky, via the workflow, we only have one id in the ids variable