From a8c574b4bdc5a4cfed6f7c4ae0b093f684434d47 Mon Sep 17 00:00:00 2001 From: Pieter Paulussen Date: Thu, 5 Mar 2020 09:22:28 +0100 Subject: [PATCH] [FIX] 12.0 make account_payment_order_inbound test multicompany resilient --- account_payment_order/README.rst | 1 + .../tests/test_payment_order_inbound.py | 10 ++++---- .../tests/test_payment_order_outbound.py | 24 ++++++++++++------- 3 files changed, 21 insertions(+), 14 deletions(-) diff --git a/account_payment_order/README.rst b/account_payment_order/README.rst index 0be86c714..aa1a4de58 100644 --- a/account_payment_order/README.rst +++ b/account_payment_order/README.rst @@ -99,6 +99,7 @@ Contributors * Jose MarĂ­a Alzaga * Meyomesse Gilles * Carlos Dauden +* Pieter Paulussen Maintainers ~~~~~~~~~~~ diff --git a/account_payment_order/tests/test_payment_order_inbound.py b/account_payment_order/tests/test_payment_order_inbound.py index 45b645a0f..dd061afb4 100644 --- a/account_payment_order/tests/test_payment_order_inbound.py +++ b/account_payment_order/tests/test_payment_order_inbound.py @@ -21,7 +21,9 @@ class TestPaymentOrderInboundBase(SavepointCase): 'account.data_account_type_revenue').id)], limit=1).id self.journal = self.env['account.journal'].search( - [('type', '=', 'bank')], limit=1 + [('type', '=', 'bank'), + '|', ('company_id', '=', self.env.user.company_id.id), + ('company_id', '=', False)], limit=1 ) self.inbound_mode.variable_journal_ids = self.journal # Make sure no others orders are present @@ -85,13 +87,11 @@ class TestPaymentOrderInbound(TestPaymentOrderInboundBase): def test_creation(self): payment_order = self.inbound_order self.assertEqual(len(payment_order.ids), 1) - bank_journal = self.env['account.journal'].search( - [('type', '=', 'bank')], limit=1) # Set journal to allow cancelling entries - bank_journal.update_posted = True + self.journal.update_posted = True payment_order.write({ - 'journal_id': bank_journal.id, + 'journal_id': self.journal.id, }) self.assertEqual(len(payment_order.payment_line_ids), 1) diff --git a/account_payment_order/tests/test_payment_order_outbound.py b/account_payment_order/tests/test_payment_order_outbound.py index 713396c84..8e50c1ec9 100644 --- a/account_payment_order/tests/test_payment_order_outbound.py +++ b/account_payment_order/tests/test_payment_order_outbound.py @@ -11,9 +11,6 @@ class TestPaymentOrderOutbound(TransactionCase): def setUp(self): super(TestPaymentOrderOutbound, self).setUp() - self.journal = self.env['account.journal'].search( - [('type', '=', 'bank')], limit=1 - ) self.invoice_line_account = self.env['account.account'].search( [('user_type_id', '=', self.env.ref( 'account.data_account_type_expenses').id)], @@ -22,10 +19,21 @@ class TestPaymentOrderOutbound(TransactionCase): self.invoice_02 = self._create_supplier_invoice() self.mode = self.env.ref( 'account_payment_mode.payment_mode_outbound_ct1') + self.mode.default_journal_ids = self.env['account.journal'].search([ + ('type', 'in', ('purchase', 'purchase_refund')), + ('company_id', '=', self.env.user.company_id.id) + ]) self.creation_mode = self.env.ref( 'account_payment_mode.payment_mode_outbound_dd1') + self.creation_mode.default_journal_ids = ( + self.env['account.journal'].search([ + ('type', 'in', ('sale', 'sale_refund')), + ('company_id', '=', self.env.user.company_id.id) + ])) self.bank_journal = self.env['account.journal'].search( - [('type', '=', 'bank')], limit=1) + [('type', '=', 'bank'), + '|', ('company_id', '=', self.env.user.company_id.id), + ('company_id', '=', False)], limit=1) # Make sure no other payment orders are in the DB self.domain = [ ('state', '=', 'draft'), @@ -144,13 +152,11 @@ class TestPaymentOrderOutbound(TransactionCase): payment_order = self.env['account.payment.order'].search(self.domain) self.assertEqual(len(payment_order), 1) - bank_journal = self.env['account.journal'].search( - [('type', '=', 'bank')], limit=1) # Set journal to allow cancelling entries - bank_journal.update_posted = True + self.bank_journal.update_posted = True payment_order.write({ - 'journal_id': bank_journal.id, + 'journal_id': self.bank_journal.id, }) self.assertEqual(len(payment_order.payment_line_ids), 1) @@ -185,7 +191,7 @@ class TestPaymentOrderOutbound(TransactionCase): outbound_order = self.env['account.payment.order'].create({ 'payment_type': 'outbound', 'payment_mode_id': self.mode.id, - 'journal_id': self.journal.id, + 'journal_id': self.bank_journal.id, }) with self.assertRaises(ValidationError): outbound_order.date_scheduled = date.today() - timedelta(