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 committed Sep 21, 2023
1 parent 01ad82e commit d50219c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 16 deletions.
11 changes: 7 additions & 4 deletions account_invoice_tax/models/account_move.py
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
9 changes: 4 additions & 5 deletions account_invoice_tax/wizards/account_invoice_tax.py
Original file line number Diff line number Diff line change
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,10 @@ 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:
currency_rate = self.move_id.line_ids.mapped('currency_rate')[0]
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)}
'debit': debit / currency_rate,
'credit': credit / currency_rate}

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

Expand Down

0 comments on commit d50219c

Please sign in to comment.