Skip to content

Commit

Permalink
[FIX] account_invoice_tax: add/remove tax wizard
Browse files Browse the repository at this point in the history
Now taxes that added/removed with wizard calculate correctly
  • Loading branch information
ica-adhoc committed May 13, 2023
1 parent 5a0b58f commit d2150c4
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions account_invoice_tax/wizards/account_invoice_tax.py
Expand Up @@ -66,16 +66,16 @@ def add_tax(self):

move = self.move_id
fixed_taxes_bu = {
line: {
line.tax_line_id: {
'amount_currency': line.amount_currency,
'debit': line.debit,
'credit': line.credit,
} for line in move.line_ids.filtered(lambda x: x.tax_repartition_line_id.tax_id.amount_type == 'fixed')}

# al crear la linea de impuesto no queda balanceado porque no recalcula las lineas AP/AR
# por eso pasamos check_move_validity
container = {'records': move.with_context(check_move_validity=False)}
with move._check_balanced(container):
container = {'records': move}
with move.with_context(check_move_validity=False)._check_balanced(container):
with move._sync_dynamic_lines(container):
move.invoice_line_ids.write({'tax_ids': [Command.link(self.tax_id.id)]})

Expand All @@ -84,14 +84,10 @@ def add_tax(self):
with move._check_balanced(container):
with move._sync_dynamic_lines(container):
# restauramos todos los valores de impuestos fixed que se habrian recomputado
commands = []
#restaured = []
for tax_line in move.line_ids.filtered(
lambda x: x.tax_repartition_line_id.tax_id.amount_type == 'fixed' and x in fixed_taxes_bu):
# ahora estamos mandando todo el write de una con el commands pero por si falla algo y queremos
# volver a probar, antes usabamos esta linea
# tax_line.write(fixed_taxes_bu.get(tax_line))
commands.append(Command.update(tax_line.id, fixed_taxes_bu.get(tax_line)))
move.write({'line_ids': commands})
lambda x: x.tax_repartition_line_id.tax_id in fixed_taxes_bu and x.tax_repartition_line_id.tax_id.amount_type == 'fixed'):
tax_line.write(fixed_taxes_bu.get(tax_line.tax_line_id))

# seteamos valor al impuesto segun lo que puso en el wizard
line_with_tax = move.line_ids.filtered(lambda x: x.tax_line_id == self.tax_id)
Expand All @@ -101,7 +97,7 @@ def remove_tax(self):
""" Remove the given taxes to all the invoice line of the current invoice """
move_id = self.move_id.with_context(check_move_validity=False)
fixed_taxes_bu = {
line: {
line.tax_line_id: {
'amount_currency': line.amount_currency,
'debit': line.debit,
'credit': line.credit,
Expand All @@ -111,5 +107,5 @@ def remove_tax(self):
with move_id._sync_dynamic_lines(container):
move_id.invoice_line_ids.write({'tax_ids': [Command.unlink(self.tax_id.id)]})
for tax_line in move_id.line_ids.filtered(
lambda x: x.tax_repartition_line_id.tax_id.amount_type == 'fixed' and x in fixed_taxes_bu):
tax_line.write(fixed_taxes_bu.get(tax_line))
lambda x: x.tax_repartition_line_id.tax_id in fixed_taxes_bu and x.tax_repartition_line_id.tax_id.amount_type == 'fixed'):
tax_line.write(fixed_taxes_bu.get(tax_line.tax_line_id))

0 comments on commit d2150c4

Please sign in to comment.