Skip to content

Commit 655ed01

Browse files
committed
[MIG] base_multicompany_reporting_currency: Migration to 19.0
1 parent 1429997 commit 655ed01

15 files changed

Lines changed: 452 additions & 77 deletions

base_multicompany_reporting_currency/README.rst

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,22 +35,33 @@ Base Multicompany Reporting Currency
3535
In Odoo standard, when it comes to reporting in a multicompany and
3636
multicurrency environment, it should be done on the invoices. (Cf Fabien
3737
Pinckaers tweet: https://twitter.com/fpodoo/status/1511831215673913344)
38+
3839
Nonetheless, some companies do not use the Invoicing or Accounting app
3940
in Odoo. For example, when using only CRM and Sales. With this module,
4041
we introduce the concept of currency for reporting to be set in General
4142
Settings. This way we can reuse the idea behind
4243
https://github.com/OCA/sale-workflow/tree/10.0/sale_company_currency,
4344
but with a predefined currency.
4445

45-
This Module adds a setting in General Settings to set multicompany
46-
reporting currency which be applied to all companies. Multicompany
47-
reporting currency field will be used in other dependent modules to
48-
compare amounts in different companies and documents. NB: This module
49-
does not provide any feature itself. You should install
50-
sale_multicompany_reporting_currency from
46+
This module adds:
47+
48+
- a setting in General Settings to set multicompany reporting currency
49+
which be applied to all companies
50+
- a system parameter to store the chosen multicompany reporting
51+
currency DB-wide
52+
- a mixin model to inherit for handling all basic operations - eg:
53+
automatically update the multicompany reporting currency on a model's
54+
records when the settings change
55+
56+
Multicompany reporting currency field will be used in other dependent
57+
modules to compare amounts in different companies and documents.
58+
59+
NB: This module does not provide any feature for specific apps. You
60+
should install ``sale_multicompany_reporting_currency`` from
5161
https://github.com/OCA/sale-reporting or
52-
crm_multicompany_reporting_currency from https://github.com/OCA/crm to
53-
have additional Total (Multicompany Reporting Currency) field.
62+
``crm_multicompany_reporting_currency`` from https://github.com/OCA/crm
63+
to have additional Total (Multicompany Reporting Currency) fields on
64+
specific apps.
5465

5566
**Table of contents**
5667

@@ -73,12 +84,16 @@ Credits
7384
Authors
7485
-------
7586

76-
* Camptocamp SA
87+
* Camptocamp
7788

7889
Contributors
7990
------------
8091

81-
- Maksym Yankin <maksym.yankin@camptocamp.com>
92+
- [Camptocamp SA](https://www.camptocamp.com):
93+
94+
- Maksym Yankin <maksym.yankin@camptocamp.com>
95+
- Silvio Gregorini <silvio.gregorini@camptocamp.com>
96+
8297
- [APSL-Nagarro](https://apsl.tech):
8398

8499
- Antoni Marroig <amarroig@apsl.net>
Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
11
# Copyright 2022 Camptocamp SA
22
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
3+
34
{
45
"name": "Base Multicompany Reporting Currency",
56
"summary": "Adds the possibility to specify Multicompany Reporting Currency",
6-
"version": "16.0.1.0.0",
7+
"version": "19.0.1.0.0",
78
"category": "Sales",
8-
"author": "Camptocamp SA, Odoo Community Association (OCA)",
9+
"author": "Camptocamp, Odoo Community Association (OCA)",
910
"license": "AGPL-3",
10-
"depends": ["base_setup"],
11+
"depends": [
12+
# Odoo
13+
"base_setup",
14+
],
1115
"website": "https://github.com/OCA/sale-reporting",
1216
"data": [
13-
"data/default_multicompany_reporting_currency.xml",
14-
"views/res_config_settings_views.xml",
17+
# Views
18+
"views/res_config_settings.xml",
1519
],
1620
"installable": True,
1721
}

base_multicompany_reporting_currency/data/default_multicompany_reporting_currency.xml

Lines changed: 0 additions & 8 deletions
This file was deleted.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1+
from . import ir_config_parameter
2+
from . import multicompany_reporting_currency_mixin
13
from . import res_config_settings
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# Copyright 2026 Camptocamp SA
2+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html)
3+
4+
from odoo import api, models
5+
6+
7+
class IrConfigParameter(models.Model):
8+
_inherit = "ir.config_parameter"
9+
10+
@api.model
11+
def _get_multicompany_reporting_currency_key(self) -> str:
12+
return "base_multicompany_reporting_currency.multicompany_reporting_currency"
13+
14+
def init(self, force=False):
15+
# OVERRIDE: if missing, create the system parameter for key
16+
# ``base_multicompany_reporting_currency.multicompany_reporting_currency``
17+
# (will be EUR by default)
18+
res = super().init(force=force)
19+
key = self._get_multicompany_reporting_currency_key()
20+
if not self.search([("key", "=", key)]):
21+
self.set_param(key, str(self.env.ref("base.EUR").id))
22+
return res
23+
24+
@api.model_create_multi
25+
def create(self, vals_list):
26+
# OVERRIDE: recompute the multicompany reporting currency if needed
27+
params = super().create(vals_list)
28+
if params._check_multicompany_reporting_currency_needs_update():
29+
self._update_multicompany_reporting_currency()
30+
return params
31+
32+
def write(self, vals):
33+
# OVERRIDE: recompute the multicompany reporting currency if needed
34+
res = super().write(vals)
35+
needs_update = self._check_multicompany_reporting_currency_needs_update()
36+
if {"key", "value"}.intersection(vals) and needs_update:
37+
self._update_multicompany_reporting_currency()
38+
return res
39+
40+
def unlink(self):
41+
# OVERRIDE: recompute the multicompany reporting currency if needed
42+
needs_update = self._check_multicompany_reporting_currency_needs_update()
43+
res = super().unlink()
44+
if needs_update:
45+
self._update_multicompany_reporting_currency()
46+
return res
47+
48+
def _check_multicompany_reporting_currency_needs_update(self) -> bool:
49+
return self._get_multicompany_reporting_currency_key() in self.mapped("key")
50+
51+
@api.model
52+
def _update_multicompany_reporting_currency(self):
53+
mixin = self.env["multicompany.reporting.currency.mixin"]
54+
mixin._update_multicompany_reporting_currency()
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
# Copyright 2026 Camptocamp SA
2+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html)
3+
4+
from logging import getLogger
5+
6+
from odoo import api, fields, models
7+
from odoo.orm.domains import Domain
8+
from odoo.tools.misc import OrderedSet
9+
10+
_logger = getLogger(__name__)
11+
12+
13+
class MulticompanyReportingCurrencyMixin(models.AbstractModel):
14+
"""Abstract mixin for models that use multicompany reporting currency"""
15+
16+
_name = "multicompany.reporting.currency.mixin"
17+
_description = "Multicompany Reporting Currency Mixin"
18+
19+
multicompany_reporting_currency_id = fields.Many2one(
20+
"res.currency",
21+
default=lambda self: self._get_default_multicompany_reporting_currency_id(),
22+
readonly=True,
23+
)
24+
25+
@api.model
26+
def _get_default_multicompany_reporting_currency_id(self):
27+
# Default to the sys param multicompany reporting currency value
28+
return self._get_multicompany_reporting_currency_from_sys_param()
29+
30+
@api.model
31+
def _get_multicompany_reporting_currency_from_sys_param(self):
32+
"""Retrieves the currently configured multicompany reporting currency
33+
34+
Hook method, can be overridden by inheriting models
35+
"""
36+
currency = self.env["res.currency"]
37+
38+
# We try to retrieve the multicompany reporting currency from the system params,
39+
# but ``get_param(key)`` will return either ``None`` or a ``str`` object; since
40+
# we cannot be 100% sure we'll be able to convert it to a ``res.currency``
41+
# record ID, we use the user's environmental company currency as fallback
42+
key = "base_multicompany_reporting_currency.multicompany_reporting_currency"
43+
if value := self.env["ir.config_parameter"].sudo().get_param(key, default=""):
44+
try:
45+
currency = currency.browse(int(value)).exists()
46+
except ValueError: # pylint: disable=except-pass
47+
pass
48+
if not currency:
49+
currency = self.env.company.currency_id
50+
_logger.warning(
51+
"Could not get multicompany reporting currency from system"
52+
f" parameters, using user's company currency '{currency.name}'"
53+
)
54+
return currency
55+
56+
@api.model
57+
def _update_multicompany_reporting_currency(self):
58+
"""Updates the multicompany reporting currency on all inheriting models"""
59+
for model in self._get_multicompany_reporting_currency_inheriting_models():
60+
# We use the sudo-ed model because this is an automation, and we
61+
# cannot predict whether the current user has read/write access
62+
# on all inheriting models
63+
model = model.sudo()
64+
ctx = model._get_multicompany_reporting_currency_ctx_for_records_update()
65+
model = model.with_context(ctx) # pylint: disable=context-overridden
66+
dom = model._get_multicompany_reporting_currency_domain_for_records_update()
67+
recs = model.search(dom)
68+
vals = model._get_multicompany_reporting_currency_vals_for_records_update()
69+
if recs and vals:
70+
recs.write(vals)
71+
72+
@api.model
73+
def _get_multicompany_reporting_currency_inheriting_models(self):
74+
"""Retrieves an ordered set of models that inherit from this mixin
75+
76+
Hook method, can be overridden by inheriting models
77+
"""
78+
inheriting_models: OrderedSet[models.BaseModel] = OrderedSet()
79+
80+
def _add_models_recursively(model: models.BaseModel):
81+
for model_name in model._inherit_children:
82+
model = self.env.get(model_name)
83+
if model is not None and model not in inheriting_models:
84+
inheriting_models.add(model)
85+
_add_models_recursively(model)
86+
87+
# NB: ``multicompany.reporting.currency.mixin`` is excluded from the end result
88+
_add_models_recursively(self.env["multicompany.reporting.currency.mixin"])
89+
return inheriting_models
90+
91+
@api.model
92+
def _get_multicompany_reporting_currency_ctx_for_records_update(self):
93+
"""Prepares a basic context to search/update records
94+
95+
Hook method, can be overridden by inheriting models
96+
"""
97+
# By default, search and update archived records too
98+
return dict(self.env.context, active_test=False)
99+
100+
@api.model
101+
def _get_multicompany_reporting_currency_domain_for_records_update(self):
102+
"""Prepares a basic domain to search records to update
103+
104+
Hook method, can be overridden by inheriting models
105+
"""
106+
currency = self._get_multicompany_reporting_currency_from_sys_param()
107+
return Domain([("multicompany_reporting_currency_id", "!=", currency.id)])
108+
109+
@api.model
110+
def _get_multicompany_reporting_currency_vals_for_records_update(self):
111+
"""Prepares basic record values for the update
112+
113+
Hook method, can be overridden by inheriting models
114+
"""
115+
currency = self._get_multicompany_reporting_currency_from_sys_param()
116+
return {"multicompany_reporting_currency_id": currency.id}
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1-
- Maksym Yankin \<<maksym.yankin@camptocamp.com>\>
1+
- \[Camptocamp SA\](<https://www.camptocamp.com>):
2+
- Maksym Yankin \<<maksym.yankin@camptocamp.com>\>
3+
- Silvio Gregorini \<<silvio.gregorini@camptocamp.com>\>
24
- \[APSL-Nagarro\](<https://apsl.tech>):
35
- Antoni Marroig \<<amarroig@apsl.net>\>
Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,26 @@
11
In Odoo standard, when it comes to reporting in a multicompany and
2-
multicurrency environment, it should be done on the invoices. (Cf Fabien
3-
Pinckaers tweet:
4-
<https://twitter.com/fpodoo/status/1511831215673913344>) Nonetheless,
5-
some companies do not use the Invoicing or Accounting app in Odoo. For
6-
example, when using only CRM and Sales. With this module, we introduce
2+
multicurrency environment, it should be done on the invoices.
3+
(Cf Fabien Pinckaers tweet: <https://twitter.com/fpodoo/status/1511831215673913344>)
4+
5+
Nonetheless, some companies do not use the Invoicing or Accounting app in Odoo.
6+
For example, when using only CRM and Sales. With this module, we introduce
77
the concept of currency for reporting to be set in General Settings.
88
This way we can reuse the idea behind
99
<https://github.com/OCA/sale-workflow/tree/10.0/sale_company_currency>,
1010
but with a predefined currency.
1111

12-
This Module adds a setting in General Settings to set multicompany
13-
reporting currency which be applied to all companies. Multicompany
14-
reporting currency field will be used in other dependent modules to
15-
compare amounts in different companies and documents. NB: This module
16-
does not provide any feature itself. You should install
17-
sale_multicompany_reporting_currency from
12+
This module adds:
13+
- a setting in General Settings to set multicompany reporting currency which be applied
14+
to all companies
15+
- a system parameter to store the chosen multicompany reporting currency DB-wide
16+
- a mixin model to inherit for handling all basic operations - eg: automatically update
17+
the multicompany reporting currency on a model's records when the settings change
18+
19+
Multicompany reporting currency field will be used in other dependent modules to
20+
compare amounts in different companies and documents.
21+
22+
NB: This module does not provide any feature for specific apps.
23+
You should install ``sale_multicompany_reporting_currency`` from
1824
<https://github.com/OCA/sale-reporting> or
19-
crm_multicompany_reporting_currency from <https://github.com/OCA/crm> to
20-
have additional Total (Multicompany Reporting Currency) field.
25+
``crm_multicompany_reporting_currency`` from <https://github.com/OCA/crm> to
26+
have additional Total (Multicompany Reporting Currency) fields on specific apps.

base_multicompany_reporting_currency/static/description/index.html

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -377,22 +377,31 @@ <h1>Base Multicompany Reporting Currency</h1>
377377
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/license-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/sale-reporting/tree/19.0/base_multicompany_reporting_currency"><img alt="OCA/sale-reporting" src="https://img.shields.io/badge/github-OCA%2Fsale--reporting-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/sale-reporting-19-0/sale-reporting-19-0-base_multicompany_reporting_currency"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/sale-reporting&amp;target_branch=19.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
378378
<p>In Odoo standard, when it comes to reporting in a multicompany and
379379
multicurrency environment, it should be done on the invoices. (Cf Fabien
380-
Pinckaers tweet: <a class="reference external" href="https://twitter.com/fpodoo/status/1511831215673913344">https://twitter.com/fpodoo/status/1511831215673913344</a>)
381-
Nonetheless, some companies do not use the Invoicing or Accounting app
380+
Pinckaers tweet: <a class="reference external" href="https://twitter.com/fpodoo/status/1511831215673913344">https://twitter.com/fpodoo/status/1511831215673913344</a>)</p>
381+
<p>Nonetheless, some companies do not use the Invoicing or Accounting app
382382
in Odoo. For example, when using only CRM and Sales. With this module,
383383
we introduce the concept of currency for reporting to be set in General
384384
Settings. This way we can reuse the idea behind
385385
<a class="reference external" href="https://github.com/OCA/sale-workflow/tree/10.0/sale_company_currency">https://github.com/OCA/sale-workflow/tree/10.0/sale_company_currency</a>,
386386
but with a predefined currency.</p>
387-
<p>This Module adds a setting in General Settings to set multicompany
388-
reporting currency which be applied to all companies. Multicompany
389-
reporting currency field will be used in other dependent modules to
390-
compare amounts in different companies and documents. NB: This module
391-
does not provide any feature itself. You should install
392-
sale_multicompany_reporting_currency from
387+
<p>This module adds:</p>
388+
<ul class="simple">
389+
<li>a setting in General Settings to set multicompany reporting currency
390+
which be applied to all companies</li>
391+
<li>a system parameter to store the chosen multicompany reporting
392+
currency DB-wide</li>
393+
<li>a mixin model to inherit for handling all basic operations - eg:
394+
automatically update the multicompany reporting currency on a model’s
395+
records when the settings change</li>
396+
</ul>
397+
<p>Multicompany reporting currency field will be used in other dependent
398+
modules to compare amounts in different companies and documents.</p>
399+
<p>NB: This module does not provide any feature for specific apps. You
400+
should install <tt class="docutils literal">sale_multicompany_reporting_currency</tt> from
393401
<a class="reference external" href="https://github.com/OCA/sale-reporting">https://github.com/OCA/sale-reporting</a> or
394-
crm_multicompany_reporting_currency from <a class="reference external" href="https://github.com/OCA/crm">https://github.com/OCA/crm</a> to
395-
have additional Total (Multicompany Reporting Currency) field.</p>
402+
<tt class="docutils literal">crm_multicompany_reporting_currency</tt> from <a class="reference external" href="https://github.com/OCA/crm">https://github.com/OCA/crm</a>
403+
to have additional Total (Multicompany Reporting Currency) fields on
404+
specific apps.</p>
396405
<p><strong>Table of contents</strong></p>
397406
<div class="contents local topic" id="contents">
398407
<ul class="simple">
@@ -418,13 +427,17 @@ <h2><a class="toc-backref" href="#toc-entry-2">Credits</a></h2>
418427
<div class="section" id="authors">
419428
<h3><a class="toc-backref" href="#toc-entry-3">Authors</a></h3>
420429
<ul class="simple">
421-
<li>Camptocamp SA</li>
430+
<li>Camptocamp</li>
422431
</ul>
423432
</div>
424433
<div class="section" id="contributors">
425434
<h3><a class="toc-backref" href="#toc-entry-4">Contributors</a></h3>
426435
<ul class="simple">
436+
<li>[Camptocamp SA](<a class="reference external" href="https://www.camptocamp.com">https://www.camptocamp.com</a>):<ul>
427437
<li>Maksym Yankin &lt;<a class="reference external" href="mailto:maksym.yankin&#64;camptocamp.com">maksym.yankin&#64;camptocamp.com</a>&gt;</li>
438+
<li>Silvio Gregorini &lt;<a class="reference external" href="mailto:silvio.gregorini&#64;camptocamp.com">silvio.gregorini&#64;camptocamp.com</a>&gt;</li>
439+
</ul>
440+
</li>
428441
<li>[APSL-Nagarro](<a class="reference external" href="https://apsl.tech">https://apsl.tech</a>):<ul>
429442
<li>Antoni Marroig &lt;<a class="reference external" href="mailto:amarroig&#64;apsl.net">amarroig&#64;apsl.net</a>&gt;</li>
430443
</ul>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import test_base_multicompany_reporting_currency

0 commit comments

Comments
 (0)