Debian Codegraph @

addons/point_of_sale/tests/test_pos_with_fiscal_position.py

raw
1 # -*- coding: utf-8 -*-
2 # Part of Odoo. See LICENSE file for full copyright and licensing details.
3
4 from odoo import Command
5 import odoo
6 from odoo.addons.point_of_sale.tests.common import TestPoSCommon
7
8 @odoo.tests.tagged('post_install', '-at_install')
9 class TestPoSWithFiscalPosition(TestPoSCommon):
10 """ Tests to pos orders with fiscal position.
11
12 keywords/phrases: fiscal position
13 """
14
15 @classmethod
16 def setUpClass(cls):
17 super(TestPoSWithFiscalPosition, cls).setUpClass()
18
19 cls.config = cls.basic_config
20 cls.company.tax_calculation_rounding_method = 'round_per_line'
21
22 cls.new_tax_17 = cls.env['account.tax'].create({'name': 'New Tax 17%', 'amount': 17})
23 cls.new_tax_17.invoice_repartition_line_ids.write({'account_id': cls.tax_received_account.id})
24
25 cls.fpos = cls._create_fiscal_position()
26 cls.fpos_no_tax_dest = cls._create_fiscal_position_no_tax_dest()
27
28 cls.product1 = cls.create_product(
29 'Product 1',
30 cls.categ_basic,
31 lst_price=10.99,
32 standard_price=5.0,
33 tax_ids=cls.taxes['tax7'].ids,
34 )
35 cls.product2 = cls.create_product(
36 'Product 2',
37 cls.categ_basic,
38 lst_price=19.99,
39 standard_price=10.0,
40 tax_ids=cls.taxes['tax10'].ids,
41 )
42 cls.product3 = cls.create_product(
43 'Product 3',
44 cls.categ_basic,
45 lst_price=30.99,
46 standard_price=15.0,
47 tax_ids=cls.taxes['tax7'].ids,
48 )
49 cls.adjust_inventory([cls.product1, cls.product2, cls.product3], [100, 50, 50])
50
51 @classmethod
52 def _create_fiscal_position(cls):
53 fpos = cls.env['account.fiscal.position'].create({'name': 'Test Fiscal Position'})
54
55 account_fpos = cls.env['account.fiscal.position.account'].create({
56 'position_id': fpos.id,
57 'account_src_id': cls.sale_account.id,
58 'account_dest_id': cls.other_sale_account.id,
59 })
60 fpos.write({
61 'account_ids': [(6, 0, account_fpos.ids)],
62 })
63 cls.new_tax_17.write({
64 'fiscal_position_ids': [Command.link(fpos.id)],
65 'original_tax_ids': [Command.link(cls.taxes['tax7'].id)],
66 })
67 return fpos
68
69 @classmethod
70 def _create_fiscal_position_no_tax_dest(cls):
71 fpos_no_tax_dest = cls.env['account.fiscal.position'].create({'name': 'Test Fiscal Position'})
72 account_fpos = cls.env['account.fiscal.position.account'].create({
73 'position_id': fpos_no_tax_dest.id,
74 'account_src_id': cls.sale_account.id,
75 'account_dest_id': cls.other_sale_account.id,
76 })
77 fpos_no_tax_dest.write({
78 'account_ids': [(6, 0, account_fpos.ids)],
79 })
80 cls.env['account.tax'].create({
81 'name': 'Exempt',
82 'amount': 0,
83 'fiscal_position_ids': [Command.link(fpos_no_tax_dest.id)],
84 'original_tax_ids': [Command.link(cls.taxes['tax7'].id)],
85 })
86 return fpos_no_tax_dest
87
88 def test_01_no_invoice_fpos(self):
89 """ orders without invoice
90
91 Orders
92 ======
93 +---------+----------+---------------+----------+-----+---------+-----------------+--------+
94 | order | payments | invoiced? | product | qty | untaxed | tax | total |
95 +---------+----------+---------------+----------+-----+---------+-----------------+--------+
96 | order 1 | cash | yes, customer | product1 | 10 | 109.90 | 18.68 [7%->17%] | 128.58 |
97 | | | | product2 | 10 | 181.73 | 18.17 [10%] | 199.90 |
98 | | | | product3 | 10 | 309.90 | 52.68 [7%->17%] | 362.58 |
99 +---------+----------+---------------+----------+-----+---------+-----------------+--------+
100 | order 2 | cash | yes, customer | product1 | 5 | 54.95 | 9.34 [7%->17%] | 64.29 |
101 | | | | product2 | 5 | 90.86 | 9.09 [10%] | 99.95 |
102 +---------+----------+---------------+----------+-----+---------+-----------------+--------+
103 | order 3 | bank | no | product2 | 5 | 90.86 | 9.09 [10%] | 99.95 |
104 | | | | product3 | 5 | 154.95 | 10.85 [7%] | 165.8 |
105 +---------+----------+---------------+----------+-----+---------+-----------------+--------+
106
107 Expected Result
108 ===============
109 +---------------------+---------+
110 | account | balance |
111 +---------------------+---------+
112 | sale_account | -154.95 | (for the 7% base amount)
113 | sale_account | -90.86 | (for the 10% base amount)
114 | other_sale_account | -474.75 | (for the 17% base amount)
115 | other_sale_account | -272.59 | (for the 10% base amount)
116 | tax 17% | -80.70 |
117 | tax 10% | -36.35 |
118 | tax 7% | -10.85 |
119 | pos receivable bank | 265.75 |
120 | pos receivable cash | 855.30 |
121 +---------------------+---------+
122 | Total balance | 0.0 |
123 +---------------------+---------+
124 """
125
126 self.customer.write({'property_account_position_id': self.fpos.id})
127
128 def _before_closing_cb():
129 # check values before closing the session
130 self.assertEqual(3, self.pos_session.order_count)
131 orders_total = sum(order.amount_total for order in self.pos_session.order_ids)
132 self.assertAlmostEqual(orders_total, self.pos_session.total_payments_amount, msg='Total order amount should be equal to the total payment amount.')
133
134 self._run_test({
135 'payment_methods': self.cash_pm1 | self.bank_pm1,
136 'orders': [
137 {'pos_order_lines_ui_args': [(self.product1, 10), (self.product2, 10), (self.product3, 10)], 'customer': self.customer, 'uuid': '00100-010-0001'},
138 {'pos_order_lines_ui_args': [(self.product1, 5), (self.product2, 5)], 'customer': self.customer, 'uuid': '00100-010-0002'},
139 {'pos_order_lines_ui_args': [(self.product2, 5), (self.product3, 5)], 'payments': [(self.bank_pm1, 265.75)], 'uuid': '00100-010-0003'},
140 ],
141 'before_closing_cb': _before_closing_cb,
142 'journal_entries_before_closing': {},
143 'journal_entries_after_closing': {
144 'session_journal_entry': {
145 'line_ids': [
146 {'account_id': self.tax_received_account.id, 'partner_id': False, 'debit': 0, 'credit': 80.70, 'reconciled': False},
147 {'account_id': self.tax_received_account.id, 'partner_id': False, 'debit': 0, 'credit': 36.35, 'reconciled': False},
148 {'account_id': self.tax_received_account.id, 'partner_id': False, 'debit': 0, 'credit': 10.85, 'reconciled': False},
149 {'account_id': self.other_sale_account.id, 'partner_id': False, 'debit': 0, 'credit': 474.75, 'reconciled': False},
150 {'account_id': self.other_sale_account.id, 'partner_id': False, 'debit': 0, 'credit': 272.59, 'reconciled': False},
151 {'account_id': self.sales_account.id, 'partner_id': False, 'debit': 0, 'credit': 90.86, 'reconciled': False},
152 {'account_id': self.sales_account.id, 'partner_id': False, 'debit': 0, 'credit': 154.95, 'reconciled': False},
153 {'account_id': self.bank_pm1.receivable_account_id.id, 'partner_id': False, 'debit': 265.75, 'credit': 0, 'reconciled': True},
154 {'account_id': self.cash_pm1.receivable_account_id.id, 'partner_id': False, 'debit': 855.30, 'credit': 0, 'reconciled': True},
155 ],
156 },
157 'cash_statement': [
158 ((855.30, ), {
159 'line_ids': [
160 {'account_id': self.cash_pm1.journal_id.default_account_id.id, 'partner_id': False, 'debit': 855.30, 'credit': 0, 'reconciled': False},
161 {'account_id': self.cash_pm1.receivable_account_id.id, 'partner_id': False, 'debit': 0, 'credit': 855.30, 'reconciled': True},
162 ]
163 }),
164 ],
165 'bank_payments': [
166 ((265.75, ), {
167 'line_ids': [
168 {'account_id': self.bank_pm1.outstanding_account_id.id, 'partner_id': False, 'debit': 265.75, 'credit': 0, 'reconciled': False},
169 {'account_id': self.bank_pm1.receivable_account_id.id, 'partner_id': False, 'debit': 0, 'credit': 265.75, 'reconciled': True},
170 ]
171 }),
172 ],
173 },
174 })
175
176 def test_02_no_invoice_fpos_no_tax_dest(self):
177 """ Customer with fiscal position that maps a tax to no tax.
178
179 Orders
180 ======
181 +---------+----------+---------------+----------+-----+---------+-------------+--------+
182 | order | payments | invoiced? | product | qty | untaxed | tax | total |
183 +---------+----------+---------------+----------+-----+---------+-------------+--------+
184 | order 1 | bank | yes, customer | product1 | 10 | 109.90 | 0 | 109.90 |
185 | | | | product2 | 10 | 181.73 | 18.17 [10%] | 199.90 |
186 | | | | product3 | 10 | 309.90 | 0 | 309.90 |
187 +---------+----------+---------------+----------+-----+---------+-------------+--------+
188 | order 2 | cash | yes, customer | product1 | 5 | 54.95 | 0 | 54.95 |
189 | | | | product2 | 5 | 90.86 | 9.09 [10%] | 99.95 |
190 +---------+----------+---------------+----------+-----+---------+-------------+--------+
191 | order 3 | bank | no | product2 | 5 | 90.86 | 9.09 [10%] | 99.95 |
192 | | | | product3 | 5 | 154.95 | 10.85 [7%] | 165.80 |
193 +---------+----------+---------------+----------+-----+---------+-------------+--------+
194
195 Expected Result
196 ===============
197 +---------------------+---------+
198 | account | balance |
199 +---------------------+---------+
200 | sale_account | -154.95 | (for the 7% base amount)
201 | sale_account | -90.86 | (for the 10% base amount)
202 | other_sale_account | -272.59 | (for the 10% base amount)
203 | other_sale_account | -474.75 | (no tax)
204 | tax 10% | -36.35 |
205 | tax 7% | -10.85 |
206 | pos receivable bank | 885.45 |
207 | pos receivable cash | 154.9 |
208 +---------------------+---------+
209 | Total balance | 0.0 |
210 +---------------------+---------+
211 """
212
213 self.customer.write({'property_account_position_id': self.fpos_no_tax_dest.id})
214
215 def _before_closing_cb():
216 # check values before closing the session
217 self.assertEqual(3, self.pos_session.order_count)
218 orders_total = sum(order.amount_total for order in self.pos_session.order_ids)
219 self.assertAlmostEqual(orders_total, self.pos_session.total_payments_amount, msg='Total order amount should be equal to the total payment amount.')
220
221 self._run_test({
222 'payment_methods': self.cash_pm1 | self.bank_pm1,
223 'orders': [
224 {'pos_order_lines_ui_args': [(self.product1, 10), (self.product2, 10), (self.product3, 10)], 'payments': [(self.bank_pm1, 619.7)], 'customer': self.customer, 'uuid': '00100-010-0001'},
225 {'pos_order_lines_ui_args': [(self.product1, 5), (self.product2, 5)], 'customer': self.customer, 'uuid': '00100-010-0002'},
226 {'pos_order_lines_ui_args': [(self.product2, 5), (self.product3, 5)], 'payments': [(self.bank_pm1, 265.75)], 'uuid': '00100-010-0003'},
227 ],
228 'before_closing_cb': _before_closing_cb,
229 'journal_entries_before_closing': {},
230 'journal_entries_after_closing': {
231 'session_journal_entry': {
232 'line_ids': [
233 {'account_id': self.tax_received_account.id, 'partner_id': False, 'debit': 0, 'credit': 36.35, 'reconciled': False},
234 {'account_id': self.tax_received_account.id, 'partner_id': False, 'debit': 0, 'credit': 10.85, 'reconciled': False},
235 {'account_id': self.other_sale_account.id, 'partner_id': False, 'debit': 0, 'credit': 474.75, 'reconciled': False},
236 {'account_id': self.other_sale_account.id, 'partner_id': False, 'debit': 0, 'credit': 272.59, 'reconciled': False},
237 {'account_id': self.sales_account.id, 'partner_id': False, 'debit': 0, 'credit': 90.86, 'reconciled': False},
238 {'account_id': self.sales_account.id, 'partner_id': False, 'debit': 0, 'credit': 154.95, 'reconciled': False},
239 {'account_id': self.bank_pm1.receivable_account_id.id, 'partner_id': False, 'debit': 885.45, 'credit': 0, 'reconciled': True},
240 {'account_id': self.cash_pm1.receivable_account_id.id, 'partner_id': False, 'debit': 154.9, 'credit': 0, 'reconciled': True},
241 ],
242 },
243 'cash_statement': [
244 ((154.9, ), {
245 'line_ids': [
246 {'account_id': self.cash_pm1.journal_id.default_account_id.id, 'partner_id': False, 'debit': 154.9, 'credit': 0, 'reconciled': False},
247 {'account_id': self.cash_pm1.receivable_account_id.id, 'partner_id': False, 'debit': 0, 'credit': 154.9, 'reconciled': True},
248 ]
249 }),
250 ],
251 'bank_payments': [
252 ((885.45, ), {
253 'line_ids': [
254 {'account_id': self.bank_pm1.outstanding_account_id.id, 'partner_id': False, 'debit': 885.45, 'credit': 0, 'reconciled': False},
255 {'account_id': self.bank_pm1.receivable_account_id.id, 'partner_id': False, 'debit': 0, 'credit': 885.45, 'reconciled': True},
256 ]
257 }),
258 ],
259 },
260 })
261
262 def test_03_invoiced_fpos(self):
263 """ Invoice 2 orders.
264
265 Orders
266 ======
267 +---------+----------+---------------------+----------+-----+---------+-----------------+--------+
268 | order | payments | invoiced? | product | qty | untaxed | tax | total |
269 +---------+----------+---------------------+----------+-----+---------+-----------------+--------+
270 | order 1 | bank | yes, customer | product1 | 10 | 109.90 | 18.68 [7%->17%] | 128.58 |
271 | | | | product2 | 10 | 181.73 | 18.17 [10%] | 199.90 |
272 | | | | product3 | 10 | 309.90 | 52.68 [7%->17%] | 362.58 |
273 +---------+----------+---------------------+----------+-----+---------+-----------------+--------+
274 | order 2 | cash | no, customer | product1 | 5 | 54.95 | 9.34 [7%->17%] | 64.29 |
275 | | | | product2 | 5 | 90.86 | 9.09 [10%] | 99.95 |
276 +---------+----------+---------------------+----------+-----+---------+-----------------+--------+
277 | order 3 | cash | yes, other_customer | product2 | 5 | 90.86 | 9.09 [10%] | 99.95 |
278 | | | | product3 | 5 | 154.95 | 10.85 [7%] | 165.80 |
279 +---------+----------+---------------------+----------+-----+---------+-----------------+--------+
280
281 Expected Result
282 ===============
283 +---------------------+---------+
284 | account | balance |
285 +---------------------+---------+
286 | other_sale_account | -54.95 | (for the 17% base amount)
287 | other_sale_account | -90.86 | (for the 10% base amount)
288 | tax 10% | -9.09 |
289 | tax 17% | -9.34 |
290 | pos receivable cash | 429.99 |
291 | pos receivable bank | 691.06 |
292 | receivable | -691.06 |
293 | other receivable | -265.75 |
294 +---------------------+---------+
295 | Total balance | 0.0 |
296 +---------------------+---------+
297 """
298
299 self.customer.write({'property_account_position_id': self.fpos.id})
300
301 def _before_closing_cb():
302 # check values before closing the session
303 self.assertEqual(3, self.pos_session.order_count)
304 orders_total = sum(order.amount_total for order in self.pos_session.order_ids)
305 self.assertAlmostEqual(orders_total, self.pos_session.total_payments_amount, msg='Total order amount should be equal to the total payment amount.')
306
307 invoiced_order_1 = self.pos_session.order_ids.filtered(lambda order: '00100-010-0001' in order.uuid)
308 invoiced_order_2 = self.pos_session.order_ids.filtered(lambda order: '00100-010-0003' in order.uuid)
309
310 self.assertTrue(invoiced_order_1, msg='Invoiced order 1 should exist.')
311 self.assertTrue(invoiced_order_2, msg='Invoiced order 2 should exist.')
312 self.assertTrue(invoiced_order_1.account_move, msg='Invoiced order 1 should have invoice (account_move).')
313 self.assertTrue(invoiced_order_2.account_move, msg='Invoiced order 2 should have invoice (account_move).')
314
315 self._run_test({
316 'payment_methods': self.cash_pm1 | self.bank_pm1,
317 'orders': [
318 {'pos_order_lines_ui_args': [(self.product1, 10), (self.product2, 10), (self.product3, 10)], 'payments': [(self.bank_pm1, 691.06)], 'customer': self.customer, 'is_invoiced': True, 'uuid': '00100-010-0001'},
319 {'pos_order_lines_ui_args': [(self.product1, 5), (self.product2, 5)], 'customer': self.customer, 'uuid': '00100-010-0002'},
320 {'pos_order_lines_ui_args': [(self.product2, 5), (self.product3, 5)], 'customer': self.other_customer, 'is_invoiced': True, 'uuid': '00100-010-0003'},
321 ],
322 'before_closing_cb': _before_closing_cb,
323 'journal_entries_before_closing': {
324 '00100-010-0001': {
325 'payments': [
326 ((self.bank_pm1, 691.06), {
327 'line_ids': [
328 {'account_id': self.c1_receivable.id, 'partner_id': self.customer.id, 'debit': 0, 'credit': 691.06, 'reconciled': True},
329 {'account_id': self.pos_receivable_account.id, 'partner_id': False, 'debit': 691.06, 'credit': 0, 'reconciled': False},
330 ]
331 }),
332 ],
333 },
334 '00100-010-0003': {
335 'payments': [
336 ((self.cash_pm1, 265.75), {
337 'line_ids': [
338 {'account_id': self.other_receivable_account.id, 'partner_id': self.other_customer.id, 'debit': 0, 'credit': 265.75, 'reconciled': True},
339 {'account_id': self.pos_receivable_account.id, 'partner_id': False, 'debit': 265.75, 'credit': 0, 'reconciled': False},
340 ]
341 }),
342 ],
343 },
344 },
345 'journal_entries_after_closing': {
346 'session_journal_entry': {
347 'line_ids': [
348 {'account_id': self.tax_received_account.id, 'partner_id': False, 'debit': 0, 'credit': 9.34, 'reconciled': False},
349 {'account_id': self.tax_received_account.id, 'partner_id': False, 'debit': 0, 'credit': 9.09, 'reconciled': False},
350 {'account_id': self.other_sale_account.id, 'partner_id': False, 'debit': 0, 'credit': 54.95, 'reconciled': False},
351 {'account_id': self.other_sale_account.id, 'partner_id': False, 'debit': 0, 'credit': 90.86, 'reconciled': False},
352 {'account_id': self.bank_pm1.receivable_account_id.id, 'partner_id': False, 'debit': 691.06, 'credit': 0, 'reconciled': True},
353 {'account_id': self.cash_pm1.receivable_account_id.id, 'partner_id': False, 'debit': 429.99, 'credit': 0, 'reconciled': True},
354 {'account_id': self.pos_receivable_account.id, 'partner_id': False, 'debit': 0, 'credit': 691.06, 'reconciled': True},
355 {'account_id': self.pos_receivable_account.id, 'partner_id': False, 'debit': 0, 'credit': 265.75, 'reconciled': True},
356 ],
357 },
358 'cash_statement': [
359 ((429.99, ), {
360 'line_ids': [
361 {'account_id': self.cash_pm1.journal_id.default_account_id.id, 'partner_id': False, 'debit': 429.99, 'credit': 0, 'reconciled': False},
362 {'account_id': self.cash_pm1.receivable_account_id.id, 'partner_id': False, 'debit': 0, 'credit': 429.99, 'reconciled': True},
363 ]
364 }),
365 ],
366 'bank_payments': [
367 ((691.06, ), {
368 'line_ids': [
369 {'account_id': self.bank_pm1.outstanding_account_id.id, 'partner_id': False, 'debit': 691.06, 'credit': 0, 'reconciled': False},
370 {'account_id': self.bank_pm1.receivable_account_id.id, 'partner_id': False, 'debit': 0, 'credit': 691.06, 'reconciled': True},
371 ]
372 }),
373 ],
374 },
375 })