11# Copyright 2015 Agile Business Group <http://www.agilebg.com>
2+ # Copyright 2021 Lorenzo Battistini @ TAKOBI
23# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
34
45from datetime import datetime
56
67from dateutil .rrule import MONTHLY
78
8- from odoo .addons . account . tests .account_test_users import AccountTestUsers
9+ from odoo .tests .common import SavepointCase
910
1011
11- class TestTaxSP (AccountTestUsers ):
12+ class TestTaxSP (SavepointCase ):
1213 def setUp (self ):
1314 super ().setUp ()
1415 self .tax_model = self .env ["account.tax" ]
15- self .invoice_model = self .env ["account.invoice " ]
16+ self .move_model = self .env ["account.move " ]
1617 self .term_model = self .env ["account.payment.term" ]
1718 self .fp_model = self .env ["account.fiscal.position" ]
1819 self .account_model = self .env ["account.account" ]
1920 self .term_line_model = self .env ["account.payment.term.line" ]
20- self .invoice_line_model = self .env ["account.invoice.line" ]
2121 self .vat_statement_model = self .env ["account.vat.period.end.statement" ]
2222 account_user_type = self .env .ref ("account.data_account_type_receivable" )
2323 today = datetime .now ().date ()
@@ -32,7 +32,7 @@ def setUp(self):
3232 "name_prefix" : "%s-" % datetime .now ().year ,
3333 "type_id" : self .range_type .id ,
3434 "duration_count" : 1 ,
35- "unit_of_time" : MONTHLY ,
35+ "unit_of_time" : str ( MONTHLY ) ,
3636 "count" : 12 ,
3737 }
3838 )
@@ -74,9 +74,9 @@ def setUp(self):
7474
7575 # ----- Set invoice date to recent date in the system
7676 # ----- This solves problems with account_invoice_sequential_dates
77- self .recent_date = self .invoice_model .search (
78- [("date_invoice " , "!=" , False )], order = "date_invoice desc" , limit = 1
79- ).date_invoice
77+ self .recent_date = self .move_model .search (
78+ [("invoice_date " , "!=" , False )], order = "invoice_date desc" , limit = 1
79+ ).invoice_date
8080
8181 self .account_tax_22sp = self .tax_model .create (
8282 {
@@ -134,7 +134,7 @@ def setUp(self):
134134 ],
135135 limit = 1 ,
136136 )
137- self .a_recv = self .account_model .sudo ( self . account_manager . id ). create (
137+ self .a_recv = self .account_model .create (
138138 dict (
139139 code = "cust_acc" ,
140140 name = "customer account" ,
@@ -203,28 +203,23 @@ def setUp(self):
203203 )
204204 # Set invoice date to recent date in the system
205205 # This solves problems with account_invoice_sequential_dates
206- self .recent_date = self .invoice_model .search (
207- [("date_invoice " , "!=" , False )], order = "date_invoice desc" , limit = 1
208- ).date_invoice
206+ self .recent_date = self .move_model .search (
207+ [("invoice_date " , "!=" , False )], order = "invoice_date desc" , limit = 1
208+ ).invoice_date
209209
210210 self .sales_journal = self .env ["account.journal" ].search (
211211 [("type" , "=" , "sale" )]
212212 )[0 ]
213- self .sales_journal .update_posted = True
214- self .purchase_journal = self .env ["account.journal" ].search (
215- [("type" , "=" , "purchase" )]
216- )[0 ]
217213 self .general_journal = self .env ["account.journal" ].search (
218214 [("type" , "=" , "general" )]
219215 )[0 ]
220216
221217 def test_invoice (self ):
222- invoice = self .invoice_model .create (
218+ invoice = self .move_model . with_context ( default_move_type = "out_invoice" ) .create (
223219 {
224- "date_invoice " : self .recent_date ,
220+ "invoice_date " : self .recent_date ,
225221 "partner_id" : self .env .ref ("base.res_partner_3" ).id ,
226222 "journal_id" : self .sales_journal .id ,
227- "account_id" : self .a_recv .id ,
228223 "fiscal_position_id" : self .sp_fp .id ,
229224 "invoice_line_ids" : [
230225 (
@@ -235,16 +230,13 @@ def test_invoice(self):
235230 "account_id" : self .a_sale .id ,
236231 "quantity" : 1 ,
237232 "price_unit" : 100 ,
238- "invoice_line_tax_ids" : [
239- (6 , 0 , {self .account_tax_22sp .id })
240- ],
233+ "tax_ids" : [(6 , 0 , {self .account_tax_22sp .id })],
241234 },
242235 )
243236 ],
244237 }
245238 )
246- invoice .compute_taxes ()
247- invoice .action_invoice_open ()
239+ invoice .action_post ()
248240
249241 self .vat_statement = self .vat_statement_model .create (
250242 {
@@ -263,7 +255,7 @@ def test_invoice(self):
263255
264256 def test_account_sp_company (self ):
265257 account_user_type = self .env .ref ("account.data_account_type_receivable" )
266- account_sp = self .account_model .sudo ( self . account_manager . id ). create (
258+ account_sp = self .account_model .create (
267259 dict (
268260 code = "split_payment_acc" ,
269261 name = "Split payment account" ,
@@ -273,12 +265,11 @@ def test_account_sp_company(self):
273265 )
274266 self .company .sp_account_id = account_sp .id
275267
276- invoice = self .invoice_model .create (
268+ invoice = self .move_model . with_context ( default_move_type = "out_invoice" ) .create (
277269 {
278- "date_invoice " : self .recent_date ,
270+ "invoice_date " : self .recent_date ,
279271 "partner_id" : self .env .ref ("base.res_partner_3" ).id ,
280272 "journal_id" : self .sales_journal .id ,
281- "account_id" : self .a_recv .id ,
282273 "fiscal_position_id" : self .sp_fp .id ,
283274 "invoice_line_ids" : [
284275 (
@@ -289,16 +280,13 @@ def test_account_sp_company(self):
289280 "account_id" : self .a_sale .id ,
290281 "quantity" : 1 ,
291282 "price_unit" : 100 ,
292- "invoice_line_tax_ids" : [
293- (6 , 0 , {self .account_tax_22sp .id })
294- ],
283+ "tax_ids" : [(6 , 0 , {self .account_tax_22sp .id })],
295284 },
296285 )
297286 ],
298287 }
299288 )
300- invoice .compute_taxes ()
301- invoice .action_invoice_open ()
289+ invoice .action_post ()
302290
303291 self .vat_statement = self .vat_statement_model .create (
304292 {
0 commit comments