From 3752b3166ec6bbb5c6ea55f96bb521381bf2b2d9 Mon Sep 17 00:00:00 2001 From: Denis Ledoux Date: Thu, 1 Dec 2022 15:18:55 +0000 Subject: [PATCH] [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) --- .../tests/test_sepa_qr.py | 2 ++ addons/crm/tests/test_crm_lead.py | 4 ++-- addons/delivery/tests/test_delivery_cost.py | 2 ++ addons/payment/__manifest__.py | 3 --- addons/payment/data/payment_demo.xml | 7 ------ .../product/tests/test_product_pricelist.py | 7 ------ addons/sale/data/sale_demo.xml | 9 -------- addons/sale/tests/test_sale_prices.py | 7 +++--- .../tests/test_sale_product_configurator.py | 5 +++++ odoo/addons/base/__manifest__.py | 1 + odoo/addons/base/data/base_data.sql | 4 ++-- odoo/addons/base/data/res_company_data.xml | 2 +- odoo/addons/base/data/res_currency_demo.xml | 22 +++++++++++++++++++ .../base/data/res_currency_rate_demo.xml | 11 ++-------- odoo/addons/base/tests/common.py | 14 ------------ 15 files changed, 43 insertions(+), 57 deletions(-) delete mode 100644 addons/payment/data/payment_demo.xml create mode 100644 odoo/addons/base/data/res_currency_demo.xml diff --git a/addons/account_qr_code_sepa/tests/test_sepa_qr.py b/addons/account_qr_code_sepa/tests/test_sepa_qr.py index 785361500c1..1613e60566a 100644 --- a/addons/account_qr_code_sepa/tests/test_sepa_qr.py +++ b/addons/account_qr_code_sepa/tests/test_sepa_qr.py @@ -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, diff --git a/addons/crm/tests/test_crm_lead.py b/addons/crm/tests/test_crm_lead.py index f4e32a50d90..e40059c4ead 100644 --- a/addons/crm/tests/test_crm_lead.py +++ b/addons/crm/tests/test_crm_lead.py @@ -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): diff --git a/addons/delivery/tests/test_delivery_cost.py b/addons/delivery/tests/test_delivery_cost.py index a242560df24..569b99cfdb2 100644 --- a/addons/delivery/tests/test_delivery_cost.py +++ b/addons/delivery/tests/test_delivery_cost.py @@ -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 diff --git a/addons/payment/__manifest__.py b/addons/payment/__manifest__.py index a8ae13a2087..0a5b174bcad 100644 --- a/addons/payment/__manifest__.py +++ b/addons/payment/__manifest__.py @@ -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', diff --git a/addons/payment/data/payment_demo.xml b/addons/payment/data/payment_demo.xml deleted file mode 100644 index 479c5fa083d..00000000000 --- a/addons/payment/data/payment_demo.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - diff --git a/addons/product/tests/test_product_pricelist.py b/addons/product/tests/test_product_pricelist.py index 2e249ee5d9c..57a0f9e84af 100644 --- a/addons/product/tests/test_product_pricelist.py +++ b/addons/product/tests/test_product_pricelist.py @@ -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 diff --git a/addons/sale/data/sale_demo.xml b/addons/sale/data/sale_demo.xml index 3f5d78eac42..79ce4a16484 100644 --- a/addons/sale/data/sale_demo.xml +++ b/addons/sale/data/sale_demo.xml @@ -1,15 +1,6 @@ - - - - - diff --git a/addons/sale/tests/test_sale_prices.py b/addons/sale/tests/test_sale_prices.py index a0ae71bf0d0..d0e0cdb2152 100644 --- a/addons/sale/tests/test_sale_prices.py +++ b/addons/sale/tests/test_sale_prices.py @@ -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""" diff --git a/addons/test_sale_product_configurators/tests/test_sale_product_configurator.py b/addons/test_sale_product_configurators/tests/test_sale_product_configurator.py index 87d6f5ee885..9d1d26259f3 100644 --- a/addons/test_sale_product_configurators/tests/test_sale_product_configurator.py +++ b/addons/test_sale_product_configurators/tests/test_sale_product_configurator.py @@ -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 diff --git a/odoo/addons/base/__manifest__.py b/odoo/addons/base/__manifest__.py index c87d083e88a..cd1d041658b 100644 --- a/odoo/addons/base/__manifest__.py +++ b/odoo/addons/base/__manifest__.py @@ -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', diff --git a/odoo/addons/base/data/base_data.sql b/odoo/addons/base/data/base_data.sql index 419e3891093..25d0cc7443c 100644 --- a/odoo/addons/base/data/base_data.sql +++ b/odoo/addons/base/data/base_data.sql @@ -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'); diff --git a/odoo/addons/base/data/res_company_data.xml b/odoo/addons/base/data/res_company_data.xml index d794d70464c..b37f3d22b45 100644 --- a/odoo/addons/base/data/res_company_data.xml +++ b/odoo/addons/base/data/res_company_data.xml @@ -4,7 +4,7 @@ My Company - + diff --git a/odoo/addons/base/data/res_currency_demo.xml b/odoo/addons/base/data/res_currency_demo.xml new file mode 100644 index 00000000000..e7ffa3d207d --- /dev/null +++ b/odoo/addons/base/data/res_currency_demo.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + diff --git a/odoo/addons/base/data/res_currency_rate_demo.xml b/odoo/addons/base/data/res_currency_rate_demo.xml index 7ceb095b95b..d0b54932972 100644 --- a/odoo/addons/base/data/res_currency_rate_demo.xml +++ b/odoo/addons/base/data/res_currency_rate_demo.xml @@ -1,19 +1,12 @@ - - 1.2834 + 1.0 2010-01-01 - - 1.5289 - - - - 5.864 @@ -748,7 +741,7 @@ 2010-01-01 - 1.0 + 1.2834 diff --git a/odoo/addons/base/tests/common.py b/odoo/addons/base/tests/common.py index 3f85b96944a..c324261b49a 100644 --- a/odoo/addons/base/tests/common.py +++ b/odoo/addons/base/tests/common.py @@ -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(