Skip to content

Commit

Permalink
[IMP] now after modifying a fixed tax through the wizard, it keeps th…
Browse files Browse the repository at this point in the history
…e total amount of the tax groups even if we change the information of the invoice lines.
  • Loading branch information
maq-adhoc authored and jjscarafia committed Sep 15, 2023
1 parent 2cea11b commit 01ad82e
Show file tree
Hide file tree
Showing 8 changed files with 101 additions and 3 deletions.
1 change: 1 addition & 0 deletions account_invoice_tax/__init__.py
@@ -1,2 +1,3 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from . import wizards
from . import models
5 changes: 5 additions & 0 deletions account_invoice_tax/__manifest__.py
Expand Up @@ -11,6 +11,11 @@
'views/account_move_view.xml',
'security/ir.model.access.csv',
],
'assets': {
'web.assets_backend': [
'account_invoice_tax/static/src/xml/**/*',
],
},
'license': 'AGPL-3',
'installable': True,
'auto_install': False,
Expand Down
2 changes: 2 additions & 0 deletions account_invoice_tax/models/__init__.py
@@ -0,0 +1,2 @@
from . import account_move
from . import account_tax
21 changes: 21 additions & 0 deletions account_invoice_tax/models/account_move.py
@@ -0,0 +1,21 @@
##############################################################################
# For copyright and license notices, see __manifest__.py file in module root
# directory
##############################################################################
from odoo import models, fields, api
import logging

_logger = logging.getLogger(__name__)


class AccountMove(models.Model):

_inherit = "account.move"


def _compute_tax_totals(self):
""" Computed field used for custom widget's rendering.
Only set on invoices.
"""
for move in self:
super(AccountMove, move.with_context(tax_total_origin=move._origin.tax_totals))._compute_tax_totals()
47 changes: 47 additions & 0 deletions account_invoice_tax/models/account_tax.py
@@ -0,0 +1,47 @@
##############################################################################
# For copyright and license notices, see __manifest__.py file in module root
# directory
##############################################################################
from odoo import models, fields, api
from odoo.tools.misc import formatLang

import logging

_logger = logging.getLogger(__name__)


class AccountTax(models.Model):

_inherit = "account.tax"


@api.model
def _prepare_tax_totals(self, base_lines, currency, tax_lines=None):
totals = super()._prepare_tax_totals(base_lines, currency, tax_lines)
##recorrer totals y si comple on la condicion y esta en self.env._context.get('tax_total_origin')
tax_total_origin = self.env.context.get('tax_total_origin')
if tax_total_origin:
for subtotals_order in totals['subtotals_order']:
for subtotals_index in range(0,len(totals['groups_by_subtotal'][subtotals_order])):
id_fixed = all([x.amount_type == 'fixed' and x.type_tax_use == 'purchase' for x in self.env['account.tax'].search([('tax_group_id' ,'=', totals['groups_by_subtotal'][subtotals_order][subtotals_index]['tax_group_id'])])])
exist = [x for x in tax_total_origin['groups_by_subtotal'][subtotals_order] if x['tax_group_id'] == totals['groups_by_subtotal'][subtotals_order][subtotals_index]['tax_group_id']]

if id_fixed and exist:
totals['groups_by_subtotal'][subtotals_order][subtotals_index] = exist[0]


subtotals = []
amount_tax = 0
for subtotal_title in totals['subtotals_order']:
amount_total = totals['amount_untaxed'] + amount_tax
subtotals.append({
'name': subtotal_title,
'amount': amount_total,
'formatted_amount': formatLang(self.env, amount_total, currency_obj=currency),
})
amount_tax += sum(x['tax_group_amount'] for x in totals['groups_by_subtotal'][subtotal_title])

amount_total = totals['amount_untaxed'] + amount_tax

totals['amount_tax'] = amount_tax
return totals
13 changes: 13 additions & 0 deletions account_invoice_tax/static/src/xml/tax_totals.xml
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<templates>

<t t-name="account.TaxGroupComponent" t-inherit="account.TaxGroupComponent" t-inherit-mode="extension" owl="1">
<xpath expr="//span[hasclass('o_tax_group_edit')]" position="replace">
<span class="o_tax_group_edit">
<span class="o_tax_group_amount_value">
<t t-out="props.taxGroup.formatted_tax_group_amount"/>
</span>
</span>
</xpath>
</t>
</templates>
2 changes: 1 addition & 1 deletion account_invoice_tax/views/account_move_view.xml
Expand Up @@ -8,7 +8,7 @@
<field name="arch" type="xml">
<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="Add/update" title="Add/update 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'}"/>
</div>
</field>
Expand Down
13 changes: 11 additions & 2 deletions account_invoice_tax/wizards/account_invoice_tax.py
Expand Up @@ -24,7 +24,16 @@ def default_get(self, fields):
def onchange_move_id(self):
taxes = self.env['account.tax'].search([]) if self.type_operation == 'add' else self.move_id.mapped(
'invoice_line_ids.tax_ids')
return {'domain': {'tax_id': [('id', 'in', taxes.ids), ('company_id', '=', self.move_id.company_id.id)]}}
leaf = [('id', 'in', taxes.ids), ('type_tax_use', '=', 'purchase') ,('company_id', '=', self.move_id.company_id.id)]
if self.env.context.get('group_id'):
leaf += [('tax_group_id', '=', self.env.context.get('group_id'))]
return {'domain': {'tax_id': leaf}}

@api.onchange('tax_id')
def onchange_tax_id(self):
tax_line = self.move_id.line_ids.filtered(lambda x: x.tax_line_id and x.tax_line_id.id == self.tax_id.id)
if tax_line:
self.amount = tax_line.balance

def _get_amount_updated_values(self):
debit = credit = 0
Expand Down Expand Up @@ -71,7 +80,6 @@ def add_tax(self):
'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}
Expand Down Expand Up @@ -109,3 +117,4 @@ def remove_tax(self):
for tax_line in move_id.line_ids.filtered(
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 01ad82e

Please sign in to comment.