Skip to content

Commit 4910c2a

Browse files
committed
[ADD] crm_lead_company_currency_fix: new module
1 parent f8be762 commit 4910c2a

12 files changed

Lines changed: 806 additions & 0 deletions

File tree

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
.. image:: https://odoo-community.org/readme-banner-image
2+
:target: https://odoo-community.org/get-involved?utm_source=readme
3+
:alt: Odoo Community Association
4+
5+
=======================
6+
CRM - Fix lead currency
7+
=======================
8+
9+
..
10+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
11+
!! This file is generated by oca-gen-addon-readme !!
12+
!! changes will be overwritten. !!
13+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
14+
!! source digest: sha256:34af6785c2aaa8fa8b396b8fae36790aa96db6030caf8ac27affbdb1f14f3088
15+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
16+
17+
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
18+
:target: https://odoo-community.org/page/development-status
19+
:alt: Beta
20+
.. |badge2| image:: https://img.shields.io/badge/license-LGPL--3-blue.png
21+
:target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html
22+
:alt: License: LGPL-3
23+
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fcrm-lightgray.png?logo=github
24+
:target: https://github.com/OCA/crm/tree/19.0/crm_lead_company_currency_fix
25+
:alt: OCA/crm
26+
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
27+
:target: https://translation.odoo-community.org/projects/crm-19-0/crm-19-0-crm_lead_company_currency_fix
28+
:alt: Translate me on Weblate
29+
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
30+
:target: https://runboat.odoo-community.org/builds?repo=OCA/crm&target_branch=19.0
31+
:alt: Try me on Runboat
32+
33+
|badge1| |badge2| |badge3| |badge4| |badge5|
34+
35+
In Odoo standard source code, leads' currency is defined as a computed,
36+
non-stored field, which follows this workflow:
37+
38+
- if the lead's company is set, then the company currency is used
39+
40+
- if the lead's company is not set, then the user's company currency is
41+
used
42+
43+
Since the field is not stored, it leads to 2 main issues:
44+
45+
1) Changing a company's currency will change the currency on all the
46+
existing leads linked to that company, but not the amounts. Eg:
47+
48+
- you have a lead linked to a company in EUR
49+
- the lead's expected revenue is 1000 EUR
50+
- you change the company currency to USD
51+
- the lead's expected revenue becomes 1000 USD
52+
53+
2) If a lead is not linked to a specific company, then 2 users that are
54+
logged in with 2 different companies and different currencies will
55+
see the lead's amounts with different currencies. Eg:
56+
57+
- you have a lead where the company is not set
58+
- accessing the lead with a user whose main company is in EUR will
59+
display an expected revenue of 1000 EUR
60+
- accessing the lead with a user whose main company is in USD will
61+
display an expected revenue of 1000 USD
62+
63+
This module stores the field in the DB to keep data consistency, and
64+
will only update the lead's currency only if the lead's company itself
65+
is updated. The behavior for computing the lead's currency will remain
66+
the same (currency is retrieved from the lead's company or the current
67+
user's company), but the issues are fixed:
68+
69+
1) Changing a company's currency **will not change the currency on
70+
existing leads**, only on the ones created after the currency has
71+
been updated. Eg:
72+
73+
- you have a lead linked to a company in EUR
74+
- the lead's expected revenue is 1000 EUR
75+
- you change the company currency to USD
76+
- the lead's expected revenue is still 1000 EUR
77+
- a newly created lead's expected revenue will be in USD, not EUR
78+
79+
2) If a lead is not linked to a specific company, then 2 users that are
80+
logged in with 2 different companies and different currencies will
81+
see the **lead's amounts with the same currency** (computed from the
82+
company of the first user that triggers the recomputation). Eg:
83+
84+
- you have a lead where the company is not set
85+
- accessing the lead with a 1st user whose main company is in EUR
86+
will display an expected revenue of 1000 EUR
87+
- accessing the lead with a 2nd user whose main company is in USD
88+
will display an expected revenue of 1000 EUR, because the currency
89+
was set from the previous user's company
90+
91+
**Table of contents**
92+
93+
.. contents::
94+
:local:
95+
96+
Bug Tracker
97+
===========
98+
99+
Bugs are tracked on `GitHub Issues <https://github.com/OCA/crm/issues>`_.
100+
In case of trouble, please check there if your issue has already been reported.
101+
If you spotted it first, help us to smash it by providing a detailed and welcomed
102+
`feedback <https://github.com/OCA/crm/issues/new?body=module:%20crm_lead_company_currency_fix%0Aversion:%2019.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
103+
104+
Do not contact contributors directly about support or help with technical issues.
105+
106+
Credits
107+
=======
108+
109+
Authors
110+
-------
111+
112+
* Camptocamp
113+
114+
Contributors
115+
------------
116+
117+
- Silvio Gregorini <silviogregorini@camptocamp.com> (`Camptocamp
118+
SA <https://www.camptocamp.com/>`__)
119+
120+
Maintainers
121+
-----------
122+
123+
This module is maintained by the OCA.
124+
125+
.. image:: https://odoo-community.org/logo.png
126+
:alt: Odoo Community Association
127+
:target: https://odoo-community.org
128+
129+
OCA, or the Odoo Community Association, is a nonprofit organization whose
130+
mission is to support the collaborative development of Odoo features and
131+
promote its widespread use.
132+
133+
This module is part of the `OCA/crm <https://github.com/OCA/crm/tree/19.0/crm_lead_company_currency_fix>`_ project on GitHub.
134+
135+
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import models
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Copyright 2026 Camptocamp SA
2+
# License LGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
3+
4+
{
5+
"name": "CRM - Fix lead currency",
6+
"summary": "Fixes usage of leads' currencies",
7+
"version": "19.0.1.0.0",
8+
"category": "Sales/CRM",
9+
"website": "https://github.com/OCA/crm",
10+
"author": "Camptocamp, Odoo Community Association (OCA)",
11+
"license": "LGPL-3",
12+
"depends": [
13+
# Odoo
14+
"crm",
15+
],
16+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import crm_lead
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Copyright 2026 Camptocamp SA
2+
# License LGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
3+
4+
from odoo import fields, models
5+
6+
7+
class CRMLead(models.Model):
8+
_inherit = "crm.lead"
9+
10+
# OVERRIDE: make ``company_currency`` a stored field
11+
company_currency = fields.Many2one(store=True)
12+
13+
def _field_to_sql(self, alias, field_expr, query=None):
14+
# OVERRIDE: module ``crm`` override for ``field_expr == "company_currency"``
15+
# creates a SQL object that represents the dynamic nature of the original
16+
# computed, non-stored field. We need to ignore that to use the DB-stored
17+
# values instead.
18+
if field_expr == "company_currency":
19+
return models.Model._field_to_sql(self, alias, field_expr, query=query)
20+
return super()._field_to_sql(alias, field_expr, query=query)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[build-system]
2+
requires = ["whool"]
3+
build-backend = "whool.buildapi"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- Silvio Gregorini \<<silviogregorini@camptocamp.com>\> ([Camptocamp SA](https://www.camptocamp.com/))
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
In Odoo standard source code, leads' currency is defined as a computed, non-stored
2+
field, which follows this workflow:
3+
4+
- if the lead's company is set, then the company currency is used
5+
6+
- if the lead's company is not set, then the user's company currency is used
7+
8+
Since the field is not stored, it leads to 2 main issues:
9+
10+
1) Changing a company's currency will change the currency on all the existing leads
11+
linked to that company, but not the amounts. Eg:
12+
- you have a lead linked to a company in EUR
13+
- the lead's expected revenue is 1000 EUR
14+
- you change the company currency to USD
15+
- the lead's expected revenue becomes 1000 USD
16+
17+
2) If a lead is not linked to a specific company, then 2 users that are logged in with
18+
2 different companies and different currencies will see the lead's amounts with
19+
different currencies. Eg:
20+
- you have a lead where the company is not set
21+
- accessing the lead with a user whose main company is in EUR will display an
22+
expected revenue of 1000 EUR
23+
- accessing the lead with a user whose main company is in USD will display an
24+
expected revenue of 1000 USD
25+
26+
This module stores the field in the DB to keep data consistency, and will only update
27+
the lead's currency only if the lead's company itself is updated. The behavior for
28+
computing the lead's currency will remain the same (currency is retrieved from the
29+
lead's company or the current user's company), but the issues are fixed:
30+
31+
1) Changing a company's currency **will not change the currency on existing leads**,
32+
only on the ones created after the currency has been updated. Eg:
33+
- you have a lead linked to a company in EUR
34+
- the lead's expected revenue is 1000 EUR
35+
- you change the company currency to USD
36+
- the lead's expected revenue is still 1000 EUR
37+
- a newly created lead's expected revenue will be in USD, not EUR
38+
39+
2) If a lead is not linked to a specific company, then 2 users that are logged in with
40+
2 different companies and different currencies will see the **lead's amounts with
41+
the same currency** (computed from the company of the first user that triggers the
42+
recomputation). Eg:
43+
- you have a lead where the company is not set
44+
- accessing the lead with a 1st user whose main company is in EUR will display an
45+
expected revenue of 1000 EUR
46+
- accessing the lead with a 2nd user whose main company is in USD will display an
47+
expected revenue of 1000 EUR, because the currency was set from the previous
48+
user's company

0 commit comments

Comments
 (0)