[FIX] account, stock_account: valuation multi-currency

- Set USD as company currency
- Set the EUR rate to 1.5
- Create a product A: FIFO & automated, invoicing based on delivery
- Create a pricelist in EUR
- Buy some quantity @ 100 USD
- Create a SO for 1 @ 200 EUR
- Confirm the SO, validate the picking, generate the invoice
- Do not set an invoice date
- Post the invoice

The COGS are incorrect:

                            Amount Currency         Debit        Credit
Stock Interim (Delivered)              0.00          0.00         66.67
Expense                                0.00         66.67          0.00

It should be:

                            Amount Currency         Debit        Credit
Stock Interim (Delivered)              0.00          0.00        100.00
Expense                                0.00        100.00          0.00

Commit 3a6ada5 attempted to correct the issue, but it was only
working when an invoice date was set.

In the current situation, when no invoice date is set, there is a
conversion issue. This is because of [1], which ultimately calls [2].
This triggers a recomputation of the credit and debit in [3].

After the accounting refactoring, it is assumed that all AML have the
same currency than the AM. This is for the case in [4]. In case of the
COGS, it is not the case.

Note that we could have done the conversion in Amount Currency (see
PR #42646). But that leads to a recomputation of the debit and credit
which (1) is unnecessary and (2) could lead to rounding errors.

[1] https://github.com/odoo/odoo/blob/01a24fd1df32766a9ed6cedd571ed30c75ef726b/addons/account/models/account_move.py#L2079
[2] https://github.com/odoo/odoo/blob/01a24fd1df32766a9ed6cedd571ed30c75ef726b/addons/account/models/account_move.py#L2894
[3] https://github.com/odoo/odoo/blob/01a24fd1df32766a9ed6cedd571ed30c75ef726b/addons/account/models/account_move.py#L2725-L2726
[4] https://github.com/odoo/odoo/blob/f71979a681d95d98db19a80feb59fdf684ec361f/addons/account/models/account_move.py#L337-L339

opw-2148171
opw-2162068

closes odoo/odoo#42816

X-original-commit: 0aee89780c8825fd28cc5bf44048101ac7010eac
Signed-off-by: Nicolas Martinelli (nim) <nim@odoo.com>
This commit is contained in:
Nicolas Martinelli
2020-01-07 08:13:41 +00:00
parent 691a22f808
commit 81b69f393b
2 changed files with 9 additions and 1 deletions
+5 -1
View File
@@ -332,7 +332,7 @@ class AccountMove(models.Model):
company_currency = self.company_id.currency_id
has_foreign_currency = self.currency_id and self.currency_id != company_currency
for line in self.line_ids:
for line in self._get_lines_onchange_currency():
new_currency = has_foreign_currency and self.currency_id
line.currency_id = new_currency
@@ -886,6 +886,10 @@ class AccountMove(models.Model):
if invoice != invoice._origin:
invoice.invoice_line_ids = invoice.line_ids.filtered(lambda line: not line.exclude_from_invoice_tab)
def _get_lines_onchange_currency(self):
# Override needed for COGS
return self.line_ids
def onchange(self, values, field_name, field_onchange):
# OVERRIDE
# As the dynamic lines in this model are quite complex, we need to ensure some computations are done exactly
@@ -13,6 +13,10 @@ class AccountMove(models.Model):
# OVERRIDE METHODS
# -------------------------------------------------------------------------
def _get_lines_onchange_currency(self):
# OVERRIDE
return self.line_ids.filtered(lambda l: not l.is_anglo_saxon_line)
def _reverse_move_vals(self, default_values, cancel=True):
# OVERRIDE
# Don't keep anglo-saxon lines if not cancelling an existing invoice.