Left: | ||
Right: |
LEFT | RIGHT |
---|---|
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 #This file is part of Tryton. The COPYRIGHT file at the top level of | 2 #This file is part of Tryton. The COPYRIGHT file at the top level of |
3 #this repository contains the full copyright notices and license terms. | 3 #this repository contains the full copyright notices and license terms. |
4 | 4 |
5 #import sys, os | 5 import sys, os |
6 #DIR = os.path.abspath(os.path.normpath(os.path.join(__file__, | 6 DIR = os.path.abspath(os.path.normpath(os.path.join(__file__, |
7 # '..', '..', '..', '..', '..', 'trytond'))) | 7 '..', '..', '..', '..', '..', 'trytond'))) |
8 #if os.path.isdir(DIR): | 8 if os.path.isdir(DIR): |
9 # sys.path.insert(0, os.path.dirname(DIR)) | 9 sys.path.insert(0, os.path.dirname(DIR)) |
10 | 10 |
11 import unittest | 11 import unittest |
12 import trytond.tests.test_tryton | 12 import trytond.tests.test_tryton |
13 from trytond.tests.test_tryton import POOL, DB, USER, test_view | 13 from trytond.tests.test_tryton import POOL, DB, USER, test_view |
14 import copy | 14 import copy |
15 from datetime import date | 15 from datetime import date |
16 from decimal import Decimal | 16 from decimal import Decimal |
17 ZERO = Decimal('0.0') | |
17 | 18 |
18 CONTEXT = {} | 19 CONTEXT = {} |
19 | 20 |
20 class AccountTestCase(unittest.TestCase): | 21 class AccountTestCase(unittest.TestCase): |
21 'Test collection for account module' | 22 'Test collection for account module' |
22 | 23 |
23 def setUp(self): | 24 def setUp(self): |
24 trytond.tests.test_tryton.install_module('account') | 25 trytond.tests.test_tryton.install_module('account') |
25 self.user = POOL.get('res.user') | 26 self.user = POOL.get('res.user') |
26 self.sequence = POOL.get('ir.sequence') | 27 self.sequence = POOL.get('ir.sequence') |
27 self.fiscalyear = POOL.get('account.fiscalyear') | 28 self.fiscalyear = POOL.get('account.fiscalyear') |
28 self.account_template = POOL.get('account.account.template') | 29 self.account_template = POOL.get('account.account.template') |
29 self.account = POOL.get('account.account') | 30 self.account = POOL.get('account.account') |
31 self.account_type = POOL.get('account.account.type') | |
30 self.journal = POOL.get('account.journal') | 32 self.journal = POOL.get('account.journal') |
31 self.currency = POOL.get('currency.currency') | 33 self.currency = POOL.get('currency.currency') |
32 self.company = POOL.get('company.company') | 34 self.company = POOL.get('company.company') |
35 self.tax = POOL.get('account.tax') | |
36 self.tax_code = POOL.get('account.tax.code') | |
33 | 37 |
34 def test0010createcompany(self): | 38 def test0010createcompany(self): |
ced
2010/04/09 18:35:27
Why not rely on company creation of module company
udono
2010/04/09 19:48:43
Yes, I want to do. But I collect some ideas for th
| |
35 'Create company' | 39 'Create company' |
36 cursor = DB.cursor() | 40 cursor = DB.cursor() |
41 ctx = self.user.get_preferences(cursor, USER) | |
42 CONTEXT.update(ctx) | |
37 currency_id = self.currency.search(cursor, USER, [ | 43 currency_id = self.currency.search(cursor, USER, [ |
38 ('code', '=', 'cu1'), | 44 ('code', '=', 'cu1'), |
39 ], 0, 1, None)[0] | 45 ], offset=0, limit=1, order=None, |
40 | 46 context=CONTEXT, count=False)[0] |
41 company_id = self.company.create(cursor, USER, { | 47 company_id = self.company.create(cursor, USER, { |
42 'name': 'ACME', | 48 'name': 'ACME', |
43 'currency': currency_id, | 49 'currency': currency_id, |
44 }) | 50 }, context=CONTEXT) |
ced
2010/04/09 18:35:27
missing context
udono
2010/04/09 19:48:43
ok
udono
2010/04/10 01:28:33
Done.
| |
45 self.assert_(company_id) | 51 self.assert_(company_id) |
46 # add company to USER | 52 # add company to USER |
47 self.user.write(cursor, USER, USER, { | 53 self.user.write(cursor, USER, USER, { |
48 'company': company_id, | 54 'company': company_id, |
49 'main_company': company_id, | 55 'main_company': company_id, |
50 }) | 56 }, context=CONTEXT) |
51 # extend CONTEXT | 57 # extend CONTEXT, |
52 ctx = self.user.get_preferences(cursor, USER) | 58 ctx = self.user.get_preferences(cursor, USER, context=CONTEXT) |
53 CONTEXT.update(ctx) | 59 CONTEXT.update(ctx) |
54 cursor.commit() | 60 cursor.commit() |
55 cursor.close() | 61 cursor.close() |
56 | 62 |
57 def test0020createfiscalyear2010(self): | 63 def test0020createpostmovesequence2009(self): |
ced
2010/04/09 18:35:27
fiscalyear test should test date overlap and also
udono
2010/04/09 19:48:43
Yes, date overlap test is needed. What is the case
ced
2010/04/09 20:42:57
There is a function check_post_move_sequence that
udono
2010/04/10 01:28:33
test date overlap Done.
| |
58 'Create fiscalyear 2010' | 64 'Create post move sequence 2009' |
59 cursor = DB.cursor() | 65 cursor = DB.cursor() |
60 company_id = self.company.search(cursor, USER, [ | 66 post_move_sequence_id = self.sequence.create( |
61 ('name', '=', 'ACME'), | 67 cursor, USER, { |
62 ], 0, 1, None, CONTEXT)[0] | 68 'name': '2009 Moves', |
ced
2010/04/09 18:35:27
you can named args
udono
2010/04/09 19:48:43
ok.
udono
2010/04/10 01:28:33
Done.
| |
63 self.assert_(company_id) | 69 'code': 'account.move', |
70 }, context=CONTEXT) | |
71 self.assert_(post_move_sequence_id) | |
72 cursor.commit() | |
73 cursor.close() | |
74 | |
75 def test0030nameofsequencemustbeuniqueforeachcode(self): | |
76 'Create sequence with same name and code is not allowed' | |
77 cursor = DB.cursor() | |
78 self.assertRaises(Exception, self.sequence.create, cursor, USER, { | |
79 'name': '2009 Moves', | |
80 'code': 'account.move', | |
81 }, context=CONTEXT) | |
82 cursor.rollback() | |
83 cursor.close() | |
84 | |
85 def test0040createpostmovesequence2010(self): | |
86 'Create post move sequence 2010' | |
87 cursor = DB.cursor() | |
64 post_move_sequence_id = self.sequence.create( | 88 post_move_sequence_id = self.sequence.create( |
65 cursor, USER, { | 89 cursor, USER, { |
66 'name': '2010 Moves', | 90 'name': '2010 Moves', |
67 'code': 'account.move', | 91 'code': 'account.move', |
68 }, CONTEXT) | 92 }, context=CONTEXT) |
93 self.assert_(post_move_sequence_id) | |
94 cursor.commit() | |
95 cursor.close() | |
96 | |
97 def test0050createfiscalyear2009(self): | |
98 'Create fiscalyear 2009' | |
99 cursor = DB.cursor() | |
100 company_id = CONTEXT.get('main_company', 1) | |
101 self.assert_(company_id) | |
102 post_move_sequence_id = self.sequence.search(cursor, USER, [ | |
103 ('name', '=', '2009 Moves'), | |
104 ], offset=0, limit=1, order=None, context=CONTEXT, | |
105 count=False)[0] | |
106 self.assert_(post_move_sequence_id) | |
107 fiscalyear_id = self.fiscalyear.create(cursor, USER, { | |
108 'name': '2009', | |
109 'code': '2009', | |
110 'start_date': date(2009,1,1), | |
111 'end_date': date(2009,12,31), | |
112 'company': company_id, | |
113 'post_move_sequence': post_move_sequence_id, | |
114 }, context=CONTEXT) | |
115 self.assert_(fiscalyear_id) | |
116 cursor.commit() | |
117 cursor.close() | |
118 | |
119 def test0060createoverlappingfiscalyearnotallowed(self): | |
120 'Create overlapping fiscalyear not allowed' | |
121 cursor = DB.cursor() | |
122 company_id = CONTEXT.get('main_company', 1) | |
123 post_move_sequence_id = self.sequence.search(cursor, USER, [ | |
124 ('name', '=', '2009 Moves'), | |
125 ], offset=0, limit=1, order=None, context=CONTEXT, | |
126 count=False)[0] | |
127 self.assert_(post_move_sequence_id) | |
128 cursor.commit() | |
129 self.assertRaises(Exception, self.fiscalyear.create, cursor, USER, { | |
130 'name': 'Overlapping Move', | |
131 'code': 'Overlapping', | |
132 'start_date': date(2009,12,31), | |
133 'end_date': date(2010,12,31), | |
134 'company': company_id, | |
135 'post_move_sequence': post_move_sequence_id, | |
136 }, context=CONTEXT) | |
137 cursor.rollback() | |
138 cursor.close() | |
139 | |
140 def test0070createfiscalyear2010(self): | |
141 'Create fiscalyear 2010' | |
142 cursor = DB.cursor() | |
143 company_id = CONTEXT.get('main_company', 1) | |
144 post_move_sequence_id = self.sequence.search(cursor, USER, [ | |
145 ('name', '=', '2010 Moves'), | |
146 ], offset=0, limit=1, order=None, context=CONTEXT, | |
147 count=False)[0] | |
69 self.assert_(post_move_sequence_id) | 148 self.assert_(post_move_sequence_id) |
70 fiscalyear_id = self.fiscalyear.create(cursor, USER, { | 149 fiscalyear_id = self.fiscalyear.create(cursor, USER, { |
71 'name': '2010', | 150 'name': '2010', |
72 'code': '2010', | 151 'code': '2010', |
73 'start_date': date(2010,1,1), | 152 'start_date': date(2010,1,1), |
74 'end_date': date(2010,12,31), | 153 'end_date': date(2010,12,31), |
75 'company': company_id, | 154 'company': company_id, |
76 'post_move_sequence': post_move_sequence_id, | 155 'post_move_sequence': post_move_sequence_id, |
77 }, CONTEXT) | 156 }, context=CONTEXT) |
157 self.assert_(fiscalyear_id) | |
158 cursor.commit() | |
159 cursor.close() | |
160 | |
161 def test0080createperiod2009(self): | |
162 'Create period 2009' | |
163 cursor = DB.cursor() | |
164 company_id = CONTEXT.get('main_company', 1) | |
165 fiscalyear_id = self.fiscalyear.search(cursor, USER, [ | |
166 ('name', '=', '2009'), | |
167 ('company', '=', company_id), | |
168 ], offset=0, limit=1, order=None, context=CONTEXT, | |
169 count=False)[0] | |
78 self.assert_(fiscalyear_id) | 170 self.assert_(fiscalyear_id) |
79 self.fiscalyear.create_period(cursor, USER, [fiscalyear_id], | 171 self.fiscalyear.create_period(cursor, USER, [fiscalyear_id], |
ced
2010/04/09 18:35:27
test also period_3
udono
2010/04/09 19:48:43
Don't understand?
ced
2010/04/09 20:42:57
There is also acreate_period_3 function.
And by th
udono
2010/04/10 01:28:33
Done.
| |
80 CONTEXT) | 172 context=CONTEXT) |
81 cursor.commit() | 173 cursor.commit() |
82 cursor.close() | 174 cursor.close() |
83 | 175 |
84 def test0030createchartofaccounts(self): | 176 def test0090createoverlappingperiod(self): |
177 'Create overlapping period not allowed' | |
178 cursor = DB.cursor() | |
179 company_id = CONTEXT.get('main_company', 1) | |
180 fiscalyear_id = self.fiscalyear.search(cursor, USER, [ | |
181 ('name', '=', '2009'), | |
182 ('company', '=', company_id), | |
183 ], offset=0, limit=1, order=None, context=CONTEXT, | |
184 count=False)[0] | |
185 self.assert_(fiscalyear_id) | |
186 cursor.commit() | |
187 self.assertRaises(Exception, self.fiscalyear.create_period, cursor, | |
188 USER, [fiscalyear_id], context=CONTEXT) | |
189 cursor.rollback() | |
190 cursor.close() | |
191 | |
192 def test0100createperiod_3_2010(self): | |
193 'Create period_3 2010' | |
194 cursor = DB.cursor() | |
195 company_id = CONTEXT.get('main_company', 1) | |
196 fiscalyear_id = self.fiscalyear.search(cursor, USER, [ | |
197 ('name', '=', '2010'), | |
198 ('company', '=', company_id), | |
199 ], offset=0, limit=1, order=None, context=CONTEXT, | |
200 count=False)[0] | |
201 self.assert_(fiscalyear_id) | |
202 self.fiscalyear.create_period_3(cursor, USER, [fiscalyear_id], | |
203 context=CONTEXT) | |
204 cursor.commit() | |
205 cursor.close() | |
206 | |
207 def test0110createoverlappingperiod_3(self): | |
208 'Create overlapping period_3 not allowed' | |
209 cursor = DB.cursor() | |
210 company_id = CONTEXT.get('main_company', 1) | |
211 fiscalyear_id = self.fiscalyear.search(cursor, USER, [ | |
212 ('name', '=', '2010'), | |
213 ('company', '=', company_id), | |
214 ], offset=0, limit=1, order=None, context=CONTEXT, | |
215 count=False)[0] | |
216 self.assert_(fiscalyear_id) | |
217 cursor.commit() | |
218 self.assertRaises(Exception, self.fiscalyear.create_period_3, cursor, | |
219 USER, [fiscalyear_id], context=CONTEXT) | |
220 cursor.rollback() | |
221 cursor.close() | |
222 | |
223 def test0120createcrossoverlappingperiod_3(self): | |
224 'Create overlapping period_3 not allowed' | |
225 cursor = DB.cursor() | |
226 company_id = CONTEXT.get('main_company', 1) | |
227 fiscalyear_id = self.fiscalyear.search(cursor, USER, [ | |
228 ('name', '=', '2009'), | |
229 ('company', '=', company_id), | |
230 ], offset=0, limit=1, order=None, context=CONTEXT, | |
231 count=False)[0] | |
232 self.assert_(fiscalyear_id) | |
233 cursor.commit() | |
234 self.assertRaises(Exception, self.fiscalyear.create_period_3, cursor, | |
235 USER, [fiscalyear_id], context=CONTEXT) | |
236 cursor.rollback() | |
237 cursor.close() | |
238 | |
239 def test0130createcrossoverlappingperiod(self): | |
240 'Create overlapping period not allowed' | |
241 cursor = DB.cursor() | |
242 company_id = CONTEXT.get('main_company', 1) | |
243 fiscalyear_id = self.fiscalyear.search(cursor, USER, [ | |
244 ('name', '=', '2010'), | |
245 ('company', '=', company_id), | |
246 ], offset=0, limit=1, order=None, context=CONTEXT, | |
247 count=False)[0] | |
248 self.assert_(fiscalyear_id) | |
249 cursor.commit() | |
250 self.assertRaises(Exception, self.fiscalyear.create_period, cursor, | |
251 USER, [fiscalyear_id], context=CONTEXT) | |
252 cursor.rollback() | |
253 cursor.close() | |
254 | |
255 def test0140createchartofaccounts(self): | |
85 'Create minimal chart of accounts' | 256 'Create minimal chart of accounts' |
86 cursor = DB.cursor() | 257 cursor = DB.cursor() |
87 # retrieve needed data | 258 # retrieve needed data |
88 company_id = self.company.search(cursor, USER, [ | 259 company_id = CONTEXT.get('main_company', 1) |
89 ('name', '=', 'ACME'), | |
90 ], 0, 1, None, CONTEXT)[0] | |
91 self.assert_(company_id) | |
92 account_template_id = self.account_template.search(cursor, USER, [ | 260 account_template_id = self.account_template.search(cursor, USER, [ |
93 ('name', '=', 'Minimal Account Chart'), | 261 ('name', '=', 'Minimal Account Chart'), |
94 ], 0, 1, None, CONTEXT)[0] | 262 ], offset=0, limit=1, order=None, context=CONTEXT, |
263 count=False)[0] | |
95 self.assert_(account_template_id) | 264 self.assert_(account_template_id) |
96 # establish create wizard | 265 # establish create wizard |
97 create_chart_account_obj = POOL.get( | 266 create_chart_account_obj = POOL.get( |
98 'account.account.create_chart_account', type='wizard') | 267 'account.account.create_chart_account', type='wizard') |
99 wizard_id = create_chart_account_obj.create(cursor, USER) | 268 wizard_id = create_chart_account_obj.create(cursor, USER) |
100 cursor.commit() | 269 cursor.commit() |
101 create_chart_account_obj.execute(cursor, USER, wizard_id, { | 270 create_chart_account_obj.execute(cursor, USER, wizard_id, { |
102 'form': { | 271 'form': { |
103 'account_template': account_template_id, | 272 'account_template': account_template_id, |
104 'company': company_id, | 273 'company': company_id, |
105 }}, 'create_account', CONTEXT) | 274 }}, 'create_account', context=CONTEXT) |
106 cursor.commit() | 275 cursor.commit() |
107 # get defaults | 276 # get defaults |
108 default_account_receivable_id = self.account.search(cursor, USER, [ | 277 default_account_receivable_id = self.account.search(cursor, USER, [ |
109 ('kind', '=', 'receivable'), | 278 ('kind', '=', 'receivable'), |
110 ('company', '=', company_id), | 279 ('company', '=', company_id), |
111 ], 0, 1, None, CONTEXT)[0] | 280 ], offset=0, limit=1, order=None, context=CONTEXT, |
281 count=False)[0] | |
112 self.assert_(default_account_receivable_id) | 282 self.assert_(default_account_receivable_id) |
113 default_account_payable_id = self.account.search(cursor, USER, [ | 283 default_account_payable_id = self.account.search(cursor, USER, [ |
114 ('kind', '=', 'payable'), | 284 ('kind', '=', 'payable'), |
115 ('company', '=', company_id), | 285 ('company', '=', company_id), |
116 ], 0, 1, None, CONTEXT)[0] | 286 ], offset=0, limit=1, order=None, context=CONTEXT, |
287 count=False)[0] | |
117 self.assert_(default_account_payable_id) | 288 self.assert_(default_account_payable_id) |
118 # create chart of accounts | 289 # create chart of accounts |
119 create_chart_account_obj.execute(cursor, USER, wizard_id, { | 290 create_chart_account_obj.execute(cursor, USER, wizard_id, { |
120 'form': { | 291 'form': { |
121 'account_receivable': \ | 292 'account_receivable': \ |
122 default_account_receivable_id, | 293 default_account_receivable_id, |
123 'account_payable': \ | 294 'account_payable': \ |
124 default_account_payable_id, | 295 default_account_payable_id, |
125 'company': company_id, | 296 'company': company_id, |
126 | 297 |
127 }}, 'create_properties', CONTEXT) | 298 }}, 'create_properties', context=CONTEXT) |
128 cursor.commit() | 299 cursor.commit() |
129 # delete wizard | 300 # delete wizard |
130 create_chart_account_obj.delete(cursor, USER, wizard_id) | 301 create_chart_account_obj.delete(cursor, USER, wizard_id) |
131 cursor.commit() | 302 cursor.commit() |
132 cursor.close() | 303 cursor.close() |
133 | 304 |
134 def test0040setupcashjournal(self): | 305 def test0150setupcashjournal(self): |
135 'Setup cash journal' | 306 'Setup cash journal' |
136 cursor = DB.cursor() | 307 cursor = DB.cursor() |
137 company_id = self.company.search(cursor, USER, [ | 308 company_id = CONTEXT.get('main_company', 1) |
138 ('name', '=', 'ACME'), | |
139 ], 0, 1, None, CONTEXT)[0] | |
140 self.assert_(company_id) | |
141 account_cash_id = self.account.search(cursor, USER, [ | 309 account_cash_id = self.account.search(cursor, USER, [ |
142 ('name', '=', 'Main Cash'), | 310 ('name', '=', 'Main Cash'), |
143 ('company', '=', company_id), | 311 ('company', '=', company_id), |
144 ], 0, 1, None, CONTEXT)[0] | 312 ], offset=0, limit=1, order=None, context=CONTEXT, |
313 count=False)[0] | |
145 self.assert_(account_cash_id) | 314 self.assert_(account_cash_id) |
146 journal_cash_id = self.journal.search(cursor, USER, [ | 315 journal_cash_id = self.journal.search(cursor, USER, [ |
147 ('type', '=', 'cash'), | 316 ('type', '=', 'cash'), |
148 ], 0, 1, None, CONTEXT)[0] | 317 ], offset=0, limit=1, order=None, context=CONTEXT, |
318 count=False)[0] | |
149 self.assert_(journal_cash_id) | 319 self.assert_(journal_cash_id) |
150 self.journal.write(cursor, USER, journal_cash_id, { | 320 self.journal.write(cursor, USER, journal_cash_id, { |
151 'credit_account': account_cash_id, | 321 'credit_account': account_cash_id, |
152 'debit_account': account_cash_id, | 322 'debit_account': account_cash_id, |
153 }, CONTEXT) | 323 }, context=CONTEXT) |
324 cursor.commit() | |
325 cursor.close() | |
326 | |
327 def test0160createtaxaccounts(self): | |
328 '''Create VAT tax accounts''' | |
329 cursor = DB.cursor() | |
330 company_id = CONTEXT.get('main_company', 1) | |
331 account_type_tax_id = self.account_type.search(cursor, USER, [ | |
332 ('name', '=', 'Tax'), | |
333 ('company', '=', company_id), | |
334 ], offset=0, limit=1, order=None, context=CONTEXT, | |
335 count=False)[0] | |
336 self.assert_(account_type_tax_id) | |
337 account_main_revenue_id = self.account.search(cursor, USER, [ | |
338 ('name', '=', 'Main Tax'), | |
339 ('company', '=', company_id), | |
340 ], offset=0, limit=1, order=None, context=CONTEXT, | |
341 count=False)[0] | |
342 self.assert_(account_main_revenue_id) | |
343 account_main_expense_id = self.account.search(cursor, USER, [ | |
344 ('name', '=', 'Main Tax'), | |
345 ('company', '=', company_id), | |
346 ], offset=0, limit=1, order=None, context=CONTEXT, | |
347 count=False)[0] | |
348 self.assert_(account_main_expense_id) | |
349 # Add accounts for collecting taxes | |
350 account_vat_received_id = self.account.create(cursor, USER, { | |
351 'name': 'VAT received', | |
352 'kind': 'receivable', | |
353 'deferral': False, | |
354 'parent': account_main_revenue_id, | |
355 'type': account_type_tax_id, | |
356 }, context=CONTEXT) | |
357 self.assert_(account_vat_received_id) | |
358 account_vat_paid_id = self.account.create(cursor, USER, { | |
359 'name': 'VAT paid', | |
360 'kind': 'payable', | |
361 'deferral': False, | |
362 'parent': account_main_expense_id, | |
363 'type': account_type_tax_id, | |
364 }, context=CONTEXT) | |
365 self.assert_(account_vat_paid_id) | |
366 | |
367 cursor.commit() | |
368 cursor.close() | |
369 | |
370 def test0170createtaxbasecodes(self): | |
371 '''Create VAT tax and base codes''' | |
372 cursor = DB.cursor() | |
373 # Add tax code tree | |
374 # Add base code structure | |
375 parent_base_code_id = self.tax_code.create(cursor, USER, { | |
376 'name': 'Total Base', | |
377 }, context=CONTEXT) | |
378 self.assert_(parent_base_code_id) | |
379 received_base_code_id = self.tax_code.create(cursor, USER, { | |
380 'name': 'Received Base', | |
381 'parent': parent_base_code_id, | |
382 }, context=CONTEXT) | |
383 self.assert_(received_base_code_id) | |
384 paid_base_code_id = self.tax_code.create(cursor, USER, { | |
385 'name': 'Paid Base', | |
386 'parent': parent_base_code_id, | |
387 }, context=CONTEXT) | |
388 self.assert_(paid_base_code_id) | |
389 # Add tax code structure | |
390 parent_tax_code_id = self.tax_code.create(cursor, USER, { | |
391 'name': 'Total Tax', | |
392 }, context=CONTEXT) | |
393 self.assert_(parent_tax_code_id) | |
394 received_tax_code_id = self.tax_code.create(cursor, USER, { | |
395 'name': 'Received Tax', | |
396 'parent': parent_tax_code_id, | |
397 }, context=CONTEXT) | |
398 self.assert_(received_tax_code_id) | |
399 paid_tax_code_id = self.tax_code.create(cursor, USER, { | |
400 'name': 'Paid Tax', | |
401 'parent': parent_tax_code_id, | |
402 }, context=CONTEXT) | |
403 self.assert_(paid_tax_code_id) | |
404 cursor.commit() | |
405 cursor.close() | |
406 | |
407 def test0180createtax(self): | |
408 '''Create VAT taxes''' | |
409 cursor = DB.cursor() | |
410 company_id = CONTEXT.get('main_company', 1) | |
411 account_type_tax_id = self.account_type.search(cursor, USER, [ | |
412 ('name', '=', 'Tax'), | |
413 ], offset=0, limit=1, order=None, context=CONTEXT, | |
414 count=False)[0] | |
415 self.assert_(account_type_tax_id) | |
416 received_base_code_id = self.tax_code.search(cursor, USER, [ | |
417 ('name', '=', 'Received Base'), | |
418 ], offset=0, limit=1, order=None, context=CONTEXT, | |
419 count=False)[0] | |
420 self.assert_(received_base_code_id) | |
421 paid_base_code_id = self.tax_code.search(cursor, USER, [ | |
422 ('name', '=', 'Paid Base'), | |
423 ], offset=0, limit=1, order=None, context=CONTEXT, | |
424 count=False)[0] | |
425 self.assert_(paid_base_code_id) | |
426 received_tax_code_id = self.tax_code.search(cursor, USER, [ | |
427 ('name', '=', 'Received Tax'), | |
428 ], offset=0, limit=1, order=None, context=CONTEXT, | |
429 count=False)[0] | |
430 self.assert_(received_tax_code_id) | |
431 paid_tax_code_id = self.tax_code.search(cursor, USER, [ | |
432 ('name', '=', 'Paid Tax'), | |
433 ], offset=0, limit=1, order=None, context=CONTEXT, | |
434 count=False)[0] | |
435 self.assert_(paid_tax_code_id) | |
436 account_vat_received_id = self.account.search(cursor, USER, [ | |
437 ('name', '=', 'VAT received'), | |
438 ], offset=0, limit=1, order=None, context=CONTEXT, | |
439 count=False)[0] | |
440 self.assert_(account_vat_received_id) | |
441 account_vat_paid_id = self.account.search(cursor, USER, [ | |
442 ('name', '=', 'VAT paid'), | |
443 ], offset=0, limit=1, order=None, context=CONTEXT, | |
444 count=False)[0] | |
445 self.assert_(account_vat_paid_id) | |
446 tax_data = [{ | |
447 'name': 'Received VAT 20%', | |
448 'description': 'Domestic VAT received', | |
449 'type': 'percentage', | |
450 'percentage': Decimal('20.0'), | |
451 'invoice_account': account_vat_received_id, | |
452 'credit_note_account': account_vat_received_id, | |
453 'invoice_base_code': received_base_code_id, | |
454 'invoice_base_sign': Decimal('1.0'), | |
455 'invoice_tax_code': received_tax_code_id, | |
456 'invoice_tax_sign': Decimal('1.0'), | |
457 'credit_note_base_code': received_base_code_id, | |
458 'credit_note_base_sign': Decimal('-1.0'), | |
459 'credit_note_tax_code': received_tax_code_id, | |
460 'credit_note_tax_sign': Decimal('-1.0'), | |
461 }, { | |
462 'name': 'Paid VAT 20%', | |
463 'description': 'Domestic VAT paid', | |
464 'type': 'percentage', | |
465 'percentage': Decimal('20.0'), | |
466 'invoice_account': account_vat_paid_id, | |
467 'credit_note_account': account_vat_paid_id, | |
468 'invoice_base_code': paid_base_code_id, | |
469 'invoice_base_sign': Decimal('1.0'), | |
470 'invoice_tax_code': paid_tax_code_id, | |
471 'invoice_tax_sign': Decimal('1.0'), | |
472 'credit_note_base_code': paid_base_code_id, | |
473 'credit_note_base_sign': Decimal('-1.0'), | |
474 'credit_note_tax_code': paid_tax_code_id, | |
475 'credit_note_tax_sign': Decimal('-1.0'), | |
476 }] | |
477 for tax in tax_data: | |
478 tax_id = self.tax.create(cursor, USER, tax, context=CONTEXT) | |
479 self.assert_(tax_id) | |
480 | |
154 cursor.commit() | 481 cursor.commit() |
155 cursor.close() | 482 cursor.close() |
156 | 483 |
157 class AccountInvoiceTestCase(unittest.TestCase): | 484 class AccountInvoiceTestCase(unittest.TestCase): |
158 'Test collection for account_invoice module' | 485 'Test collection for account_invoice module' |
159 | 486 |
160 def setUp(self): | 487 def setUp(self): |
161 trytond.tests.test_tryton.install_module('account_invoice') | 488 trytond.tests.test_tryton.install_module('account_invoice') |
162 self.user = POOL.get('res.user') | 489 self.user = POOL.get('res.user') |
163 self.account = POOL.get('account.account') | 490 self.account = POOL.get('account.account') |
491 self.account_type = POOL.get('account.account.type') | |
164 self.currency = POOL.get('currency.currency') | 492 self.currency = POOL.get('currency.currency') |
165 self.fiscalyear = POOL.get('account.fiscalyear') | 493 self.fiscalyear = POOL.get('account.fiscalyear') |
166 self.period = POOL.get('account.period') | 494 self.period = POOL.get('account.period') |
167 self.sequence_strict = POOL.get('ir.sequence.strict') | 495 self.sequence_strict = POOL.get('ir.sequence.strict') |
168 self.payment_term = POOL.get('account.invoice.payment_term') | 496 self.payment_term = POOL.get('account.invoice.payment_term') |
169 self.company = POOL.get('company.company') | 497 self.company = POOL.get('company.company') |
170 self.invoice = POOL.get('account.invoice') | 498 self.invoice = POOL.get('account.invoice') |
171 self.journal = POOL.get('account.journal') | 499 self.journal = POOL.get('account.journal') |
500 self.tax = POOL.get('account.tax') | |
172 self.party = POOL.get('party.party') | 501 self.party = POOL.get('party.party') |
173 self.party_address = POOL.get('party.address') | 502 self.party_address = POOL.get('party.address') |
174 # self.tax = POOL.get('account.tax') | |
175 | 503 |
176 def test0010updatefiscalyear2010(self): | 504 def test0010updatefiscalyear2010(self): |
177 'Update fiscalyear 2010' | 505 'Update fiscalyear 2010' |
178 cursor = DB.cursor() | 506 cursor = DB.cursor() |
179 company_id = self.company.search(cursor, USER, [ | 507 company_id = CONTEXT.get('main_company', 1) |
180 ('name', '=', 'ACME'), | |
181 ], 0, 1, None, CONTEXT)[0] | |
182 self.assert_(company_id) | |
183 out_invoice_sequence_id = self.sequence_strict.create( | 508 out_invoice_sequence_id = self.sequence_strict.create( |
184 cursor, USER, { | 509 cursor, USER, { |
185 'name': '2010 Out-Invoices', | 510 'name': '2010 Out-Invoice', |
186 'code': 'account.invoice', | 511 'code': 'account.invoice', |
187 }, CONTEXT) | 512 }, context=CONTEXT) |
188 self.assert_(out_invoice_sequence_id) | 513 self.assert_(out_invoice_sequence_id) |
189 out_credit_note_sequence_id = self.sequence_strict.create( | 514 out_credit_note_sequence_id = self.sequence_strict.create( |
190 cursor, USER, { | 515 cursor, USER, { |
191 'name': '2010 Out-Credit-Notes', | 516 'name': '2010 Out-Credit-Notes', |
192 'code': 'account.invoice', | 517 'code': 'account.invoice', |
193 }, CONTEXT) | 518 }, context=CONTEXT) |
194 self.assert_(out_credit_note_sequence_id) | 519 self.assert_(out_credit_note_sequence_id) |
195 in_invoice_sequence_id = self.sequence_strict.create( | 520 in_invoice_sequence_id = self.sequence_strict.create( |
196 cursor, USER, { | 521 cursor, USER, { |
197 'name': '2010 In-Invoicea', | 522 'name': '2010 In-Invoice', |
198 'code': 'account.invoice', | 523 'code': 'account.invoice', |
199 }, CONTEXT) | 524 }, context=CONTEXT) |
200 self.assert_(in_invoice_sequence_id) | 525 self.assert_(in_invoice_sequence_id) |
201 in_credit_note_sequence_id = self.sequence_strict.create( | 526 in_credit_note_sequence_id = self.sequence_strict.create( |
202 cursor, USER, { | 527 cursor, USER, { |
203 'name': '2010 In-Credit-Note', | 528 'name': '2010 In-Credit-Note', |
204 'code': 'account.invoice', | 529 'code': 'account.invoice', |
205 }, CONTEXT) | 530 }, context=CONTEXT) |
206 self.assert_(in_credit_note_sequence_id) | 531 self.assert_(in_credit_note_sequence_id) |
207 fiscalyear_id = self.fiscalyear.search(cursor, USER, [ | 532 fiscalyear_id = self.fiscalyear.search(cursor, USER, [ |
208 ('name', '=', '2010'), | 533 ('name', '=', '2010'), |
209 ('company', '=', company_id), | 534 ('company', '=', company_id), |
210 ], 0, 1, None, CONTEXT)[0] | 535 ], offset=0, limit=1, order=None, context=CONTEXT, |
536 count=False)[0] | |
211 self.assert_(fiscalyear_id) | 537 self.assert_(fiscalyear_id) |
212 self.fiscalyear.write(cursor, USER, fiscalyear_id, { | 538 self.fiscalyear.write(cursor, USER, fiscalyear_id, { |
213 'out_invoice_sequence': out_invoice_sequence_id, | 539 'out_invoice_sequence': out_invoice_sequence_id, |
214 'in_invoice_sequence': in_invoice_sequence_id, | 540 'in_invoice_sequence': in_invoice_sequence_id, |
215 'out_credit_note_sequence': \ | 541 'out_credit_note_sequence': \ |
216 out_credit_note_sequence_id, | 542 out_credit_note_sequence_id, |
217 'in_credit_note_sequence': \ | 543 'in_credit_note_sequence': \ |
218 in_credit_note_sequence_id, | 544 in_credit_note_sequence_id, |
219 }, CONTEXT) | 545 }, context=CONTEXT) |
220 # update periods | 546 # update periods |
221 period_ids = self.period.search(cursor, USER, [ | 547 period_ids = self.period.search(cursor, USER, [ |
222 ('fiscalyear', '=', fiscalyear_id), | 548 ('fiscalyear', '=', fiscalyear_id), |
223 ], 0, None, None, CONTEXT) | 549 ], 0, None, None, context=CONTEXT) |
224 for period_id in period_ids: | 550 for period_id in period_ids: |
225 self.period.write(cursor, USER, period_id, { | 551 self.period.write(cursor, USER, period_id, { |
226 'out_invoice_sequence': out_invoice_sequence_id, | 552 'out_invoice_sequence': out_invoice_sequence_id, |
227 'in_invoice_sequence': in_invoice_sequence_id, | 553 'in_invoice_sequence': in_invoice_sequence_id, |
228 'out_credit_note_sequence': \ | 554 'out_credit_note_sequence': \ |
229 out_credit_note_sequence_id, | 555 out_credit_note_sequence_id, |
230 'in_credit_note_sequence': \ | 556 'in_credit_note_sequence': \ |
231 in_credit_note_sequence_id, | 557 in_credit_note_sequence_id, |
232 }, CONTEXT) | 558 }, context=CONTEXT) |
559 | |
233 cursor.commit() | 560 cursor.commit() |
234 cursor.close() | 561 cursor.close() |
235 | 562 |
236 def test0020createpaymentterm(self): | 563 def test0020createpaymentterm(self): |
237 'Create payment term' | 564 'Create payment term' |
238 cursor = DB.cursor() | 565 cursor = DB.cursor() |
239 payment_term_id = self.payment_term.create(cursor, USER, { | 566 payment_term_id = self.payment_term.create(cursor, USER, { |
240 'name': '20 Days Net', | 567 'name': '20 Days Net', |
241 'lines': [ | 568 'lines': [ |
242 ('create', { | 569 ('create', { |
243 'type': "remainder", | 570 'type': "remainder", |
244 'days': 20, | 571 'days': 20, |
245 'delay': "net_days", | 572 'delay': "net_days", |
246 })]}, CONTEXT) | 573 })]}, context=CONTEXT) |
247 self.assert_(payment_term_id) | 574 self.assert_(payment_term_id) |
248 cursor.commit() | 575 cursor.commit() |
249 cursor.close() | 576 cursor.close() |
250 | 577 |
251 def test0030createinvoiceparty(self): | 578 def test0030createinvoiceparties(self): |
252 'Create invoice party' | 579 'Create invoice parties' |
253 cursor = DB.cursor() | 580 cursor = DB.cursor() |
254 payment_term_id = self.payment_term.search(cursor, USER, [ | 581 payment_term_id = self.payment_term.search(cursor, USER, [ |
255 ('name', '=', '20 Days Net') | 582 ('name', '=', '20 Days Net') |
256 ], 0, 1, None, CONTEXT)[0] | 583 ], offset=0, limit=1, order=None, context=CONTEXT, |
584 count=False)[0] | |
257 self.assert_(payment_term_id) | 585 self.assert_(payment_term_id) |
258 party_id = self.party.create(cursor, USER, { | 586 party_data = [{ |
259 'name': 'Customer domestic', | 587 'name': 'Customer domestic', |
260 'payment_term': payment_term_id, | 588 'payment_term': payment_term_id, |
261 'addresses': [( | 589 'addresses': [( |
262 'create', { | 590 'create', { |
263 'invoice': True, | 591 'invoice': True, |
264 'street': 'Neptunia Street 1', | 592 'street': 'Neptunia Street 1', |
265 'zip': '12345', | 593 'zip': '12345', |
266 'city': 'Tryton-City', | 594 'city': 'Tryton-City', |
267 })] | 595 })] |
268 }, CONTEXT) | 596 }, { |
597 'name': 'Supplier domestic', | |
598 'payment_term': payment_term_id, | |
599 'addresses': [( | |
600 'create', { | |
601 'invoice': True, | |
602 'street': 'Marsfield 26', | |
603 'zip': '44321', | |
604 'city': 'Machine', | |
605 })] | |
606 | |
607 }] | |
608 for party in party_data: | |
609 party_id = self.party.create(cursor, USER, party, context=CONTEXT) | |
610 self.assert_(party_id) | |
611 cursor.commit() | |
612 cursor.close() | |
613 | |
614 def test0040createdraftoutinvoice(self): | |
615 'Create draft out-invoice' | |
616 cursor = DB.cursor() | |
617 company_id = CONTEXT.get('main_company', 1) | |
618 party_id = self.party.search(cursor, USER, [ | |
619 ('name', '=', 'Customer domestic') | |
620 ], offset=0, limit=1, order=None, context=CONTEXT, | |
621 count=False)[0] | |
269 self.assert_(party_id) | 622 self.assert_(party_id) |
270 cursor.commit() | |
271 cursor.close() | |
272 | |
273 def test0040createinvoice(self): | |
274 'Create invoice' | |
275 cursor = DB.cursor() | |
276 company_id = self.company.search(cursor, USER, [ | |
277 ('name', '=', 'ACME'), | |
278 ], 0, 1, None, CONTEXT)[0] | |
279 self.assert_(company_id) | |
280 party_id1 = self.party.search(cursor, USER, [ | |
281 ('name', '=', 'Customer domestic') | |
282 ], 0, 1, None, CONTEXT)[0] | |
283 self.assert_(party_id1) | |
284 currency_id = self.currency.search(cursor, USER, [ | 623 currency_id = self.currency.search(cursor, USER, [ |
285 ('code', '=', 'cu1'), | 624 ('code', '=', 'cu1'), |
286 ], 0, 1, None, CONTEXT)[0] | 625 ], offset=0, limit=1, order=None, context=CONTEXT, |
626 count=False)[0] | |
287 self.assert_(currency_id) | 627 self.assert_(currency_id) |
288 journal_revenue_id = self.journal.search(cursor, USER, [ | 628 journal_revenue_id = self.journal.search(cursor, USER, [ |
289 ('type', '=', 'revenue'), | 629 ('type', '=', 'revenue'), |
290 ], 0, 1, None, CONTEXT)[0] | 630 ], offset=0, limit=1, order=None, context=CONTEXT, |
631 count=False)[0] | |
291 self.assert_(journal_revenue_id) | 632 self.assert_(journal_revenue_id) |
292 payment_term_id = self.payment_term.search(cursor, USER, [ | 633 payment_term_id = self.payment_term.search(cursor, USER, [ |
293 ('name', '=', '20 Days Net'), | 634 ('name', '=', '20 Days Net'), |
294 ], 0, 1, None, CONTEXT)[0] | 635 ], offset=0, limit=1, order=None, context=CONTEXT, |
636 count=False)[0] | |
295 self.assert_(payment_term_id) | 637 self.assert_(payment_term_id) |
296 account_receivable_id = self.party.read(cursor, USER, party_id1, [ | 638 account_receivable_id = self.party.read(cursor, USER, party_id, [ |
297 'account_receivable' | 639 'account_receivable' |
298 ], CONTEXT)['account_receivable'] | 640 ], context=CONTEXT)['account_receivable'] |
299 self.assert_(account_receivable_id) | 641 self.assert_(account_receivable_id) |
300 invoice_address_ids = self.party_address.search(cursor, USER, [ | 642 invoice_address_id = self.party_address.search(cursor, USER, [ |
301 ('invoice', '=', True), | 643 ('invoice', '=', True), |
302 ('party', '=', party_id1) | 644 ('party', '=', party_id) |
303 ], 0, 1, None, CONTEXT) | 645 ], offset=0, limit=1, order=None, context=CONTEXT, |
304 if not invoice_address_ids: | 646 count=False)[0] |
305 invoice_address_id = self.party_address.search(cursor, USER, [ | |
306 ('party', '=', party_id1) | |
307 ], 0, 1, None, CONTEXT)[0] | |
308 else: | |
309 invoice_address_id = invoice_address_ids[0] | |
310 self.assert_(invoice_address_id) | 647 self.assert_(invoice_address_id) |
311 account_revenue_id = self.account.search(cursor, USER, [ | 648 account_revenue_id = self.account.search(cursor, USER, [ |
312 ('name', '=', 'Main Revenue'), | 649 ('name', '=', 'Main Revenue'), |
313 ('company', '=', company_id), | 650 ('company', '=', company_id), |
314 ], 0, 1, None, CONTEXT)[0] | 651 ], offset=0, limit=1, order=None, context=CONTEXT, |
652 count=False)[0] | |
315 self.assert_(account_revenue_id) | 653 self.assert_(account_revenue_id) |
316 | 654 tax_id = self.tax.search(cursor, USER, [ |
655 ('name', '=', 'Received VAT 20%'), | |
656 ('company', '=', company_id), | |
657 ], offset=0, limit=1, order=None, context=CONTEXT, | |
658 count=False)[0] | |
659 self.assert_(tax_id) | |
317 invoice_res = { | 660 invoice_res = { |
318 'type': 'out_invoice', | 661 'type': 'out_invoice', |
319 'party': party_id1, | 662 'party': party_id, |
320 'currency': currency_id, | |
321 'state': 'draft', | |
322 'company': company_id, | 663 'company': company_id, |
323 'journal': journal_revenue_id, | 664 'journal': journal_revenue_id, |
324 'payment_term': payment_term_id, | |
325 'account': account_receivable_id, | 665 'account': account_receivable_id, |
326 'invoice_date': date(2010,03,18), | 666 'invoice_date': date(2010,03,18), |
327 'invoice_address': invoice_address_id, | 667 'invoice_address': invoice_address_id, |
328 'description': 'Domestic Delivery VAT-free', | 668 'description': 'Domestic Sale', |
329 'lines': [( | 669 'lines': [( |
330 'create', { | 670 'create', { |
331 # 'company': company_id, | |
332 'description': 'Premium Birthday Cake', | 671 'description': 'Premium Birthday Cake', |
333 'unit_price': Decimal('100.00'), | 672 'unit_price': Decimal('100.00'), |
673 'account': account_revenue_id, | |
674 'taxes': [('set', [tax_id])], | |
675 'quantity': 1, | |
676 }), ( | |
677 'create', { | |
678 'description': 'Gift Box for Cake', | |
679 'unit_price': Decimal('10.00'), | |
334 'account': account_revenue_id, | 680 'account': account_revenue_id, |
335 'type': 'line', | 681 'type': 'line', |
336 'quantity': 1, | 682 'quantity': 1, |
337 } | 683 } |
338 )] | 684 )] |
339 } | 685 } |
340 invoice_id = self.invoice.create(cursor, USER, invoice_res, CONTEXT) | 686 invoice_id = self.invoice.create(cursor, USER, invoice_res, context=CONT EXT) |
341 self.assert_(invoice_id) | 687 self.assert_(invoice_id) |
342 | 688 |
343 cursor.commit() | 689 cursor.commit() |
344 cursor.close() | 690 cursor.close() |
345 | 691 |
346 def test0050deletedraftinvoicefailure(self): | 692 def test0050deletedraftinvoicefailure(self): |
347 'Workflow: delete a draft invoice not allowed' | 693 'Workflow: delete a draft invoice not allowed' |
348 cursor = DB.cursor() | 694 cursor = DB.cursor() |
349 invoice_id = self.invoice.search(cursor, USER, [ | 695 invoice_id = self.invoice.search(cursor, USER, [ |
350 ('description', '=', 'Domestic Delivery VAT-free'), | 696 ('description', '=', 'Domestic Sale'), |
351 ('state', '=', 'draft'), | 697 ('state', '=', 'draft'), |
352 ], 0, 1, None, CONTEXT)[0] | 698 ], offset=0, limit=1, order=None, context=CONTEXT, |
699 count=False)[0] | |
353 self.assert_(invoice_id) | 700 self.assert_(invoice_id) |
354 | 701 |
355 self.assertRaises(Exception, self.invoice.delete, cursor, USER, | 702 self.assertRaises(Exception, self.invoice.delete, cursor, USER, |
356 invoice_id, CONTEXT) | 703 invoice_id, context=CONTEXT) |
357 cursor.commit() | 704 cursor.commit() |
358 cursor.close() | 705 cursor.close() |
359 | 706 |
360 def test0060canceldeletedraftinvoice(self): | 707 def test0060canceldeletedraftinvoice(self): |
361 'Workflow: cancel draft invoice, then delete' | 708 'Workflow: cancel draft invoice, then delete' |
362 cursor = DB.cursor() | 709 cursor = DB.cursor() |
363 invoice_id = self.invoice.search(cursor, USER, [ | 710 invoice_id = self.invoice.search(cursor, USER, [ |
364 ('description', '=', 'Domestic Delivery VAT-free'), | 711 ('description', '=', 'Domestic Sale'), |
365 ('state', '=', 'draft'), | 712 ('state', '=', 'draft'), |
366 ], 0, 1, None, CONTEXT)[0] | 713 ], offset=0, limit=1, order=None, context=CONTEXT, |
714 count=False)[0] | |
367 self.assert_(invoice_id) | 715 self.assert_(invoice_id) |
368 self.invoice.workflow_trigger_validate(cursor, USER, invoice_id, | 716 self.invoice.workflow_trigger_validate(cursor, USER, invoice_id, |
369 'cancel', CONTEXT) | 717 'cancel', context=CONTEXT) |
370 self.invoice.delete(cursor, USER, invoice_id, CONTEXT) | 718 self.invoice.delete(cursor, USER, invoice_id, context=CONTEXT) |
371 invoice_id_after_delete = self.invoice.search(cursor, USER, [ | 719 invoice_id_after_delete = self.invoice.search(cursor, USER, [ |
372 ('description', '=', 'Domestic Delivery VAT-free'), | 720 ('description', '=', 'Domestic Sale'), |
373 ('state', '=', 'draft'), | 721 ('state', '=', 'draft'), |
374 ], 0, 1, None, CONTEXT) | 722 ], offset=0, limit=1, order=None, context=CONTEXT, |
723 count=False) | |
375 self.assertFalse(invoice_id_after_delete) | 724 self.assertFalse(invoice_id_after_delete) |
376 cursor.rollback() | 725 cursor.rollback() |
377 self.invoice.button_draft(cursor, USER, [invoice_id], CONTEXT) | 726 self.invoice.button_draft(cursor, USER, [invoice_id], context=CONTEXT) |
378 cursor.commit() | 727 cursor.commit() |
379 cursor.close() | 728 cursor.close() |
380 | 729 |
381 def test0070proformainvoice(self): | 730 def test0070proformainvoice(self): |
382 'Workflow: draft-proforma-draft' | 731 'Workflow: draft-proforma-draft' |
383 cursor = DB.cursor() | 732 cursor = DB.cursor() |
384 invoice_id = self.invoice.search(cursor, USER, [ | 733 invoice_id = self.invoice.search(cursor, USER, [ |
385 ('description', '=', 'Domestic Delivery VAT-free'), | 734 ('description', '=', 'Domestic Sale'), |
386 ('state', '=', 'draft'), | 735 ('state', '=', 'draft'), |
387 ], 0, 1, None, CONTEXT)[0] | 736 ], offset=0, limit=1, order=None, context=CONTEXT, |
737 count=False)[0] | |
388 self.assert_(invoice_id) | 738 self.assert_(invoice_id) |
389 | 739 |
390 self.invoice.workflow_trigger_validate(cursor, USER, invoice_id, | 740 self.invoice.workflow_trigger_validate(cursor, USER, invoice_id, |
391 'pro-forma', CONTEXT) | 741 'pro-forma', context=CONTEXT) |
392 self.invoice.workflow_trigger_validate(cursor, USER, invoice_id, | 742 self.invoice.workflow_trigger_validate(cursor, USER, invoice_id, |
393 'draft', CONTEXT) | 743 'draft', context=CONTEXT) |
394 | 744 |
395 cursor.commit() | 745 cursor.commit() |
396 cursor.close() | 746 cursor.close() |
397 | 747 |
398 def test0080openinvoice(self): | 748 def test0080openinvoice(self): |
399 'Workflow: open invoice' | 749 'Workflow: open invoice' |
400 cursor = DB.cursor() | 750 cursor = DB.cursor() |
401 invoice_id = self.invoice.search(cursor, USER, [ | 751 invoice_id = self.invoice.search(cursor, USER, [ |
402 ('description', '=', 'Domestic Delivery VAT-free'), | 752 ('description', '=', 'Domestic Sale'), |
403 ('state', '=', 'draft'), | 753 ('state', '=', 'draft'), |
404 ], 0, 1, None, CONTEXT)[0] | 754 ], offset=0, limit=1, order=None, context=CONTEXT, |
755 count=False)[0] | |
405 self.assert_(invoice_id) | 756 self.assert_(invoice_id) |
406 | 757 |
407 self.invoice.workflow_trigger_validate(cursor, USER, invoice_id, | 758 self.invoice.workflow_trigger_validate(cursor, USER, invoice_id, |
408 'open', CONTEXT) | 759 'open', context=CONTEXT) |
409 cursor.commit() | 760 cursor.commit() |
410 cursor.close() | 761 cursor.close() |
411 | 762 |
412 def test0090canceldeletedraftopeninvoicefailure(self): | 763 def test0090canceldeletedraftopeninvoicefailure(self): |
413 'Workflow: cancel, delete or reset an open invoice not allowed' | 764 'Workflow: cancel, delete or reset an open invoice not allowed' |
414 cursor = DB.cursor() | 765 cursor = DB.cursor() |
415 invoice_id = self.invoice.search(cursor, USER, [ | 766 invoice_id = self.invoice.search(cursor, USER, [ |
416 ('description', '=', 'Domestic Delivery VAT-free'), | 767 ('description', '=', 'Domestic Sale'), |
417 ('state', '=', 'open'), | 768 ('state', '=', 'open'), |
418 ], 0, 1, None, CONTEXT)[0] | 769 ], offset=0, limit=1, order=None, context=CONTEXT, |
770 count=False)[0] | |
419 self.assert_(invoice_id) | 771 self.assert_(invoice_id) |
420 self.invoice.workflow_trigger_validate(cursor, USER, invoice_id, | 772 self.invoice.workflow_trigger_validate(cursor, USER, invoice_id, |
421 'cancel', CONTEXT) | 773 'cancel', context=CONTEXT) |
422 self.assertRaises(Exception, self.invoice.delete, cursor, USER, | 774 self.assertRaises(Exception, self.invoice.delete, cursor, USER, |
423 invoice_id, CONTEXT) | 775 invoice_id, context=CONTEXT) |
424 self.assertRaises(Exception, self.invoice.button_draft, cursor, USER, | 776 self.assertRaises(Exception, self.invoice.button_draft, cursor, USER, |
425 [invoice_id], CONTEXT) | 777 [invoice_id], context=CONTEXT) |
426 cursor.commit() | 778 cursor.commit() |
427 cursor.close() | 779 cursor.close() |
428 | 780 |
429 def test0100partialpayopeninvoice(self): | 781 def test0100partialpayopeninvoice(self): |
430 'Partial payment of open invoice' | 782 'Partial payment of open invoice' |
431 cursor = DB.cursor() | 783 cursor = DB.cursor() |
432 invoice_id = self.invoice.search(cursor, USER, [ | 784 invoice_id = self.invoice.search(cursor, USER, [ |
433 ('description', '=', 'Domestic Delivery VAT-free'), | 785 ('description', '=', 'Domestic Sale'), |
434 ('state', '=', 'open'), | 786 ('state', '=', 'open'), |
435 ], 0, 1, None, CONTEXT)[0] | 787 ], offset=0, limit=1, order=None, context=CONTEXT, |
788 count=False)[0] | |
436 self.assert_(invoice_id) | 789 self.assert_(invoice_id) |
437 journal_cash_id = self.journal.search(cursor, USER, [ | 790 journal_cash_id = self.journal.search(cursor, USER, [ |
438 ('type', '=', 'cash'), | 791 ('type', '=', 'cash'), |
439 ], 0, 1, None, CONTEXT)[0] | 792 ], offset=0, limit=1, order=None, context=CONTEXT, |
793 count=False)[0] | |
440 self.assert_(journal_cash_id) | 794 self.assert_(journal_cash_id) |
441 currency_id = self.currency.search(cursor, USER, [ | 795 currency_id = self.currency.search(cursor, USER, [ |
442 ('code', '=', 'cu1'), | 796 ('code', '=', 'cu1'), |
443 ], 0, 1, None, CONTEXT)[0] | 797 ], offset=0, limit=1, order=None, context=CONTEXT, |
798 count=False)[0] | |
444 self.assert_(currency_id) | 799 self.assert_(currency_id) |
445 # establish create wizard | 800 # establish create wizard |
446 create_invoice_pay_obj = POOL.get( | 801 create_invoice_pay_obj = POOL.get( |
447 'account.invoice.pay_invoice', type='wizard') | 802 'account.invoice.pay_invoice', type='wizard') |
448 wizard_id = create_invoice_pay_obj.create(cursor, USER) | 803 wizard_id = create_invoice_pay_obj.create(cursor, USER) |
449 cursor.commit() | 804 cursor.commit() |
450 form_data = { | 805 form_data = { |
451 'description': 'Partial Payment', | 806 'description': 'Partial Payment', |
452 'journal': journal_cash_id, | 807 'journal': journal_cash_id, |
453 'currency': currency_id, | 808 'currency': currency_id, |
454 'currency_digits': 2, | 809 'currency_digits': 2, |
455 'amount': Decimal('50.0'), | 810 'amount': Decimal('50.0'), |
456 'date': date(2010,03,28), | 811 'date': date(2010,03,20), |
457 } | 812 } |
458 # execute step one | 813 # execute step one |
459 create_invoice_pay_obj.execute(cursor, USER, wizard_id, { | 814 create_invoice_pay_obj.execute(cursor, USER, wizard_id, { |
460 'model': 'account.invoice', | 815 'model': 'account.invoice', |
461 'id': invoice_id, | 816 'id': invoice_id, |
462 'form': form_data, | 817 'form': form_data, |
463 }, 'choice', CONTEXT) | 818 }, 'choice', context=CONTEXT) |
464 cursor.commit() | 819 cursor.commit() |
465 form_data['type'] = 'partial' | 820 form_data['type'] = 'partial' |
466 | 821 |
467 # execute step two | 822 # execute step two |
468 create_invoice_pay_obj.execute(cursor, USER, wizard_id, { | 823 create_invoice_pay_obj.execute(cursor, USER, wizard_id, { |
469 'model': 'account.invoice', | 824 'model': 'account.invoice', |
470 'id': invoice_id, | 825 'id': invoice_id, |
471 'form': form_data, | 826 'form': form_data, |
472 }, 'pay', CONTEXT) | 827 }, 'pay', context=CONTEXT) |
473 cursor.commit() | 828 cursor.commit() |
474 # delete wizard | 829 # delete wizard |
475 create_invoice_pay_obj.delete(cursor, USER, wizard_id) | 830 create_invoice_pay_obj.delete(cursor, USER, wizard_id) |
476 cursor.commit() | 831 cursor.commit() |
477 cursor.close() | 832 cursor.close() |
478 | 833 |
479 def test0110overpayopeninvoice(self): | 834 def test0110payopeninvoice(self): |
480 'Over payment of open invoice' | 835 'Over payment of open invoice' |
481 cursor = DB.cursor() | 836 cursor = DB.cursor() |
482 company_id = self.company.search(cursor, USER, [ | 837 company_id = CONTEXT.get('main_company', 1) |
483 ('name', '=', 'ACME'), | |
484 ], 0, 1, None, CONTEXT)[0] | |
485 self.assert_(company_id) | |
486 invoice_id = self.invoice.search(cursor, USER, [ | 838 invoice_id = self.invoice.search(cursor, USER, [ |
487 ('description', '=', 'Domestic Delivery VAT-free'), | 839 ('description', '=', 'Domestic Sale'), |
488 ('state', '=', 'open'), | 840 ('state', '=', 'open'), |
489 ], 0, 1, None, CONTEXT)[0] | 841 ], offset=0, limit=1, order=None, context=CONTEXT, |
842 count=False)[0] | |
490 self.assert_(invoice_id) | 843 self.assert_(invoice_id) |
491 journal_cash_id = self.journal.search(cursor, USER, [ | 844 journal_cash_id = self.journal.search(cursor, USER, [ |
492 ('type', '=', 'cash'), | 845 ('type', '=', 'cash'), |
493 ], 0, 1, None, CONTEXT)[0] | 846 ], offset=0, limit=1, order=None, context=CONTEXT, |
847 count=False)[0] | |
494 self.assert_(journal_cash_id) | 848 self.assert_(journal_cash_id) |
495 journal_revenue_id = self.journal.search(cursor, USER, [ | 849 journal_revenue_id = self.journal.search(cursor, USER, [ |
496 ('type', '=', 'revenue'), | 850 ('type', '=', 'revenue'), |
497 ], 0, 1, None, CONTEXT)[0] | 851 ], offset=0, limit=1, order=None, context=CONTEXT, |
852 count=False)[0] | |
498 self.assert_(journal_cash_id) | 853 self.assert_(journal_cash_id) |
499 account_revenue_id = self.account.search(cursor, USER, [ | 854 account_revenue_id = self.account.search(cursor, USER, [ |
500 ('name', '=', 'Main Revenue'), | 855 ('name', '=', 'Main Revenue'), |
501 ('company', '=', company_id), | 856 ('company', '=', company_id), |
502 ], 0, 1, None, CONTEXT)[0] | 857 ], offset=0, limit=1, order=None, context=CONTEXT, |
858 count=False)[0] | |
503 self.assert_(account_revenue_id) | 859 self.assert_(account_revenue_id) |
504 | 860 |
505 currency_id = self.currency.search(cursor, USER, [ | 861 currency_id = self.currency.search(cursor, USER, [ |
506 ('code', '=', 'cu1'), | 862 ('code', '=', 'cu1'), |
507 ], 0, 1, None, CONTEXT)[0] | 863 ], offset=0, limit=1, order=None, context=CONTEXT, |
864 count=False)[0] | |
508 self.assert_(currency_id) | 865 self.assert_(currency_id) |
509 # establish create wizard | 866 # establish create wizard |
510 create_invoice_pay_obj = POOL.get( | 867 create_invoice_pay_obj = POOL.get( |
511 'account.invoice.pay_invoice', type='wizard') | 868 'account.invoice.pay_invoice', type='wizard') |
512 wizard_id = create_invoice_pay_obj.create(cursor, USER) | 869 wizard_id = create_invoice_pay_obj.create(cursor, USER) |
513 cursor.commit() | 870 cursor.commit() |
514 form_data = { | 871 data_step1 = { |
515 'description': 'Partial Payment', | |
516 'journal': journal_cash_id, | |
517 'currency': currency_id, | |
518 'currency_digits': 2, | |
519 'amount': Decimal('100.0'), | |
520 'date': date(2010,03,28), | |
521 } | |
522 # execute step one | |
523 create_invoice_pay_obj.execute(cursor, USER, wizard_id, { | |
524 'model': 'account.invoice', | 872 'model': 'account.invoice', |
525 'id': invoice_id, | 873 'id': invoice_id, |
526 'form': form_data, | 874 'form': { |
527 }, 'choice', CONTEXT) | 875 'description': 'Partial Payment', |
528 cursor.commit() | 876 'journal': journal_cash_id, |
529 form_data['type'] = 'writeoff' | 877 'currency': currency_id, |
530 form_data['account_writeoff'] = account_revenue_id | 878 'currency_digits': 2, |
531 form_data['journal_writeoff'] = journal_revenue_id | 879 'amount': Decimal('80.0'), |
532 form_data['amount_writeoff'] = Decimal('-50.0') | 880 'date': date(2010,03,28), |
533 form_data['currency_digits_writeoff'] = 2 | 881 }} |
534 # execute step two | 882 # execute step one |
535 create_invoice_pay_obj.execute(cursor, USER, wizard_id, { | 883 result_step1 = create_invoice_pay_obj.execute(cursor, USER, wizard_id, |
536 'model': 'account.invoice', | 884 data_step1, 'choice', context=CONTEXT) |
537 'id': invoice_id, | |
538 'form': form_data, | |
539 }, 'pay', CONTEXT) | |
540 cursor.commit() | 885 cursor.commit() |
541 # delete wizard | 886 # delete wizard |
542 create_invoice_pay_obj.delete(cursor, USER, wizard_id) | 887 create_invoice_pay_obj.delete(cursor, USER, wizard_id) |
543 cursor.commit() | 888 cursor.commit() |
544 cursor.close() | 889 cursor.close() |
545 | 890 |
546 def test0120checkbalance(self): | 891 def test0120checkbalance(self): |
547 # Unsure if this test is useful | 892 # Unsure if this test is useful |
548 'Check balance' | 893 'Check balance' |
549 cursor = DB.cursor() | 894 cursor = DB.cursor() |
550 company_id = self.company.search(cursor, USER, [ | 895 company_id = CONTEXT.get('main_company', 1) |
551 ('name', '=', 'ACME'), | 896 amount = ZERO |
552 ], 0, 1, None, CONTEXT)[0] | 897 root_type_ids = self.account_type.search(cursor, USER, [ |
553 self.assert_(company_id) | 898 ('name', 'in', ['Asset', 'Liability', 'Equity']), |
554 all_account_ids = self.account.search(cursor, USER, [ | 899 ('company', '=', company_id), |
555 ('company', '=', company_id), | 900 ], offset=0, limit=None, order=None, context=CONTEXT, |
556 ], 0, None, None, CONTEXT) | 901 count=False) |
557 self.assert_(all_account_ids) | 902 self.assert_(root_type_ids) |
558 balance_amounts = self.account.get_balance(cursor, USER, all_account_ids , | 903 balances = self.account_type.get_amount(cursor, USER, |
559 CONTEXT) | 904 root_type_ids, name=None, context=CONTEXT) |
560 amount = Decimal('0.0') | 905 for id in balances: |
561 for key in balance_amounts: | 906 amount += balances[id] |
562 amount += balance_amounts[key] | 907 |
563 self.assert_(amount == Decimal('0.0')) | 908 if amount != ZERO: |
564 cursor.commit() | 909 cursor.commit() |
565 cursor.close() | 910 cursor.close() |
566 | 911 self.fail("Unbalanced Ledger! Decimal('0.0') %s %s" % ( |
567 def test0130checkcopy(self): | 912 (amount > ZERO and '>' or '<'), amount)) |
568 'Invoice copy' | 913 |
569 cursor = DB.cursor() | 914 cursor.commit() |
570 company_id = self.company.search(cursor, USER, [ | 915 cursor.close() |
571 ('name', '=', 'ACME'), | 916 |
572 ], 0, 1, None, CONTEXT)[0] | 917 def test0130copyinvoice(self): |
918 'Copy Invoice' | |
919 cursor = DB.cursor() | |
920 company_id = CONTEXT.get('main_company', 1) | |
573 original_invoice_id = self.invoice.search(cursor, USER, [ | 921 original_invoice_id = self.invoice.search(cursor, USER, [ |
574 ('description', '=', 'Domestic Delivery VAT-free'), | 922 ('description', '=', 'Domestic Sale'), |
575 ('state', '=', 'paid'), | 923 ('state', '=', 'paid'), |
576 ], 0, 1, None, CONTEXT)[0] | 924 ], offset=0, limit=1, order=None, context=CONTEXT, |
925 count=False)[0] | |
577 self.assert_(original_invoice_id) | 926 self.assert_(original_invoice_id) |
578 copied_invoice_id = self.invoice.copy(cursor, USER, | 927 copied_invoice_id = self.invoice.copy(cursor, USER, |
579 original_invoice_id, CONTEXT) | 928 original_invoice_id, context=CONTEXT) |
580 self.assert_(copied_invoice_id) | 929 self.assert_(copied_invoice_id) |
581 readed_invoice_ids = self.invoice.search(cursor, USER, [ | 930 readed_invoice_ids = self.invoice.search(cursor, USER, [ |
582 ('description', '=', 'Domestic Delivery VAT-free'), | 931 ('description', '=', 'Domestic Sale'), |
583 ('state', '=', 'draft'), | 932 ('state', '=', 'draft'), |
584 ('company', '=', company_id), | 933 ('company', '=', company_id), |
585 ], 0, None, None, CONTEXT) | 934 ], 0, None, None, context=CONTEXT) |
586 self.assert_(len(readed_invoice_ids) == 1) | 935 self.assert_(len(readed_invoice_ids) == 1) |
587 self.assert_(readed_invoice_ids[0] == copied_invoice_id) | 936 self.assert_(readed_invoice_ids[0] == copied_invoice_id) |
937 cursor.commit() | |
938 cursor.close() | |
939 | |
940 def test0140createopenininvoice(self): | |
941 'Create and open in-invoice' | |
942 cursor = DB.cursor() | |
943 company_id = CONTEXT.get('main_company', 1) | |
944 party_id = self.party.search(cursor, USER, [ | |
945 ('name', '=', 'Supplier domestic') | |
946 ], offset=0, limit=1, order=None, context=CONTEXT, | |
947 count=False)[0] | |
948 self.assert_(party_id) | |
949 invoice_address_id = self.party_address.search(cursor, USER, [ | |
950 ('invoice', '=', True), | |
951 ('party', '=', party_id) | |
952 ], offset=0, limit=1, order=None, context=CONTEXT, | |
953 count=False)[0] | |
954 self.assert_(invoice_address_id) | |
955 currency_id = self.currency.search(cursor, USER, [ | |
956 ('code', '=', 'cu1'), | |
957 ], offset=0, limit=1, order=None, context=CONTEXT, | |
958 count=False)[0] | |
959 self.assert_(currency_id) | |
960 journal_expense_id = self.journal.search(cursor, USER, [ | |
961 ('type', '=', 'expense'), | |
962 ], offset=0, limit=1, order=None, context=CONTEXT, | |
963 count=False)[0] | |
964 self.assert_(journal_expense_id) | |
965 payment_term_id = self.payment_term.search(cursor, USER, [ | |
966 ('name', '=', '20 Days Net'), | |
967 ], offset=0, limit=1, order=None, context=CONTEXT, | |
968 count=False)[0] | |
969 self.assert_(payment_term_id) | |
970 account_payable_id = self.party.read(cursor, USER, party_id, [ | |
971 'account_payable' | |
972 ], context=CONTEXT)['account_payable'] | |
973 self.assert_(account_payable_id) | |
974 account_expense_id = self.account.search(cursor, USER, [ | |
975 ('name', '=', 'Main Expense'), | |
976 ('company', '=', company_id), | |
977 ], offset=0, limit=1, order=None, context=CONTEXT, | |
978 count=False)[0] | |
979 self.assert_(account_expense_id) | |
980 tax_id = self.tax.search(cursor, USER, [ | |
981 ('name', '=', 'Paid VAT 20%'), | |
982 ('company', '=', company_id), | |
983 ], offset=0, limit=1, order=None, context=CONTEXT, | |
984 count=False)[0] | |
985 self.assert_(tax_id) | |
986 | |
987 invoice_res = { | |
988 'type': 'in_invoice', | |
989 'party': party_id, | |
990 'company': company_id, | |
991 'journal': journal_expense_id, | |
992 'account': account_payable_id, | |
993 'invoice_date': date(2010,02,10), | |
994 'invoice_address': invoice_address_id, | |
995 'description': 'Domestic Purchase', | |
996 'lines': [( | |
997 'create', { | |
998 'description': 'Premium Birthday Cake', | |
999 'unit_price': Decimal('80.00'), | |
1000 'taxes': [('set', [tax_id])], | |
1001 'account': account_expense_id, | |
1002 'quantity': 1, | |
1003 }), ( | |
1004 'create', { | |
1005 'description': 'Gift Box for Cake', | |
1006 'unit_price': Decimal('1.00'), | |
1007 'account': account_expense_id, | |
1008 'type': 'line', | |
1009 'quantity': 1, | |
1010 } | |
1011 )] | |
1012 } | |
1013 invoice_id = self.invoice.create(cursor, USER, invoice_res, context=CONT EXT) | |
1014 self.assert_(invoice_id) | |
1015 self.invoice.workflow_trigger_validate(cursor, USER, invoice_id, | |
1016 'open', context=CONTEXT) | |
588 cursor.commit() | 1017 cursor.commit() |
589 cursor.close() | 1018 cursor.close() |
590 | 1019 |
591 def suite(): | 1020 def suite(): |
592 suite = trytond.tests.test_tryton.suite() | 1021 suite = trytond.tests.test_tryton.suite() |
593 suite.debug() | 1022 suite.debug() |
594 from trytond.modules.currency.tests import test_currency | 1023 from trytond.modules.currency.tests import test_currency |
595 for test in test_currency.suite(): | 1024 for test in test_currency.suite(): |
596 if test not in suite: | 1025 if test not in suite: |
597 suite.addTest(test) | 1026 suite.addTest(test) |
598 | 1027 |
599 suite.addTests(unittest.TestLoader().loadTestsFromTestCase( | 1028 suite.addTests(unittest.TestLoader().loadTestsFromTestCase( |
600 AccountTestCase)) | 1029 AccountTestCase)) |
601 suite.addTests(unittest.TestLoader().loadTestsFromTestCase( | 1030 suite.addTests(unittest.TestLoader().loadTestsFromTestCase( |
602 AccountInvoiceTestCase)) | 1031 AccountInvoiceTestCase)) |
603 | 1032 |
604 return suite | 1033 return suite |
605 | 1034 |
606 if __name__ == '__main__': | 1035 if __name__ == '__main__': |
607 unittest.TextTestRunner(verbosity=2).run(suite()) | 1036 unittest.TextTestRunner(verbosity=2).run(suite()) |
LEFT | RIGHT |