Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
135 changes: 135 additions & 0 deletions crm_lead_company_currency_fix/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
.. image:: https://odoo-community.org/readme-banner-image
:target: https://odoo-community.org/get-involved?utm_source=readme
:alt: Odoo Community Association

=======================
CRM - Fix lead currency
=======================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:34af6785c2aaa8fa8b396b8fae36790aa96db6030caf8ac27affbdb1f14f3088
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/license-LGPL--3-blue.png
:target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html
:alt: License: LGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fcrm-lightgray.png?logo=github
:target: https://github.com/OCA/crm/tree/19.0/crm_lead_company_currency_fix
:alt: OCA/crm
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/crm-19-0/crm-19-0-crm_lead_company_currency_fix
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/crm&target_branch=19.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

In Odoo standard source code, leads' currency is defined as a computed,
non-stored field, which follows this workflow:

- if the lead's company is set, then the company currency is used

- if the lead's company is not set, then the user's company currency is
used

Since the field is not stored, it leads to 2 main issues:

1) Changing a company's currency will change the currency on all the
existing leads linked to that company, but not the amounts. Eg:

- you have a lead linked to a company in EUR
- the lead's expected revenue is 1000 EUR
- you change the company currency to USD
- the lead's expected revenue becomes 1000 USD

2) If a lead is not linked to a specific company, then 2 users that are
logged in with 2 different companies and different currencies will
see the lead's amounts with different currencies. Eg:

- you have a lead where the company is not set
- accessing the lead with a user whose main company is in EUR will
display an expected revenue of 1000 EUR
- accessing the lead with a user whose main company is in USD will
display an expected revenue of 1000 USD

This module stores the field in the DB to keep data consistency, and
will only update the lead's currency only if the lead's company itself
is updated. The behavior for computing the lead's currency will remain
the same (currency is retrieved from the lead's company or the current
user's company), but the issues are fixed:

1) Changing a company's currency **will not change the currency on
existing leads**, only on the ones created after the currency has
been updated. Eg:

- you have a lead linked to a company in EUR
- the lead's expected revenue is 1000 EUR
- you change the company currency to USD
- the lead's expected revenue is still 1000 EUR
- a newly created lead's expected revenue will be in USD, not EUR

2) If a lead is not linked to a specific company, then 2 users that are
logged in with 2 different companies and different currencies will
see the **lead's amounts with the same currency** (computed from the
company of the first user that triggers the recomputation). Eg:

- you have a lead where the company is not set
- accessing the lead with a 1st user whose main company is in EUR
will display an expected revenue of 1000 EUR
- accessing the lead with a 2nd user whose main company is in USD
will display an expected revenue of 1000 EUR, because the currency
was set from the previous user's company

**Table of contents**

.. contents::
:local:

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/crm/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`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**>`_.

Do not contact contributors directly about support or help with technical issues.

Credits
=======

Authors
-------

* Camptocamp

Contributors
------------

- Silvio Gregorini <silvio.gregorini@camptocamp.com> (`Camptocamp
SA <https://www.camptocamp.com/>`__)

Maintainers
-----------

This module is maintained by the OCA.

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

This module is part of the `OCA/crm <https://github.com/OCA/crm/tree/19.0/crm_lead_company_currency_fix>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
1 change: 1 addition & 0 deletions crm_lead_company_currency_fix/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
20 changes: 20 additions & 0 deletions crm_lead_company_currency_fix/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Copyright 2026 Camptocamp SA
# License LGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

{
"name": "CRM - Fix lead currency",
"summary": "Fixes usage of leads' currencies",
"version": "19.0.1.0.0",
"category": "Sales/CRM",
"website": "https://github.com/OCA/crm",
"author": "Camptocamp, Odoo Community Association (OCA)",
"license": "LGPL-3",
"depends": [
# Odoo
"crm",
],
# Make sure this module is installed as soon as possible
# after ``crm`` is installed: this way, the override of
# ``crm.lead._field_to_sql()`` will work correctly
"sequence": 0,
}
1 change: 1 addition & 0 deletions crm_lead_company_currency_fix/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import crm_lead
20 changes: 20 additions & 0 deletions crm_lead_company_currency_fix/models/crm_lead.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Copyright 2026 Camptocamp SA
# License LGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

from odoo import fields, models


class CRMLead(models.Model):
_inherit = "crm.lead"

# OVERRIDE: make ``company_currency`` a stored field
company_currency = fields.Many2one(store=True)

def _field_to_sql(self, alias, field_expr, query=None):
# OVERRIDE: module ``crm`` override for ``field_expr == "company_currency"``
# creates a SQL object that represents the dynamic nature of the original
# computed, non-stored field. We need to ignore that to use the DB-stored
# values instead.
if field_expr == "company_currency":
return models.Model._field_to_sql(self, alias, field_expr, query=query)
return super()._field_to_sql(alias, field_expr, query=query)
3 changes: 3 additions & 0 deletions crm_lead_company_currency_fix/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["whool"]
build-backend = "whool.buildapi"
1 change: 1 addition & 0 deletions crm_lead_company_currency_fix/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Silvio Gregorini \<<silvio.gregorini@camptocamp.com>\> ([Camptocamp SA](https://www.camptocamp.com/))
48 changes: 48 additions & 0 deletions crm_lead_company_currency_fix/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
In Odoo standard source code, leads' currency is defined as a computed, non-stored
field, which follows this workflow:

- if the lead's company is set, then the company currency is used

- if the lead's company is not set, then the user's company currency is used

Since the field is not stored, it leads to 2 main issues:

1) Changing a company's currency will change the currency on all the existing leads
linked to that company, but not the amounts. Eg:
- you have a lead linked to a company in EUR
- the lead's expected revenue is 1000 EUR
- you change the company currency to USD
- the lead's expected revenue becomes 1000 USD

2) If a lead is not linked to a specific company, then 2 users that are logged in with
2 different companies and different currencies will see the lead's amounts with
different currencies. Eg:
- you have a lead where the company is not set
- accessing the lead with a user whose main company is in EUR will display an
expected revenue of 1000 EUR
- accessing the lead with a user whose main company is in USD will display an
expected revenue of 1000 USD

This module stores the field in the DB to keep data consistency, and will only update
the lead's currency only if the lead's company itself is updated. The behavior for
computing the lead's currency will remain the same (currency is retrieved from the
lead's company or the current user's company), but the issues are fixed:

1) Changing a company's currency **will not change the currency on existing leads**,
only on the ones created after the currency has been updated. Eg:
- you have a lead linked to a company in EUR
- the lead's expected revenue is 1000 EUR
- you change the company currency to USD
- the lead's expected revenue is still 1000 EUR
- a newly created lead's expected revenue will be in USD, not EUR

2) If a lead is not linked to a specific company, then 2 users that are logged in with
2 different companies and different currencies will see the **lead's amounts with
the same currency** (computed from the company of the first user that triggers the
recomputation). Eg:
- you have a lead where the company is not set
- accessing the lead with a 1st user whose main company is in EUR will display an
expected revenue of 1000 EUR
- accessing the lead with a 2nd user whose main company is in USD will display an
expected revenue of 1000 EUR, because the currency was set from the previous
user's company
Loading