From 7ffe049ad3095f61835e30fb369c975c24341413 Mon Sep 17 00:00:00 2001 From: Pieter Paulussen Date: Thu, 5 Mar 2020 09:23:43 +0100 Subject: [PATCH] [REF] 12.0 account_payment_order code style update --- .../tests/test_payment_order_inbound.py | 54 ++++++++--------- .../tests/test_payment_order_outbound.py | 59 ++++++++++--------- 2 files changed, 58 insertions(+), 55 deletions(-) diff --git a/account_payment_order/tests/test_payment_order_inbound.py b/account_payment_order/tests/test_payment_order_inbound.py index dd061afb4..727f5a8e1 100644 --- a/account_payment_order/tests/test_payment_order_inbound.py +++ b/account_payment_order/tests/test_payment_order_inbound.py @@ -11,61 +11,61 @@ from datetime import date, timedelta class TestPaymentOrderInboundBase(SavepointCase): @classmethod def setUpClass(cls): - self = cls - super().setUpClass() - self.inbound_mode = self.env.ref( + super(TestPaymentOrderInboundBase, cls).setUpClass() + cls.inbound_mode = cls.env.ref( 'account_payment_mode.payment_mode_inbound_dd1' ) - self.invoice_line_account = self.env['account.account'].search( - [('user_type_id', '=', self.env.ref( + cls.invoice_line_account = cls.env['account.account'].search( + [('user_type_id', '=', cls.env.ref( 'account.data_account_type_revenue').id)], limit=1).id - self.journal = self.env['account.journal'].search( + cls.journal = cls.env['account.journal'].search( [('type', '=', 'bank'), - '|', ('company_id', '=', self.env.user.company_id.id), + '|', ('company_id', '=', cls.env.user.company_id.id), ('company_id', '=', False)], limit=1 ) - self.inbound_mode.variable_journal_ids = self.journal + cls.inbound_mode.variable_journal_ids = cls.journal # Make sure no others orders are present - self.domain = [ + cls.domain = [ ('state', '=', 'draft'), ('payment_type', '=', 'inbound'), ] - self.payment_order_obj = self.env['account.payment.order'] - self.payment_order_obj.search(self.domain).unlink() + cls.payment_order_obj = cls.env['account.payment.order'] + cls.payment_order_obj.search(cls.domain).unlink() # Create payment order - self.inbound_order = self.env['account.payment.order'].create({ + cls.inbound_order = cls.env['account.payment.order'].create({ 'payment_type': 'inbound', - 'payment_mode_id': self.inbound_mode.id, - 'journal_id': self.journal.id, + 'payment_mode_id': cls.inbound_mode.id, + 'journal_id': cls.journal.id, }) # Open invoice - self.invoice = self._create_customer_invoice(self) - self.invoice.action_invoice_open() + cls.invoice = cls._create_customer_invoice() + cls.invoice.action_invoice_open() # Add to payment order using the wizard - self.env['account.invoice.payment.line.multi'].with_context( + cls.env['account.invoice.payment.line.multi'].with_context( active_model='account.invoice', - active_ids=self.invoice.ids + active_ids=cls.invoice.ids ).create({}).run() - def _create_customer_invoice(self): - invoice_account = self.env['account.account'].search( - [('user_type_id', '=', self.env.ref( + @classmethod + def _create_customer_invoice(cls): + invoice_account = cls.env['account.account'].search( + [('user_type_id', '=', cls.env.ref( 'account.data_account_type_receivable').id)], limit=1).id - invoice = self.env['account.invoice'].create({ - 'partner_id': self.env.ref('base.res_partner_4').id, + invoice = cls.env['account.invoice'].create({ + 'partner_id': cls.env.ref('base.res_partner_4').id, 'account_id': invoice_account, 'type': 'out_invoice', - 'payment_mode_id': self.inbound_mode.id + 'payment_mode_id': cls.inbound_mode.id }) - self.env['account.invoice.line'].create({ - 'product_id': self.env.ref('product.product_product_4').id, + cls.env['account.invoice.line'].create({ + 'product_id': cls.env.ref('product.product_product_4').id, 'quantity': 1.0, 'price_unit': 100.0, 'invoice_id': invoice.id, 'name': 'product that cost 100', - 'account_id': self.invoice_line_account, + 'account_id': cls.invoice_line_account, }) return invoice diff --git a/account_payment_order/tests/test_payment_order_outbound.py b/account_payment_order/tests/test_payment_order_outbound.py index 8e50c1ec9..1557e555e 100644 --- a/account_payment_order/tests/test_payment_order_outbound.py +++ b/account_payment_order/tests/test_payment_order_outbound.py @@ -4,63 +4,66 @@ from datetime import date, datetime, timedelta from odoo.exceptions import UserError, ValidationError -from odoo.tests.common import TransactionCase +from odoo.tests.common import SavepointCase -class TestPaymentOrderOutbound(TransactionCase): +class TestPaymentOrderOutbound(SavepointCase): - def setUp(self): - super(TestPaymentOrderOutbound, self).setUp() - self.invoice_line_account = self.env['account.account'].search( - [('user_type_id', '=', self.env.ref( + @classmethod + def setUpClass(cls): + super(TestPaymentOrderOutbound, cls).setUpClass() + cls.company = cls.env.user.company_id + cls.invoice_line_account = cls.env['account.account'].search( + [('user_type_id', '=', cls.env.ref( 'account.data_account_type_expenses').id)], limit=1).id - self.invoice = self._create_supplier_invoice() - self.invoice_02 = self._create_supplier_invoice() - self.mode = self.env.ref( + cls.invoice = cls._create_supplier_invoice() + cls.invoice_02 = cls._create_supplier_invoice() + cls.mode = cls.env.ref( 'account_payment_mode.payment_mode_outbound_ct1') - self.mode.default_journal_ids = self.env['account.journal'].search([ + cls.mode.default_journal_ids = cls.env['account.journal'].search([ ('type', 'in', ('purchase', 'purchase_refund')), - ('company_id', '=', self.env.user.company_id.id) + ('company_id', '=', cls.env.user.company_id.id) ]) - self.creation_mode = self.env.ref( + cls.creation_mode = cls.env.ref( 'account_payment_mode.payment_mode_outbound_dd1') - self.creation_mode.default_journal_ids = ( - self.env['account.journal'].search([ + cls.creation_mode.default_journal_ids = ( + cls.env['account.journal'].search([ ('type', 'in', ('sale', 'sale_refund')), - ('company_id', '=', self.env.user.company_id.id) + ('company_id', '=', cls.env.user.company_id.id) ])) - self.bank_journal = self.env['account.journal'].search( + cls.bank_journal = cls.env['account.journal'].search( [('type', '=', 'bank'), - '|', ('company_id', '=', self.env.user.company_id.id), + '|', ('company_id', '=', cls.env.user.company_id.id), ('company_id', '=', False)], limit=1) # Make sure no other payment orders are in the DB - self.domain = [ + cls.domain = [ ('state', '=', 'draft'), ('payment_type', '=', 'outbound'), ] - self.env['account.payment.order'].search(self.domain).unlink() + cls.env['account.payment.order'].search(cls.domain).unlink() - def _create_supplier_invoice(self): - invoice_account = self.env['account.account'].search( - [('user_type_id', '=', self.env.ref( + @classmethod + def _create_supplier_invoice(cls): + invoice_account = cls.env['account.account'].search( + [('user_type_id', '=', cls.env.ref( 'account.data_account_type_payable').id)], limit=1).id - invoice = self.env['account.invoice'].create({ - 'partner_id': self.env.ref('base.res_partner_4').id, + invoice = cls.env['account.invoice'].create({ + 'partner_id': cls.env.ref('base.res_partner_4').id, 'account_id': invoice_account, 'type': 'in_invoice', - 'payment_mode_id': self.env.ref( + 'payment_mode_id': cls.env.ref( 'account_payment_mode.payment_mode_outbound_ct1').id }) - self.env['account.invoice.line'].create({ - 'product_id': self.env.ref('product.product_product_4').id, + cls.env['account.invoice.line'].create({ + 'product_id': cls.env.ref('product.product_product_4').id, 'quantity': 1.0, 'price_unit': 100.0, 'invoice_id': invoice.id, 'name': 'product that cost 100', - 'account_id': self.invoice_line_account, + 'account_id': cls.invoice_line_account, }) return invoice