[REF] base: set USD as default currency for the main company

There are three rationales behind this change to set USD as default
currency and to enable it in the demo data, from the beginning.
With a demo database, before this revision:
1. On runbot, with all modules installed, it's already USD the default
   company currency. It's only when you install a module not depending
   on account that it's EUR the company currency by default (e.g. CRM)
2. in the base demo data,
   the company is set in the United States but with the currency EUR,
3. before installing account, the company currency is EUR,
   after installing account, the company currency is USD,
   this is due to the fact as the company is in the United States,
   the US Chart Of Account is installed, switching the company currency
   to USD.
4. when you install a demo database with a module not depending on
   account, you are left with a database without any active currency,
   and the monetary fields therefore do not show any currency.
   For instance, install only CRM with demo,
   you have no currency symbol before or after the expected revenue,
   which is not the best user friendly experience.
   On runbot you do not feel it because all modules are installed,
   therefore with account installed, which activated the USD currency.

Additional weird thing with point 2.:
- Unit tests in modules not dependent on account with the
  post-install tag had to handle this sudden change of currency change
  before and after installing account.
  For instance, when running their unit tests with only their module,
  but not account, the company currency is EUR,
  but when executing the same unit test with all modules installed,
  the company currency is USD.
  The unit tests had to handle this sudden change within the unit test,
  for instance by setting a 1.0 rate for their own company currency,
  which shouldn't be the case: the rate of your own currency should
  always be 1.0.

closes odoo/odoo#107113

Related: odoo/enterprise#34613
Signed-off-by: Denis Ledoux (dle) <dle@odoo.com>
This commit is contained in:
Denis Ledoux
2022-12-13 11:47:49 +01:00
parent 96753cc371
commit 3752b3166e
15 changed files with 43 additions and 57 deletions
@@ -25,6 +25,8 @@ class TestSEPAQRCode(AccountTestInvoicingCommon):
'partner_id': cls.company_data['company'].partner_id.id,
})
cls.env.ref('base.EUR').active = True
cls.sepa_qr_invoice = cls.env['account.move'].create({
'move_type': 'out_invoice',
'partner_id': cls.partner_a.id,
+2 -2
View File
@@ -246,6 +246,8 @@ class TestCRMLead(TestCrmCommon):
@users('user_sales_manager')
def test_crm_lead_currency_sync(self):
self.company_main.currency_id = self.env.ref('base.EUR')
lead = self.env['crm.lead'].create({
'name': 'Lead 1',
'company_id': self.company_main.id
@@ -255,8 +257,6 @@ class TestCRMLead(TestCrmCommon):
self.company_main.currency_id = self.env.ref('base.CHF')
lead.with_company(self.company_main).update({'company_id': False})
self.assertEqual(lead.company_currency, self.env.ref('base.CHF'))
#set back original currency
self.company_main.currency_id = self.env.ref('base.EUR')
@users('user_sales_manager')
def test_crm_lead_date_closed(self):
@@ -272,6 +272,8 @@ class TestDeliveryCost(common.TransactionCase):
self.normal_delivery.product_id.taxes_id = tax_price_include
# Create sales order
# Required to see `pricelist_id` in the view
self.env.user.groups_id += self.env.ref('product.group_product_pricelist')
order_form = Form(self.env['sale.order'].with_context(tracking_disable=True))
order_form.partner_id = self.partner_18
order_form.pricelist_id = self.pricelist
-3
View File
@@ -26,9 +26,6 @@
'wizards/payment_link_wizard_views.xml',
'wizards/payment_onboarding_views.xml',
],
'demo': [
'data/payment_demo.xml',
],
'assets': {
'web.assets_frontend': [
'payment/static/src/scss/portal_payment.scss',
-7
View File
@@ -1,7 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<odoo>
<!-- Enable the EUR currency since it's the currency of the company. -->
<function model="res.currency" name="action_unarchive" eval="[[ref('base.EUR')]]"/>
</odoo>
@@ -16,13 +16,6 @@ class TestProductPricelist(ProductCommon):
def setUpClass(cls):
super().setUpClass()
# Required for some of the tests below
# Breaks if run after account installation (and with demo data)
# as generic chart of accounts changes company currency to USD
# therefore the test must stay at_install until adapted to work with USD
# or according to current currency.
cls._use_currency('EUR')
cls.category_5_id = cls.env['product.category'].create({
'name': 'Office Furniture',
'parent_id': cls.product_category.id
-9
View File
@@ -1,15 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo noupdate="1">
<!-- Enable EUR currency since it's the currency on the company, pricelist and Sale Orders
If the currency is not enabled, you cannot pay the demo SO's with a payment link bc the currency
is disabled.
-->
<function model="res.currency" name="action_unarchive">
<value model="res.currency" search="[('id', '=', obj().env.ref('product.list0').currency_id.id), ('active', '=', False)]"/>
</function>
<!-- We want to activate pay and sign by default for easier demoing. -->
<record id="base.main_company" model="res.company">
<field name="portal_confirmation_pay" eval="True"/>
+4 -3
View File
@@ -219,8 +219,8 @@ class TestSalePrices(SaleCommon):
})
self.env['res.currency.rate'].create({
'name': fields.Date.today(),
'rate': 1.0,
'currency_id': self.env.company.currency_id.id,
'rate': 2.0,
'currency_id': other_currency.id,
'company_id': self.env.company.id,
})
order_in_other_currency = self.env['sale.order'].create({
@@ -234,7 +234,8 @@ class TestSalePrices(SaleCommon):
}),
]
})
self.assertEqual(order_in_other_currency.amount_total, 480.0)
# 20.0 (product price) * 24.0 (2 dozens) * 2.0 (price rate USD -> EUR)
self.assertEqual(order_in_other_currency.amount_total, 960.0)
def test_negative_discounts(self):
"""aka surcharges"""
@@ -133,6 +133,11 @@ class TestProductConfiguratorUi(HttpCase, TestProductConfiguratorCommon):
Also testing B2C setting: no impact on the backend configurator.
"""
# Required to see `pricelist_id` in the view
self.salesman.write({
'groups_id': [(4, self.env.ref('product.group_product_pricelist').id)],
})
# Add a 15% tax on desk
tax = self.env['account.tax'].create({'name': "Test tax", 'amount': 15})
self.product_product_custo_desk.taxes_id = tax
+1
View File
@@ -78,6 +78,7 @@ The kernel of Odoo, needed for all installation.
'demo': [
'data/res_users_demo.xml',
'data/res_partner_bank_demo.xml',
'data/res_currency_demo.xml',
'data/res_currency_rate_demo.xml',
'data/res_bank_demo.xml',
'data/res_partner_demo.xml',
+2 -2
View File
@@ -119,8 +119,8 @@ CREATE TABLE res_partner (
---------------------------------
-- Default data
---------------------------------
insert into res_currency (id, name, symbol) VALUES (1, 'EUR', '€');
insert into ir_model_data (name, module, model, noupdate, res_id) VALUES ('EUR', 'base', 'res.currency', true, 1);
insert into res_currency (id, name, symbol) VALUES (1, 'USD', '$');
insert into ir_model_data (name, module, model, noupdate, res_id) VALUES ('USD', 'base', 'res.currency', true, 1);
select setval('res_currency_id_seq', 1);
insert into res_company (id, name, partner_id, currency_id, create_date) VALUES (1, 'My Company', 1, 1, now() at time zone 'UTC');
+1 -1
View File
@@ -4,7 +4,7 @@
<record id="main_company" model="res.company">
<field name="name">My Company</field>
<field name="partner_id" ref="main_partner"/>
<field name="currency_id" ref="base.EUR"/>
<field name="currency_id" ref="base.USD"/>
<field name="favicon" model="res.company" eval="obj()._get_default_favicon(original=True)"/>
</record>
</data>
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data noupdate="1">
<!--
In demo only, enable the USD currency.
The rationale is that, without demo, you shouldn't enable any currency by default,
so you do not land in a multi-currency database by default.
e.g. if USD was enabled by default even without demo, and you install the accounting for Belgium,
installing the Belgian Chart Of Account, it would enable the EUR currency,
therefore leaving you with the USD and EUR currency enabled,
and therefore in a multi-currency environment.
But, with demo, you need to enable the currency used by the company by default,
so the monetary fields display the currency symbol even when invoicing (account) is not installed.
e.g. install a demo database with just CRM, you want the $ to appear next to the expected revenue field.
-->
<record id="USD" model="res.currency">
<field name="active" eval="True"/>
</record>
</data>
</odoo>
@@ -1,19 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data noupdate="1">
<!-- The Following currency rates are considered as on 1st Jan,2010 against EUR. -->
<record forcecreate="0" id="rateUSD" model="res.currency.rate">
<field name="rate">1.2834</field>
<field name="rate">1.0</field>
<field name="currency_id" ref="USD"/>
<field name="name">2010-01-01</field>
</record>
<record id="rateUSDbis" model="res.currency.rate">
<field name="rate">1.5289</field>
<field name="currency_id" ref="USD"/>
<field eval="time.strftime('%Y-01-01')" name="name"/>
</record>
<record forcecreate="0" id="rateVEF" model="res.currency.rate">
<field name="rate">5.864</field>
<field name="currency_id" ref="VEF"/>
@@ -748,7 +741,7 @@
<record forcecreate="0" id="rateEUR" model="res.currency.rate">
<field name="currency_id" ref="EUR" />
<field name="name">2010-01-01</field>
<field name="rate">1.0</field>
<field name="rate">1.2834</field>
</record>
<record forcecreate="0" id="rateVUV" model="res.currency.rate">
-14
View File
@@ -22,9 +22,6 @@ class BaseCommon(TransactionCase):
def setUpClass(cls):
super().setUpClass()
# Enforce the use of USD as main currency unless modified in inherited class(es)
cls._use_currency('USD')
# Mail logic won't be tested by default in other modules.
# Mail API overrides should be tested with dedicated tests on purpose
# Hack to use with_context and avoid manual context dict modification
@@ -34,17 +31,6 @@ class BaseCommon(TransactionCase):
'name': 'Test Partner',
})
@classmethod
def _use_currency(cls, currency_code):
# Enforce constant currency
currency = cls._enable_currency(currency_code)
if not cls.env.company.currency_id == currency:
cls.env.transaction.cache.set(cls.env.company, type(cls.env.company).currency_id, currency.id, dirty=True)
# this is equivalent to cls.env.company.currency_id = currency but without triggering buisness code checks.
# The value is added in cache, and the cache value is set as dirty so that that
# the value will be written to the database on next flush.
# this was needed because some journal entries may exist when running tests, especially l10n demo data.
@classmethod
def _enable_currency(cls, currency_code):
currency = cls.env['res.currency'].with_context(active_test=False).search(