Bug invoice rate ICT

This commit is contained in:
2026-07-07 20:55:47 +02:00
parent 5c3464da5c
commit 3122255bc7

View File

@@ -565,6 +565,16 @@ class Invoice(Workflow, ModelSQL, ModelView, TaxableMixin, InvoiceReportMixin):
if rate:
return round(1/rate,6) or 1
def _compute_company_currency_amount(self, amount, date=None):
Currency = Pool().get('currency.currency')
if self.currency == self.company.currency:
return amount
if self.rate:
return self.company.currency.round(amount / self.rate)
with Transaction().set_context(date=date or self.currency_date):
return Currency.compute(
self.currency, amount, self.company.currency)
@staticmethod
def default_type():
return Transaction().context.get('type', 'out')
@@ -1900,6 +1910,8 @@ class Invoice(Workflow, ModelSQL, ModelView, TaxableMixin, InvoiceReportMixin):
moves = []
for invoice in invoices:
if invoice.currency != invoice.company.currency and not invoice.rate:
invoice.rate = invoice.get_selected_rate()
move = invoice.get_move()
if move != invoice.move:
invoice.move = move
@@ -3199,7 +3211,6 @@ class InvoiceLine(sequence_ordered(), ModelSQL, ModelView, TaxableMixin):
def _compute_taxes(self):
pool = Pool()
Currency = pool.get('currency.currency')
TaxLine = pool.get('account.tax.line')
tax_lines = []
@@ -3208,11 +3219,7 @@ class InvoiceLine(sequence_ordered(), ModelSQL, ModelView, TaxableMixin):
taxes = self._get_taxes().values()
for tax in taxes:
amount = tax['base']
with Transaction().set_context(
date=self.invoice.currency_date):
amount = Currency.compute(
self.invoice.currency, amount,
self.invoice.company.currency)
amount = self.invoice._compute_company_currency_amount(amount)
tax_line = TaxLine()
tax_line.amount = amount
tax_line.type = 'base'
@@ -3537,9 +3544,7 @@ class InvoiceTax(sequence_ordered(), ModelSQL, ModelView):
'''
Return a list of move lines instances for invoice tax
'''
Currency = Pool().get('currency.currency')
pool = Pool()
Currency = pool.get('currency.currency')
MoveLine = pool.get('account.move.line')
TaxLine = pool.get('account.tax.line')
line = MoveLine()
@@ -3547,11 +3552,8 @@ class InvoiceTax(sequence_ordered(), ModelSQL, ModelView):
return []
line.description = self.description
if self.invoice.currency != self.invoice.company.currency:
with Transaction().set_context(date=self.invoice.currency_date):
amount = Currency.compute(self.invoice.currency, self.amount,
self.invoice.company.currency)
base = Currency.compute(self.invoice.currency, self.base,
self.invoice.company.currency)
amount = self.invoice._compute_company_currency_amount(self.amount)
base = self.invoice._compute_company_currency_amount(self.base)
line.amount_second_currency = self.amount
line.second_currency = self.invoice.currency
else: