Skip to content

Commit

Permalink
[FIX] fix force multicurrency info
Browse files Browse the repository at this point in the history
[FIX] Only evaluate tax type in used taxes
  • Loading branch information
maq-adhoc authored and jjscarafia committed Sep 22, 2023
1 parent 01ad82e commit 3b6c23d
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 18 deletions.
11 changes: 7 additions & 4 deletions account_invoice_tax/models/account_move.py
Expand Up @@ -10,12 +10,15 @@

class AccountMove(models.Model):

_inherit = "account.move"
_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()
super(AccountMove, move.with_context(
tax_list_origin=move._origin.mapped('invoice_line_ids.tax_ids'),
tax_total_origin=move._origin.tax_totals)
)._compute_tax_totals()
18 changes: 11 additions & 7 deletions account_invoice_tax/models/account_tax.py
Expand Up @@ -12,22 +12,26 @@

class AccountTax(models.Model):

_inherit = "account.tax"
_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:
tax_list_origin = self.env.context.get('tax_list_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']]
id_fixed = tax_list_origin.filtered(lambda x: \
x.amount_type == 'fixed' and x.type_tax_use == 'purchase' \
and x.tax_group_id.id == totals['groups_by_subtotal'][subtotals_order][subtotals_index]['tax_group_id'])

existent_group = [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]
if id_fixed and existent_group:
totals['groups_by_subtotal'][subtotals_order][subtotals_index] = existent_group[0]


subtotals = []
Expand Down
4 changes: 3 additions & 1 deletion account_invoice_tax/views/account_move_view.xml
Expand Up @@ -7,8 +7,10 @@
<field name="inherit_id" ref="account.view_move_form"/>
<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/update" title="Add/update Tax" class="oe_link" context="{'move_type': move_type, 'type_operation': 'add'}"/>
<strong>TAX: </strong>
<button name="%(account_invoice_tax.action_view_account_invoice_tax)d" type="action" string="Add/update" title="Add/update fixed 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
8 changes: 2 additions & 6 deletions account_invoice_tax/wizards/account_invoice_tax.py
Expand Up @@ -33,7 +33,7 @@ def onchange_move_id(self):
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
self.amount = abs(tax_line.amount_currency)

def _get_amount_updated_values(self):
debit = credit = 0
Expand All @@ -52,11 +52,7 @@ def _get_amount_updated_values(self):
move_currency = self.move_id.currency_id
company_currency = self.move_id.company_currency_id
if move_currency and move_currency != company_currency:
return {'amount_currency': self.amount if debit else -self.amount,
'debit': move_currency._convert(
debit, company_currency, self.move_id.company_id, self.move_id.invoice_date),
'credit': move_currency._convert(
credit, company_currency, self.move_id.company_id, self.move_id.invoice_date)}
return {'amount_currency': self.amount if debit else -self.amount}

return {'debit': debit, 'credit': credit, 'balance': self.amount}

Expand Down

0 comments on commit 3b6c23d

Please sign in to comment.