22# Copyright 2021 Tecnativa - Víctor Martínez
33# License AGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
44
5- from odoo import _ , fields
5+ from odoo import Command , _ , fields
66from odoo .exceptions import UserError , ValidationError
7- from odoo .fields import Date
8- from odoo .tests import Form , TransactionCase , tagged
7+ from odoo .tests import Form , tagged
98
10- from odoo .addons .base .tests .common import DISABLED_MAIL_CONTEXT
9+ from odoo .addons .base .tests .common import BaseCommon
1110
1211
1312@tagged ("-at_install" , "post_install" )
14- class TestAccountPaymentPartner (TransactionCase ):
13+ class TestAccountPaymentPartner (BaseCommon ):
1514 @classmethod
1615 def setUpClass (cls ):
1716 super ().setUpClass ()
18- cls .env = cls .env (context = dict (cls .env .context , ** DISABLED_MAIL_CONTEXT ))
19-
2017 cls .res_users_model = cls .env ["res.users" ]
2118 cls .move_model = cls .env ["account.move" ]
2219 cls .journal_model = cls .env ["account.journal" ]
2320 cls .payment_mode_model = cls .env ["account.payment.mode" ]
2421 cls .partner_bank_model = cls .env ["res.partner.bank" ]
25-
2622 # Refs
2723 cls .company = cls .env .ref ("base.main_company" )
28-
2924 cls .company_2 = cls .env ["res.company" ].create ({"name" : "Company 2" })
3025 chart = cls .env ["account.chart.template" ]._guess_chart_template (
3126 cls .company .country_id
@@ -41,7 +36,6 @@ def setUpClass(cls):
4136 cls .manual_out = cls .env .ref ("account.account_payment_method_manual_out" )
4237 cls .manual_out .bank_account_required = True
4338 cls .manual_in = cls .env .ref ("account.account_payment_method_manual_in" )
44-
4539 cls .journal_sale = cls .env ["account.journal" ].create (
4640 {
4741 "name" : "Test Sales Journal" ,
@@ -50,7 +44,6 @@ def setUpClass(cls):
5044 "company_id" : cls .company .id ,
5145 }
5246 )
53-
5447 cls .journal_purchase = cls .env ["account.journal" ].create (
5548 {
5649 "name" : "Test Purchases Journal" ,
@@ -59,7 +52,6 @@ def setUpClass(cls):
5952 "company_id" : cls .company .id ,
6053 }
6154 )
62-
6355 cls .journal_c1 = cls .journal_model .create (
6456 {
6557 "name" : "J1" ,
@@ -69,7 +61,6 @@ def setUpClass(cls):
6961 "bank_acc_number" : "123456" ,
7062 }
7163 )
72-
7364 cls .journal_c2 = cls .journal_model .create (
7465 {
7566 "name" : "J2" ,
@@ -79,7 +70,6 @@ def setUpClass(cls):
7970 "bank_acc_number" : "552344" ,
8071 }
8172 )
82-
8373 cls .supplier_payment_mode = cls .payment_mode_model .create (
8474 {
8575 "name" : "Suppliers Bank 1" ,
@@ -91,7 +81,6 @@ def setUpClass(cls):
9181 "variable_journal_ids" : [(6 , 0 , [cls .journal_c1 .id ])],
9282 }
9383 )
94-
9584 cls .supplier_payment_mode_c2 = cls .payment_mode_model .create (
9685 {
9786 "name" : "Suppliers Bank 2" ,
@@ -102,7 +91,6 @@ def setUpClass(cls):
10291 "variable_journal_ids" : [(6 , 0 , [cls .journal_c2 .id ])],
10392 }
10493 )
105-
10694 cls .customer_payment_mode = cls .payment_mode_model .create (
10795 {
10896 "name" : "Customers to Bank 1" ,
@@ -117,7 +105,6 @@ def setUpClass(cls):
117105 cls .supplier_payment_mode .write (
118106 {"refund_payment_mode_id" : cls .customer_payment_mode .id }
119107 )
120-
121108 cls .customer = (
122109 cls .env ["res.partner" ]
123110 .with_company (cls .company .id )
@@ -128,7 +115,6 @@ def setUpClass(cls):
128115 }
129116 )
130117 )
131-
132118 cls .supplier = (
133119 cls .env ["res.partner" ]
134120 .with_company (cls .company .id )
@@ -148,18 +134,17 @@ def setUpClass(cls):
148134 cls .supplier .with_company (
149135 cls .company_2 .id
150136 ).supplier_payment_mode_id = cls .supplier_payment_mode_c2
151-
152137 cls .invoice_account = cls .env ["account.account" ].search (
153138 [
154139 ("account_type" , "=" , "liability_payable" ),
155- ("company_id " , "in" , cls .company .id ),
140+ ("company_ids " , "in" , cls .company .ids ),
156141 ],
157142 limit = 1 ,
158143 )
159144 cls .invoice_line_account = cls .env ["account.account" ].search (
160145 [
161146 ("account_type" , "=" , "expense" ),
162- ("company_id " , "in" , cls .company .id ),
147+ ("company_ids " , "in" , cls .company .ids ),
163148 ],
164149 limit = 1 ,
165150 )
@@ -212,7 +197,7 @@ def _create_invoice(self, default_move_type, partner):
212197 self .env ["account.move" ].with_context (default_move_type = default_move_type )
213198 )
214199 move_form .partner_id = partner
215- move_form .invoice_date = Date .today ()
200+ move_form .invoice_date = fields . Date .today ()
216201 with move_form .invoice_line_ids .new () as line_form :
217202 line_form .product_id = self .product
218203 line_form .name = "product that cost 100"
@@ -351,9 +336,7 @@ def test_payment_mode_constrains_02(self):
351336 "ref" : "reference" ,
352337 "state" : "draft" ,
353338 "invoice_line_ids" : [
354- (
355- 0 ,
356- 0 ,
339+ Command .create (
357340 {
358341 "account_id" : self .invoice_account .id ,
359342 "credit" : 1000 ,
@@ -362,9 +345,7 @@ def test_payment_mode_constrains_02(self):
362345 "ref" : "reference" ,
363346 },
364347 ),
365- (
366- 0 ,
367- 0 ,
348+ Command .create (
368349 {
369350 "account_id" : self .invoice_line_account .id ,
370351 "credit" : 0 ,
0 commit comments