8
8
9
9
10
10
class TestPurchaseDeposit (TransactionCase ):
11
- def setUp ( self ):
12
- super ( TestPurchaseDeposit , self ). setUp ()
13
- self . product_model = self . env [ "product.product" ]
14
- self . account_model = self .env ["account.account " ]
15
- self . invoice_model = self .env ["account.move " ]
16
- self . default_model = self .env ["ir.default " ]
11
+ @ classmethod
12
+ def setUpClass ( cls ):
13
+ super (). setUpClass ()
14
+ cls . product_model = cls .env ["product.product " ]
15
+ cls . account_model = cls .env ["account.account " ]
16
+ cls . invoice_model = cls .env ["account.move " ]
17
17
18
18
# Create Deposit Account
19
- self .account_deposit = self .account_model .create (
19
+ cls .account_deposit = cls .account_model .create (
20
20
{
21
21
"name" : "Purchase Deposit" ,
22
22
"code" : "11620" ,
23
- "user_type_id" : self .env .ref (
24
- "account.data_account_type_current_assets"
25
- ).id ,
23
+ "account_type" : "asset_current" ,
26
24
}
27
25
)
28
26
# Create products:
29
- p1 = self .product1 = self .product_model .create (
27
+ p1 = cls .product1 = cls .product_model .create (
30
28
{
31
29
"name" : "Test Product 1" ,
32
30
"type" : "service" ,
@@ -35,9 +33,9 @@ def setUp(self):
35
33
}
36
34
)
37
35
38
- self .po = self .env ["purchase.order" ].create (
36
+ cls .po = cls .env ["purchase.order" ].create (
39
37
{
40
- "partner_id" : self . ref ("base.res_partner_3" ),
38
+ "partner_id" : cls . env . ref ("base.res_partner_3" ). id ,
41
39
"order_line" : [
42
40
(
43
41
0 ,
@@ -68,14 +66,12 @@ def test_create_deposit_invoice(self):
68
66
self .po .button_confirm ()
69
67
with Form (CreateDeposit .with_context (** ctx )) as f :
70
68
f .advance_payment_method = "percentage"
71
- f .deposit_account_id = self .account_deposit
72
69
wizard = f .save ()
73
70
wizard .amount = 10.0 # 10%
71
+ wizard .deposit_account_id = self .account_deposit
74
72
wizard .create_invoices ()
75
73
# New Purchase Deposit is created automatically
76
- deposit_id = self .default_model .sudo ().get (
77
- "purchase.advance.payment.inv" , "purchase_deposit_product_id"
78
- )
74
+ deposit_id = self .env .company .purchase_deposit_product_id .id
79
75
deposit = self .product_model .browse (deposit_id )
80
76
self .assertEqual (deposit .name , "Purchase Deposit" )
81
77
# 1 Deposit Invoice is created
@@ -127,20 +123,17 @@ def test_create_deposit_invoice_exception_1(self):
127
123
"create_bills" : True ,
128
124
}
129
125
CreateDeposit = self .env ["purchase.advance.payment.inv" ]
130
- # 1. This action is allowed only in Purchase Order sate
131
- with self .assertRaises (UserError ):
132
- Form (CreateDeposit .with_context (** ctx )) # Initi wizard
133
126
self .po .button_confirm ()
134
127
self .assertEqual (self .po .state , "purchase" )
135
- # 2 . The value of the deposit must be positive
128
+ # 1 . The value of the deposit must be positive
136
129
f = Form (CreateDeposit .with_context (** ctx ))
137
130
f .advance_payment_method = "fixed"
138
131
f .amount = 0.0
139
132
f .deposit_account_id = self .account_deposit
140
133
wizard = f .save ()
141
134
with self .assertRaises (UserError ):
142
135
wizard .create_invoices ()
143
- # 3 . For type percentage, The percentage of the deposit must <= 100
136
+ # 2 . For type percentage, The percentage of the deposit must <= 100
144
137
wizard .advance_payment_method = "percentage"
145
138
wizard .amount = 101.0
146
139
with self .assertRaises (UserError ):
@@ -168,9 +161,7 @@ def test_create_deposit_invoice_exception_2(self):
168
161
f .deposit_account_id = self .account_deposit
169
162
wizard = f .save ()
170
163
# 4. Purchase Deposit Product's purchase_method != purchase
171
- deposit_id = self .default_model .sudo ().get (
172
- "purchase.advance.payment.inv" , "purchase_deposit_product_id"
173
- )
164
+ deposit_id = self .env .company .purchase_deposit_product_id .id
174
165
deposit = self .product_model .browse (deposit_id )
175
166
deposit .purchase_method = "receive"
176
167
wizard .purchase_deposit_product_id = deposit
@@ -197,9 +188,7 @@ def test_create_deposit_invoice_exception_3(self):
197
188
f .amount = 101.0
198
189
f .deposit_account_id = self .account_deposit
199
190
wizard = f .save ()
200
- deposit_id = self .default_model .sudo ().get (
201
- "purchase.advance.payment.inv" , "purchase_deposit_product_id"
202
- )
191
+ deposit_id = self .env .company .purchase_deposit_product_id .id
203
192
deposit = self .product_model .browse (deposit_id )
204
193
# 5. Purchase Deposit Product's type != service
205
194
deposit .type = "consu"
0 commit comments