[FIX] account: check exchange rate

An issue occurs in the following situation:
- Define a currency exchange rate at day 1 and day 2
- Create an invoice at day 1, and calculate the taxes. Do not set an
  invoice date!
- Validate the invoice at day 2

The exchange rate for taxes is the rate at day 1, while the exchange
rate for other amounts is the rate at day 2.

There is actually no way to know what was the rate applied for the
taxes at invoice validation. There are two solutions:
- recompute the taxes at validation
- force the user to set an invoice date and recompute manually the
  taxes

The first solution might have unexpected effects, therefore the second
solution is applied.

Fixes #13473
opw-688517
This commit is contained in:
Nicolas Martinelli 2016-09-27 09:41:05 +02:00
parent d3c4ab23e4
commit a1d6c2d631
1 changed files with 10 additions and 1 deletions

View File

@ -807,11 +807,20 @@ class account_invoice(models.Model):
ctx = dict(self._context, lang=inv.partner_id.lang)
company_currency = inv.company_id.currency_id
if not inv.date_invoice:
# FORWARD-PORT UP TO SAAS-6
if inv.currency_id != company_currency and inv.tax_line:
raise except_orm(
_('Warning!'),
_('No invoice date!'
'\nThe invoice currency is not the same than the company currency.'
' An invoice date is required to determine the exchange rate to apply. Do not forget to update the taxes!'
)
)
inv.with_context(ctx).write({'date_invoice': fields.Date.context_today(self)})
date_invoice = inv.date_invoice
company_currency = inv.company_id.currency_id
# create the analytical lines, one move line per invoice line
iml = inv._get_analytic_lines()
# check if taxes are all computed