Before this commit the reports in sales and associated app suffered from a confusion between
multiplicative and divisive rates for currency conversion. After this commit this will no longer be
the case.
There are several models with their own currencies that are involved in computing the amount of a
sale order:
- the order's company currency `order.company_id.currency_id`
- the order's pricelist currency `order.pricelist_id.currency_id`
- the product's currency for each product in the sale order `product.currency_id`
In the case of a report we need also to take into account the current user's company currency:
`self.env.company.currency_id`.
The `sale_order.currency_rate` is the **multiplicative <u>rate</u>** to convert from the company
currency into the SO currency.
Any product added to a sale order follow the next conversion. Let `conversion_rate` be the conversion
rate between the product's currency and the order's company currency, then:
```python
product_amount_converted = product.list_price / conversion_rate
order.amount_total += product_amount_converted * order.currency_rate
```
The rates returned by `_get_query_currency_table()`, on the other hand, are computed as the
**multiplicative <u>ratio</u>** to convert from each company currency into the current user's
company currency.
Any order that is to be analysed on a *report* follow the next conversion. Let `current_company_currency_rate`
be the conversion rate between the order's company currency and the current user's company, then:
```python
order_amount_in_cmp_currency = order.amount_total / order.currency_rate
report.order_id.price_total = order_amount_in_cmp_currency * current_company_currency_rate
```
What follow is a numerical example. Suppose you have the following multi-company and
multi-currency environment.
|order.id|order.company |line.subtotal|order.currency|order.currency_rate|
| ------ | ----------- | ----------- | ------------ | ----------------- |
|1 |BE Company (EUR)|1000 |INR |89.46 |
|2 |BE Company (EUR)|2000 |USD |1.09 |
|3 |BE Company (EUR)|3000 |EUR |1.0 |
|4 |US Company (USD)|4000 |USD |1.0 |
If we try to convert all of this for reporting in the US company, the currency table returned by
`_get_query_currency_table()` will give this (company currencies vs USD):
|currency_table.company|currency_table.rate|
| -------------------- | ------------------ |
|BE Company (EUR) |1.09 |
|US Company (USD) |1.0 |
Finally, in order to convert each amount into USD, applying the formulae listed above should give
the following result:
|order.id|order.company|display_price_usd |
| ------ | ----------- | -------------------------- |
|1 |BE Company |1000 / 89.46 * 1.09 = 12.18 |
|2 |BE Company |2000 / 1.09 * 1.09 = 2000.00|
|3 |BE Company |3000 / 1.0 * 1.09 = 3270.00 |
|4 |US Company |4000 / 1.0 * 1.0 = 4000.00 |
|Total (USD): 9282.18|
Task - 3277006
closesodoo/odoo#125402
X-original-commit: e8f7a692eaf6b87ccf4a8d95b7a46146b1199bf2
Signed-off-by: Victor Feyens (vfe) <vfe@odoo.com>
Signed-off-by: Horacio Tellez Perez (hote) <hote@odoo.com>
Sale Analysis report shows prices in company currency, converting foreign currency into the company currency according to the currency exchange rate.
Currently, the currency conversion is done incorrectly.
For example let's say 1 EUR = 25 CZK OR 1 CZK = 0.04 EUR.
Sales order: 39 EUR = 975 CZK.
Sales Analysis report shows 1.56.
This is because we are trying to multiply the order amount by 0.04, while it should be divided.
It used to be divided up until 16.0.
This commit changes the operator to convert the currency correctly.
opw-3167522
closesodoo/odoo#113525
X-original-commit: ef57d53866dc1d404138809132176c79d60a3b51
Signed-off-by: Aliya Tastemirova (alta) <alta@odoo.com>
Before when reporting in the sale module in a multi-company
environment currencies where not converted to a unique currency
before mathematical operations (sum, avg, ...).
Now before mathematical operations currencies are converted to
the currency of the company currently selected.
Task - 2696759
closesodoo/odoo#83550
Signed-off-by: Victor Feyens (vfe) <vfe@odoo.com>
* remove unused delay column (there was no field using the value server
side)
* remove unused joins in the FROM part of the table definition (join on
pricelists)
* fix broken inheritance API
pos_sale inheritance adds a null value for fields not available added in
sub modules (website, invoice_status, ...). But this was only working
because the default value of the fields parameter of the _query method
was overridden to a dict in all overrides, filling the record while
climbing the inheritance chain.
This was clearly too magic, using information provided higher in the
inheritance chain, assuming you were calling the super before generating
the pos part of the query.
This commit cleans the methods and API of the model, providing clean
hooks and reducing the mess of values given in overrides of _query.
closesodoo/odoo#85125
Related: odoo/enterprise#24626
Signed-off-by: Yannick Tivisse (yti) <yti@odoo.com>
Impacted modules: sale, sale_margin, sale_timesheet, pos_sale
This speed up a lot reports like sale.report when multiple currencies
with multiple rates are used, even with few currencies and few rates.
Using `_select_companies_rates` in SQL view bring lots of JOINs,
which slow down the view generation. This commit adds a computed
stored field containing the currency rate at the order date to speed
up report generation (database schema denormalisation).
This commit also use this new column on sale.report extensions and on
the project.profitability.report in sale_timesheet module.
Since a4d6bff197, the pos.report is
included in the sale.report. So, the same change had to be
applied on the pos.order model.
Task #1877418Closes#25089
This issue was introduced with the following commit
https://github.com/odoo/odoo/commit/a4d6bff197b894f70eaecf5aa4e2088e5b014780
The problem is that during the task #58961 we changed the API to
generate the sale_report, but forgot to include the
website_sale_dashboard sale_report, hence when accessing we had a
traceback since this file was using the old API.
Task #1869500Closes#26070
In Sales, we want to merge the `All Channels Sale Orders` report with
the `Sales` report in order to avoid having information scattered
accross two different reports.
Related to task #58961Closes#23324