Commit Graph
25 Commits
Author SHA1 Message Date
hote 8447c93ba2 [FIX] sale: currency conversions and rates
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

closes odoo/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>
2023-06-22 08:34:58 +02:00
aliya 141bed9360 [FIX] sale: fix currency conversion in sale report
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

closes odoo/odoo#113525

X-original-commit: ef57d53866dc1d404138809132176c79d60a3b51
Signed-off-by: Aliya Tastemirova (alta) <alta@odoo.com>
2023-02-23 18:29:02 +01:00
Horacio Tellez 20fbc19a2d [FIX] sale: Report on converted currency
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

closes odoo/odoo#83550

Signed-off-by: Victor Feyens (vfe) <vfe@odoo.com>
2022-04-29 12:05:21 +02:00
Victor Feyens 740a507de6 [REF] *sale*: clean inheritance/setup of sale report
* 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.

closes odoo/odoo#85125

Related: odoo/enterprise#24626
Signed-off-by: Yannick Tivisse (yti) <yti@odoo.com>
2022-02-28 13:52:57 +00:00
Nicolas Seinlet e8f01b94ce [IMP] sale,sale_*: denormalize sale.order to speed up sale.report
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 #1877418
Closes #25089
2018-08-21 13:28:42 +02:00
RomainLibert 5752a8643a [FIX] sale*,pos_sale: edit sale_report to fix an issue in enterprise
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 #1869500
Closes #26070
2018-07-31 17:12:58 +02:00
Hetashree Chauhan a4d6bff197 [IMP] sale, pos_sale: merge sale report
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 #58961
Closes #23324
2018-07-26 11:47:18 +02:00
Christophe Simonis 50d8ea1d58 [MERGE] forward port branch saas-15 up to aae12c2bad 2017-06-12 19:37:28 +02:00
Christophe Simonis 6ceecffcad [MERGE] forward port branch 9.0 up to d9d455bea3 2017-06-12 18:18:05 +02:00
Goffin Simon 7bc52a34ba [FIX] sale_margin: margin in company currency in sale.report
The margin must be expressed in the company currency like price_total
or price_subtotal.

opw:746038
2017-06-12 16:54:29 +02:00
xmo-odoo b4429c2a91 [FIX] Various P3-related import changes
* LDAP import: python-ldap is not python3-compatible, pyldap is

  Warning: only supported from debian Stretch (current testing)?
  https://packages.debian.org/search?searchon=names&keywords=pyldap

* implicitly relative imports
* imports of moved or removed stdlib modules

issue #8530
2017-04-28 09:06:53 +02:00
Anand Kansagra 1ca86e70de [IMP] sale_margin: Migrate into new api. 2015-12-16 10:29:03 +01:00
Jitendra Prajapati 6c56e1edd3 [IMP] sale_margin: show margin on sale analysis report if sale_margin module is installed 2014-12-19 13:18:25 +01:00
Fabien Pinckaers 4fdebeef0f [IMP] removed completly false report
bzr revid: fp@tinyerp.com-20110924141451-772qbu8ipjib4ulo
2011-09-24 16:14:51 +02:00
Antony Lesuisse ccc56996dd [MERGE] trunk-search_views or instead of and in groups
bzr revid: al@openerp.com-20110923172247-pj5ii3pxisiyco6k
2011-09-23 19:22:47 +02:00
Kuldeep Joshi (OpenERP) 73d8fcb8a8 [IMP] rename Current into Open in report.account.invoice.product search_view
bzr revid: kjo@tinyerp.com-20110920093305-eguvulko7rmn2m84
2011-09-20 15:03:05 +05:30
Fabien Pinckaers 05d6d35cc8 [Merge]
bzr revid: fp@tinyerp.com-20110917110317-34apz3spz1h9azjl
2011-09-17 13:03:17 +02:00
Xavier Morel 9888008e74 [FIX] pie chart composition: groups don't make sense, 2 value fields don't either
bzr revid: xmo@openerp.com-20110513132417-mfxd2wvyn0dx3cs2
2011-05-13 15:24:17 +02:00
Xavier Morel 4e6a9ea55c [REM] all @col and @colspan attributes on groups in search views: search views are not laid out by columns, therefore these attributes do not belong
bzr revid: xmo@openerp.com-20110315140859-uh9w3exdit84qz47
2011-03-15 15:08:59 +01:00
Vir (Open ERP) e8ec3efe69 [ADD] account_* : help added for menus
bzr revid: vir@tinyerp.com-20101102070455-obn9kosyhajipnur
2010-11-02 12:34:55 +05:30
AMP (OpenERP) 9867d80411 [MOD/IMP] account,sale : Usebility Improvement in Icon and Extended Filter
bzr revid: amp@tinyerp.com-20101026130235-qrx5ky3mgmfc2yf7
2010-10-26 18:32:35 +05:30
Vir (Open ERP) 6652e6b0eb [IMP/MOD] mrp,point_of_sale,product,project,project_issue,purchase,sale,sale_margin * : Extended filter option set before group by in search view
bzr revid: vir@tinyerp.com-20100927074124-j4waeanwhbhvb0kn
2010-09-27 13:11:24 +05:30
Vir (Open ERP) e0f5805183 [MOD] Improvements in sales_* module access rights
bzr revid: vir@tinyerp.com-20100805135146-v823i09f2e8bq3b9
2010-08-05 19:21:46 +05:30
AMP(OpenERP) 4f02237856 [RENAME] From Extended option to Extended Filters, in all search views
bzr revid: vir@tinyerp.com-20100730110414-dfpapk594677vfsm
2010-07-30 16:34:14 +05:30
sbh (Open ERP) a94a5a9266 [IMP] sale_margin: Move the report file in folder
bzr revid: sbh@tinyerp.com-20100603103023-u0bcuwh4fpcoswfh
2010-06-03 16:00:23 +05:30