From 2237e5c3e8aba45481dc639b67979683dbadc9db Mon Sep 17 00:00:00 2001 From: David Ramia Date: Wed, 6 Jul 2022 14:00:22 +0200 Subject: [PATCH 1/3] [FIX] account_banking_pain_base, account_banking_sepa_credit_transfer, account_banking_direct_debit: Remove Environment.manage() Environment.manage() is deprecated in v 15.0 --- account_banking_pain_base/post_install.py | 7 ++-- .../post_install.py | 33 +++++++++---------- .../post_install.py | 33 +++++++++---------- 3 files changed, 35 insertions(+), 38 deletions(-) diff --git a/account_banking_pain_base/post_install.py b/account_banking_pain_base/post_install.py index a8ba7b995..2ada23094 100644 --- a/account_banking_pain_base/post_install.py +++ b/account_banking_pain_base/post_install.py @@ -6,8 +6,7 @@ from odoo import SUPERUSER_ID, api def set_default_initiating_party(cr, registry): - with api.Environment.manage(): - env = api.Environment(cr, SUPERUSER_ID, {}) - for company in env["res.company"].search([]): - company._default_initiating_party() + env = api.Environment(cr, SUPERUSER_ID, {}) + for company in env["res.company"].search([]): + company._default_initiating_party() return diff --git a/account_banking_sepa_credit_transfer/post_install.py b/account_banking_sepa_credit_transfer/post_install.py index 8cfd84b8f..fe9cf853f 100644 --- a/account_banking_sepa_credit_transfer/post_install.py +++ b/account_banking_sepa_credit_transfer/post_install.py @@ -5,21 +5,20 @@ from odoo import SUPERUSER_ID, api def update_bank_journals(cr, registry): - with api.Environment.manage(): - env = api.Environment(cr, SUPERUSER_ID, {}) - ajo = env["account.journal"] - journals = ajo.search([("type", "=", "bank")]) - sct = env.ref("account_banking_sepa_credit_transfer.sepa_credit_transfer") - if sct: - journals.write( - { - "outbound_payment_method_line_ids": [ - ( - 0, - 0, - {"payment_method_id": sct.id, "name": "SEPA Direct Credit"}, - ) - ] - } - ) + env = api.Environment(cr, SUPERUSER_ID, {}) + ajo = env["account.journal"] + journals = ajo.search([("type", "=", "bank")]) + sct = env.ref("account_banking_sepa_credit_transfer.sepa_credit_transfer") + if sct: + journals.write( + { + "outbound_payment_method_line_ids": [ + ( + 0, + 0, + {"payment_method_id": sct.id, "name": "SEPA Direct Credit"}, + ) + ] + } + ) return diff --git a/account_banking_sepa_direct_debit/post_install.py b/account_banking_sepa_direct_debit/post_install.py index 88b84dad9..663c0cabd 100644 --- a/account_banking_sepa_direct_debit/post_install.py +++ b/account_banking_sepa_direct_debit/post_install.py @@ -5,21 +5,20 @@ from odoo import SUPERUSER_ID, api def update_bank_journals(cr, registry): - with api.Environment.manage(): - env = api.Environment(cr, SUPERUSER_ID, {}) - ajo = env["account.journal"] - journals = ajo.search([("type", "=", "bank")]) - sdd = env.ref("account_banking_sepa_direct_debit.sepa_direct_debit") - if sdd: - journals.write( - { - "inbound_payment_method_line_ids": [ - ( - 0, - 0, - {"payment_method_id": sdd.id, "name": "SEPA Direct Debit"}, - ) - ] - } - ) + env = api.Environment(cr, SUPERUSER_ID, {}) + ajo = env["account.journal"] + journals = ajo.search([("type", "=", "bank")]) + sdd = env.ref("account_banking_sepa_direct_debit.sepa_direct_debit") + if sdd: + journals.write( + { + "inbound_payment_method_line_ids": [ + ( + 0, + 0, + {"payment_method_id": sdd.id, "name": "SEPA Direct Debit"}, + ) + ] + } + ) return From f3ec4a2a6f811fe020921b96804b77b96b01067b Mon Sep 17 00:00:00 2001 From: David Ramia Date: Wed, 6 Jul 2022 14:02:07 +0200 Subject: [PATCH 2/3] [FIX] account_payment_partner: Fix tests Add company permissions to the admin user to be able to create the demo data --- account_payment_partner/tests/test_account_payment_partner.py | 1 + 1 file changed, 1 insertion(+) diff --git a/account_payment_partner/tests/test_account_payment_partner.py b/account_payment_partner/tests/test_account_payment_partner.py index 0890c2c74..f1c129917 100644 --- a/account_payment_partner/tests/test_account_payment_partner.py +++ b/account_payment_partner/tests/test_account_payment_partner.py @@ -34,6 +34,7 @@ class TestAccountPaymentPartner(TransactionCase): raise ValidationError(_("No Chart of Account Template has been defined !")) old_company = cls.env.user.company_id cls.env.user.company_id = cls.company_2.id + cls.env.ref("base.user_admin").company_ids = [(4, cls.company_2.id)] cls.chart.try_loading() cls.env.user.company_id = old_company.id From 46ab40f75f13580afc0f81bb67ebb40599d77e3a Mon Sep 17 00:00:00 2001 From: David Ramia Date: Wed, 6 Jul 2022 14:02:42 +0200 Subject: [PATCH 3/3] [FIX] account_payment_order: Fix tests Some tests need to be run on post-install The bank_journal.inbound_payment_order_only field is true only if all inbound_payment_method_ids are payment_order_only True. For this we must include the "SEPA Direct Debit for customers" in test --- account_payment_order/tests/test_account_payment.py | 6 ++++++ account_payment_order/tests/test_payment_order_inbound.py | 3 +++ account_payment_order/tests/test_payment_order_outbound.py | 2 ++ 3 files changed, 11 insertions(+) diff --git a/account_payment_order/tests/test_account_payment.py b/account_payment_order/tests/test_account_payment.py index e7853ffa4..edd838472 100644 --- a/account_payment_order/tests/test_account_payment.py +++ b/account_payment_order/tests/test_account_payment.py @@ -3,10 +3,13 @@ from unittest.mock import patch +from odoo.tests import tagged + from odoo.addons.account.models.account_payment_method import AccountPaymentMethod from odoo.addons.account.tests.common import AccountTestInvoicingCommon +@tagged("-at_install", "post_install") class TestAccountPayment(AccountTestInvoicingCommon): @classmethod def setUpClass(cls, chart_template_ref=None): @@ -62,6 +65,7 @@ class TestAccountPayment(AccountTestInvoicingCommon): ) # Journals cls.manual_in = cls.env.ref("account.account_payment_method_manual_in") + cls.sepa_in = cls.env.ref("account_banking_sepa_direct_debit.sepa_direct_debit") cls.manual_out = cls.env.ref("account.account_payment_method_manual_out") cls.bank_journal = cls.company_data["default_journal_bank"] @@ -78,6 +82,7 @@ class TestAccountPayment(AccountTestInvoicingCommon): self.assertTrue(self.inbound_payment_method_01.payment_order_only) self.assertTrue(self.inbound_payment_method_02.payment_order_only) self.manual_in.payment_order_only = True + self.sepa_in.payment_order_only = True self.assertTrue(self.bank_journal.inbound_payment_order_only) def test_account_payment_02(self): @@ -145,6 +150,7 @@ class TestAccountPayment(AccountTestInvoicingCommon): self.assertTrue(self.inbound_payment_method_01.payment_order_only) self.assertTrue(self.inbound_payment_method_02.payment_order_only) self.manual_in.payment_order_only = True + self.sepa_in.payment_order_only = True self.assertTrue(self.bank_journal.inbound_payment_order_only) # check journals journals = new_account_payment._get_default_journal() diff --git a/account_payment_order/tests/test_payment_order_inbound.py b/account_payment_order/tests/test_payment_order_inbound.py index 3b1195697..1e663f129 100644 --- a/account_payment_order/tests/test_payment_order_inbound.py +++ b/account_payment_order/tests/test_payment_order_inbound.py @@ -6,11 +6,13 @@ from datetime import date, timedelta from odoo.exceptions import UserError, ValidationError +from odoo.tests import tagged from odoo.tests.common import Form from odoo.addons.account.tests.common import AccountTestInvoicingCommon +@tagged("-at_install", "post_install") class TestPaymentOrderInboundBase(AccountTestInvoicingCommon): @classmethod def setUpClass(cls, chart_template_ref=None): @@ -77,6 +79,7 @@ class TestPaymentOrderInboundBase(AccountTestInvoicingCommon): return invoice_form.save() +@tagged("-at_install", "post_install") class TestPaymentOrderInbound(TestPaymentOrderInboundBase): def test_constrains_type(self): with self.assertRaises(ValidationError): diff --git a/account_payment_order/tests/test_payment_order_outbound.py b/account_payment_order/tests/test_payment_order_outbound.py index 8a087265a..ad867f249 100644 --- a/account_payment_order/tests/test_payment_order_outbound.py +++ b/account_payment_order/tests/test_payment_order_outbound.py @@ -6,10 +6,12 @@ from datetime import date, datetime, timedelta from odoo import fields from odoo.exceptions import UserError, ValidationError +from odoo.tests import tagged from odoo.addons.account.tests.common import AccountTestInvoicingCommon +@tagged("-at_install", "post_install") class TestPaymentOrderOutbound(AccountTestInvoicingCommon): @classmethod def setUpClass(cls, chart_template_ref=None):