|
| 1 | +from odoo import models, fields, api |
| 2 | + |
| 3 | +class AccountTax(models.Model): |
| 4 | + |
| 5 | + _inherit = "account.tax" |
| 6 | + |
| 7 | + @api.model |
| 8 | + def _get_tax_totals_summary(self, base_lines, currency, company, cash_rounding=None): |
| 9 | + res = super()._get_tax_totals_summary(base_lines, currency, company, cash_rounding=cash_rounding) |
| 10 | + if 'tax_context' in self.env.context: |
| 11 | + rate = self.env.context.get('inverse_invoice_currency_rate', 1) |
| 12 | + for tax_groups in res['subtotals'][0]['tax_groups']: |
| 13 | + for involved_tax_id in tax_groups['involved_tax_ids']: |
| 14 | + amount = self.env.context['tax_context'].get(involved_tax_id) |
| 15 | + original_amount = tax_groups.get('tax_amount', 0.0) |
| 16 | + if amount and amount != original_amount: |
| 17 | + tax_groups.update({ |
| 18 | + 'tax_amount': amount, |
| 19 | + 'tax_amount_currency': amount |
| 20 | + }) |
| 21 | + res['tax_amount'] += amount - original_amount |
| 22 | + res['total_amount'] += amount - original_amount |
| 23 | + res['tax_amount_currency'] += (amount - original_amount) * rate |
| 24 | + res['total_amount_currency'] += (amount - original_amount) * rate |
| 25 | + |
| 26 | + return res |
| 27 | + |
| 28 | + |
| 29 | +""" |
| 30 | +{'base_amount': 25476.980000000003, |
| 31 | + 'base_amount_currency': 25476.980000000003, |
| 32 | + 'company_currency_id': 19, |
| 33 | + 'company_currency_pd': 0.01, |
| 34 | + 'currency_id': 19, |
| 35 | + 'currency_pd': 0.01, |
| 36 | + 'has_tax_groups': True, |
| 37 | + 'same_tax_base': True, |
| 38 | + 'subtotals': [{'base_amount': 25476.980000000003, |
| 39 | + 'base_amount_currency': 25476.980000000003, |
| 40 | + 'name': 'Untaxed Amount', |
| 41 | + 'tax_amount': 5356.169999999999, |
| 42 | + 'tax_amount_currency': 5356.169999999999, |
| 43 | + 'tax_groups': [{'base_amount': 25476.980000000003, |
| 44 | + 'base_amount_currency': 25476.980000000003, |
| 45 | + 'display_base_amount': 25476.980000000003, |
| 46 | + 'display_base_amount_currency': 25476.980000000003, |
| 47 | + 'group_label': False, |
| 48 | + 'group_name': 'VAT 21%', |
| 49 | + 'id': 84, |
| 50 | + 'involved_tax_ids': [140], |
| 51 | + 'tax_amount': 5350.169999999999, |
| 52 | + 'tax_amount_currency': 5350.169999999999}, |
| 53 | + {'base_amount': 25476.980000000003, |
| 54 | + 'base_amount_currency': 25476.980000000003, |
| 55 | + 'display_base_amount': None, |
| 56 | + 'display_base_amount_currency': None, |
| 57 | + 'group_label': False, |
| 58 | + 'group_name': 'Perc IIBB ARBA', |
| 59 | + 'id': 98, |
| 60 | + 'involved_tax_ids': [79], |
| 61 | + 'tax_amount': 6.0, |
| 62 | + 'tax_amount_currency': 6.0}]}], |
| 63 | + 'tax_amount': 5356.169999999999, |
| 64 | + 'tax_amount_currency': 5356.169999999999, |
| 65 | + 'total_amount': 30833.15, |
| 66 | + 'total_amount_currency': 30833.15} |
| 67 | +
|
| 68 | +""" |
| 69 | +class AccountMove(models.Model): |
| 70 | + |
| 71 | + _inherit = "account.move" |
| 72 | + |
| 73 | + def _compute_tax_totals(self): |
| 74 | + for move in self: |
| 75 | + tax_context = {'inverse_invoice_currency_rate': move.inverse_invoice_currency_rate} |
| 76 | + for line in move.line_ids.filtered(lambda x: x.fixed_amount_in_currency): |
| 77 | + tax_context[line.tax_line_id.id] = line.fixed_amount_in_currency |
| 78 | + super(AccountMove, move.with_context(tax_context=tax_context))._compute_tax_totals() |
0 commit comments