Skip to content

Commit

Permalink
[MIG] account_invoice_tax/: Migration to 16.0
Browse files Browse the repository at this point in the history
closes #144

Signed-off-by: Katherine Zaoral <kz@adhoc.com.ar>
  • Loading branch information
ica-adhoc committed Dec 13, 2022
1 parent 1759774 commit 4ea927e
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 17 deletions.
5 changes: 2 additions & 3 deletions account_invoice_tax/__manifest__.py
@@ -1,19 +1,18 @@
{
'name': 'Account Invoice Tax',
'version': "15.0.1.0.0",
'version': "16.0.1.0.0",
'author': 'ADHOC SA',
'category': 'Localization',
'depends': [
'account',
'account_ux', # for _recompute_tax_lines patch
],
'data': [
'wizards/account_invoice_tax_view.xml',
'views/account_move_view.xml',
'security/ir.model.access.csv',
],
'license': 'AGPL-3',
'installable': False,
'installable': True,
'auto_install': False,
'application': False,
}
2 changes: 1 addition & 1 deletion account_invoice_tax/views/account_move_view.xml
Expand Up @@ -6,7 +6,7 @@
<field name="model">account.move</field>
<field name="inherit_id" ref="account.view_move_form"/>
<field name="arch" type="xml">
<field name="tax_totals_json" position="after">
<field name="tax_totals" position="after">
<div colspan="2" class="oe_right oe_edit_only" attrs="{'invisible': ['|', ('state', '!=', 'draft'), ('move_type', 'not in', ('in_invoice', 'in_refund', 'in_receipt'))]}">
<button name="%(account_invoice_tax.action_view_account_invoice_tax)d" type="action" string="Add" title="Add Tax" class="oe_link" context="{'move_type': move_type, 'type_operation': 'add'}"/>
<button name="%(account_invoice_tax.action_view_account_invoice_tax)d" type="action" string="Remove" title="Remove Tax" class="oe_link" context="{'move_type': move_type, 'type_operation': 'remove'}"/>
Expand Down
40 changes: 27 additions & 13 deletions account_invoice_tax/wizards/account_invoice_tax.py
@@ -1,6 +1,5 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import fields, models, api, _

from odoo import fields, models, api, _, Command

class AccountInvoiceTax(models.TransientModel):

Expand Down Expand Up @@ -65,21 +64,36 @@ def add_tax_and_new(self):
def add_tax(self):
""" Add the given taxes to all the invoice line of the current invoice """
move_id = self.move_id.with_context(check_move_validity=False)
move_id.invoice_line_ids.write({'tax_ids': [(4, self.tax_id.id)]})
# pasar "recompute_all_taxes=True" seria lo mismo que marcar una linea con recompute_tax_line
# IMPORTANTE para que esto funcione sin que se recompute todo es necesaria la modificacion que hicimos
# en account_ux en _recompute_tax_lines
move_id._recompute_dynamic_lines(recompute_all_taxes=True)

fixed_taxes_bu = {
line: {
'amount_currency': line.amount_currency,
'debit': line.debit,
'credit': line.credit,
} for line in move_id.line_ids.filtered(lambda x: x.tax_repartition_line_id.tax_id.amount_type == 'fixed')}
container = {'records': move_id, 'self': move_id}
with move_id._check_balanced(container):
with move_id._sync_dynamic_lines(container):
move_id.invoice_line_ids.write({'tax_ids': [Command.link(self.tax_id.id)]})
# set amount in the new created tax line
line_with_tax = move_id.line_ids.filtered(lambda x: x.tax_line_id == self.tax_id)
line_with_tax.write(self._get_amount_updated_values())
move_id._onchange_invoice_line_ids()
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))

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)
line_with_tax = move_id.line_ids.filtered(lambda x: x.tax_line_id == self.tax_id)
move_id.line_ids -= line_with_tax
move_id.invoice_line_ids.write({'tax_ids': [(3, self.tax_id.id)]})
move_id._onchange_invoice_line_ids()
fixed_taxes_bu = {
line: {
'amount_currency': line.amount_currency,
'debit': line.debit,
'credit': line.credit,
} for line in move_id.line_ids.filtered(lambda x: x.tax_repartition_line_id.tax_id.amount_type == 'fixed')}
container = {'records': move_id, 'self': move_id}
with move_id._check_balanced(container):
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))

0 comments on commit 4ea927e

Please sign in to comment.