Debian Codegraph @

addons/point_of_sale/tests/test_pos_other_currency_config.py

raw symbols SCIP
1 # -*- coding: utf-8 -*-
2 # Part of Odoo. See LICENSE file for full copyright and licensing details.
3
4 from unittest import skip
5
6 import odoo
7
8 from odoo import tools
9 from odoo.addons.point_of_sale.tests.common import TestPoSCommon
10
11 @odoo.tests.tagged('post_install', '-at_install')
12 class TestPoSOtherCurrencyConfig(TestPoSCommon):
13 """ Test PoS with basic configuration
14 """
15
16 def setUp(self):
17 super(TestPoSOtherCurrencyConfig, self).setUp()
18
19 self.config = self.other_currency_config
20 self.product1 = self.create_product('Product 1', self.categ_basic, 10.0, 5)
21 self.product2 = self.create_product('Product 2', self.categ_basic, 20.0, 10)
22 self.product3 = self.create_product('Product 3', self.categ_basic, 30.0, 15)
23 self.product4 = self.create_product('Product 4', self.categ_anglo, 100, 50)
24 self.product5 = self.create_product('Product 5', self.categ_anglo, 200, 70)
25 self.product6 = self.create_product('Product 6', self.categ_anglo, 45.3, 10.73)
26 self.product7 = self.create_product('Product 7', self.categ_basic, 7, 7, tax_ids=self.taxes['tax7'].ids)
27 self.adjust_inventory(
28 [self.product1, self.product2, self.product3, self.product4, self.product5, self.product6, self.product7],
29 [100, 50, 50, 100, 100, 100, 100]
30 )
31 # change the price of product2 to 12.99 fixed. No need to convert.
32 pricelist_item = self.env['product.pricelist.item'].create({
33 'product_tmpl_id': self.product2.product_tmpl_id.id,
34 'fixed_price': 12.99,
35 })
36 self.config.pricelist_id.write({'item_ids': [(6, 0, (self.config.pricelist_id.item_ids | pricelist_item).ids)]})
37
38 self.expense_account = self.categ_anglo.property_account_expense_categ_id
39
40 def test_01_check_product_cost(self):
41 # Product price should be half of the original price because currency rate is 0.5.
42 # (see `self._create_other_currency_config` method)
43 # Except for product2 where the price is specified in the pricelist.
44
45 self.assertAlmostEqual(self.config.pricelist_id._get_product_price(self.product1, 1), 5.00)
46 self.assertAlmostEqual(self.config.pricelist_id._get_product_price(self.product2, 1), 12.99)
47 self.assertAlmostEqual(self.config.pricelist_id._get_product_price(self.product3, 1), 15.00)
48 self.assertAlmostEqual(self.config.pricelist_id._get_product_price(self.product4, 1), 50)
49 self.assertAlmostEqual(self.config.pricelist_id._get_product_price(self.product5, 1), 100)
50 self.assertAlmostEqual(self.config.pricelist_id._get_product_price(self.product6, 1), 22.65)
51 self.assertAlmostEqual(self.config.pricelist_id._get_product_price(self.product7, 1), 3.50)
52
53 def test_02_orders_without_invoice(self):
54 """ orders without invoice
55
56 Orders
57 ======
58 +---------+----------+-----------+----------+-----+-------+
59 | order | payments | invoiced? | product | qty | total |
60 +---------+----------+-----------+----------+-----+-------+
61 | order 1 | cash | no | product1 | 10 | 50 |
62 | | | | product2 | 10 | 129.9 |
63 | | | | product3 | 10 | 150 |
64 +---------+----------+-----------+----------+-----+-------+
65 | order 2 | cash | no | product1 | 5 | 25 |
66 | | | | product2 | 5 | 64.95 |
67 +---------+----------+-----------+----------+-----+-------+
68 | order 3 | bank | no | product2 | 5 | 64.95 |
69 | | | | product3 | 5 | 75 |
70 +---------+----------+-----------+----------+-----+-------+
71
72 Expected Result
73 ===============
74 +---------------------+---------+-----------------+
75 | account | balance | amount_currency |
76 +---------------------+---------+-----------------+
77 | sale_account | -1119.6 | -559.80 |
78 | pos receivable bank | 279.9 | 139.95 |
79 | pos receivable cash | 839.7 | 419.85 |
80 +---------------------+---------+-----------------+
81 | Total balance | 0.0 | 0.00 |
82 +---------------------+---------+-----------------+
83 """
84
85 def _before_closing_cb():
86 # check values before closing the session
87 self.assertEqual(3, self.pos_session.order_count)
88 orders_total = sum(order.amount_total for order in self.pos_session.order_ids)
89 self.assertAlmostEqual(orders_total, self.pos_session.total_payments_amount, msg='Total order amount should be equal to the total payment amount.')
90
91 self._run_test({
92 'payment_methods': self.cash_pm2 | self.bank_pm2,
93 'orders': [
94 {'pos_order_lines_ui_args': [(self.product1, 10), (self.product2, 10), (self.product3, 10)], 'uuid': '00100-010-0001'},
95 {'pos_order_lines_ui_args': [(self.product1, 5), (self.product2, 5)], 'uuid': '00100-010-0002'},
96 {'pos_order_lines_ui_args': [(self.product2, 5), (self.product3, 5)], 'payments': [(self.bank_pm2, 139.95)], 'uuid': '00100-010-0003'},
97 ],
98 'before_closing_cb': _before_closing_cb,
99 'journal_entries_before_closing': {},
100 'journal_entries_after_closing': {
101 'session_journal_entry': {
102 'line_ids': [
103 {'account_id': self.sales_account.id, 'partner_id': False, 'debit': 0, 'credit': 1119.6, 'reconciled': False, 'amount_currency': -559.80},
104 {'account_id': self.bank_pm2.receivable_account_id.id, 'partner_id': False, 'debit': 279.9, 'credit': 0, 'reconciled': True, 'amount_currency': 139.95},
105 {'account_id': self.cash_pm2.receivable_account_id.id, 'partner_id': False, 'debit': 839.7, 'credit': 0, 'reconciled': True, 'amount_currency': 419.85},
106 ],
107 },
108 'cash_statement': [
109 ((419.85, ), {
110 'line_ids': [
111 {'account_id': self.cash_pm2.journal_id.default_account_id.id, 'partner_id': False, 'debit': 839.7, 'credit': 0, 'reconciled': False, 'amount_currency': 419.85},
112 {'account_id': self.cash_pm2.receivable_account_id.id, 'partner_id': False, 'debit': 0, 'credit': 839.7, 'reconciled': True, 'amount_currency': -419.85},
113 ]
114 }),
115 ],
116 'bank_payments': [
117 ((139.95, ), {
118 'line_ids': [
119 {'account_id': self.bank_pm2.outstanding_account_id.id, 'partner_id': False, 'debit': 279.9, 'credit': 0, 'reconciled': False, 'amount_currency': 139.95},
120 {'account_id': self.bank_pm2.receivable_account_id.id, 'partner_id': False, 'debit': 0, 'credit': 279.9, 'reconciled': True, 'amount_currency': -139.95},
121 ]
122 }),
123 ],
124 },
125 })
126
127 def test_03_orders_with_invoice(self):
128 """ orders with invoice
129
130 Orders
131 ======
132 +---------+----------+---------------+----------+-----+-------+
133 | order | payments | invoiced? | product | qty | total |
134 +---------+----------+---------------+----------+-----+-------+
135 | order 1 | cash | no | product1 | 10 | 50 |
136 | | | | product2 | 10 | 129.9 |
137 | | | | product3 | 10 | 150 |
138 +---------+----------+---------------+----------+-----+-------+
139 | order 2 | cash | yes, customer | product1 | 5 | 25 |
140 | | | | product2 | 5 | 64.95 |
141 +---------+----------+---------------+----------+-----+-------+
142 | order 3 | bank | yes, customer | product2 | 5 | 64.95 |
143 | | | | product3 | 5 | 75 |
144 +---------+----------+---------------+----------+-----+-------+
145
146 Expected Result
147 ===============
148 +---------------------+---------+-----------------+
149 | account | balance | amount_currency |
150 +---------------------+---------+-----------------+
151 | sale_account | -659.8 | -329.90 |
152 | pos receivable bank | 279.9 | 139.95 |
153 | pos receivable cash | 839.7 | 419.85 |
154 | invoice receivable | -179.9 | -89.95 |
155 | invoice receivable | -279.9 | -139.95 |
156 +---------------------+---------+-----------------+
157 | Total balance | 0.0 | 0.00 |
158 +---------------------+---------+-----------------+
159 """
160
161 def _before_closing_cb():
162 # check values before closing the session
163 self.assertEqual(3, self.pos_session.order_count)
164 orders_total = sum(order.amount_total for order in self.pos_session.order_ids)
165 self.assertAlmostEqual(orders_total, self.pos_session.total_payments_amount, msg='Total order amount should be equal to the total payment amount.')
166
167 self._run_test({
168 'payment_methods': self.cash_pm2 | self.bank_pm2,
169 'orders': [
170 {'pos_order_lines_ui_args': [(self.product1, 10), (self.product2, 10), (self.product3, 10)], 'uuid': '00100-010-0001'},
171 {'pos_order_lines_ui_args': [(self.product1, 5), (self.product2, 5)], 'is_invoiced': True, 'customer': self.customer, 'uuid': '00100-010-0002'},
172 {'pos_order_lines_ui_args': [(self.product2, 5), (self.product3, 5)], 'payments': [(self.bank_pm2, 139.95)], 'is_invoiced': True, 'customer': self.customer, 'uuid': '00100-010-0003'},
173 ],
174 'before_closing_cb': _before_closing_cb,
175 'journal_entries_before_closing': {
176 '00100-010-0002': {
177 'payments': [
178 ((self.cash_pm2, 89.95), {
179 'line_ids': [
180 {'account_id': self.c1_receivable.id, 'partner_id': self.customer.id, 'debit': 0, 'credit': 179.90, 'reconciled': True, 'amount_currency': -89.95},
181 {'account_id': self.pos_receivable_account.id, 'partner_id': False, 'debit': 179.90, 'credit': 0, 'reconciled': False, 'amount_currency': 89.95},
182 ]
183 }),
184 ],
185 },
186 '00100-010-0003': {
187 'payments': [
188 ((self.bank_pm2, 139.95), {
189 'line_ids': [
190 {'account_id': self.c1_receivable.id, 'partner_id': self.customer.id, 'debit': 0, 'credit': 279.9, 'reconciled': True, 'amount_currency': -139.95},
191 {'account_id': self.pos_receivable_account.id, 'partner_id': False, 'debit': 279.9, 'credit': 0, 'reconciled': False, 'amount_currency': 139.95},
192 ]
193 }),
194 ],
195 },
196 },
197 'journal_entries_after_closing': {
198 'session_journal_entry': {
199 'line_ids': [
200 {'account_id': self.sales_account.id, 'partner_id': False, 'debit': 0, 'credit': 659.8, 'reconciled': False, 'amount_currency': -329.90},
201 {'account_id': self.bank_pm2.receivable_account_id.id, 'partner_id': False, 'debit': 279.9, 'credit': 0, 'reconciled': True, 'amount_currency': 139.95},
202 {'account_id': self.cash_pm2.receivable_account_id.id, 'partner_id': False, 'debit': 839.7, 'credit': 0, 'reconciled': True, 'amount_currency': 419.85},
203 {'account_id': self.pos_receivable_account.id, 'partner_id': False, 'debit': 0, 'credit': 179.90, 'reconciled': True, 'amount_currency': -89.95},
204 {'account_id': self.pos_receivable_account.id, 'partner_id': False, 'debit': 0, 'credit': 279.9, 'reconciled': True, 'amount_currency': -139.95},
205 ],
206 },
207 'cash_statement': [
208 ((419.85, ), {
209 'line_ids': [
210 {'account_id': self.cash_pm2.journal_id.default_account_id.id, 'partner_id': False, 'debit': 839.7, 'credit': 0, 'reconciled': False, 'amount_currency': 419.85},
211 {'account_id': self.cash_pm2.receivable_account_id.id, 'partner_id': False, 'debit': 0, 'credit': 839.7, 'reconciled': True, 'amount_currency': -419.85},
212 ]
213 }),
214 ],
215 'bank_payments': [
216 ((139.95, ), {
217 'line_ids': [
218 {'account_id': self.bank_pm2.outstanding_account_id.id, 'partner_id': False, 'debit': 279.9, 'credit': 0, 'reconciled': False, 'amount_currency': 139.95},
219 {'account_id': self.bank_pm2.receivable_account_id.id, 'partner_id': False, 'debit': 0, 'credit': 279.9, 'reconciled': True, 'amount_currency': -139.95},
220 ]
221 }),
222 ],
223 },
224 })
225
226 @skip('Temporary to fast merge new valuation')
227 def test_04_anglo_saxon_products(self):
228 """
229 ======
230 Orders
231 ======
232 +---------+----------+-----------+----------+-----+----------+------------+
233 | order | payments | invoiced? | product | qty | total | total cost |
234 | | | | | | | |
235 +---------+----------+-----------+----------+-----+----------+------------+
236 | order 1 | cash | no | product4 | 7 | 700 | 350 |
237 | | | | product5 | 7 | 1400 | 490 |
238 +---------+----------+-----------+----------+-----+----------+------------+
239 | order 2 | cash | no | product5 | 6 | 1200 | 420 |
240 | | | | product4 | 6 | 600 | 300 |
241 | | | | product6 | 49 | 2219.7 | 525.77 |
242 +---------+----------+-----------+----------+-----+----------+------------+
243 | order 3 | cash | no | product5 | 2 | 400 | 140 |
244 | | | | product6 | 13 | 588.9 | 139.49 |
245 +---------+----------+-----------+----------+-----+----------+------------+
246 | order 4 | cash | no | product6 | 1 | 45.3 | 10.73 |
247 +---------+----------+-----------+----------+-----+----------+------------+
248
249 ===============
250 Expected Result
251 ===============
252 +---------------------+------------+-----------------+
253 | account | balance | amount_currency |
254 +---------------------+------------+-----------------+
255 | sale_account | -7153.90 | -3576.95 |
256 | pos_receivable-cash | 7153.90 | 3576.95 |
257 | expense_account | 2375.99 | 2375.99 |
258 | output_account | -2375.99 | -2375.99 |
259 +---------------------+------------+-----------------+
260 | Total balance | 0.00 | 0.00 |
261 +---------------------+------------+-----------------+
262 """
263
264 self._run_test({
265 'payment_methods': self.cash_pm2,
266 'orders': [
267 {'pos_order_lines_ui_args': [(self.product4, 7), (self.product5, 7)], 'uuid': '00100-010-0001'},
268 {'pos_order_lines_ui_args': [(self.product5, 6), (self.product4, 6), (self.product6, 49)], 'uuid': '00100-010-0002'},
269 {'pos_order_lines_ui_args': [(self.product5, 2), (self.product6, 13)], 'uuid': '00100-010-0003'},
270 {'pos_order_lines_ui_args': [(self.product6, 1)], 'uuid': '00100-010-0004'},
271 ],
272 'journal_entries_before_closing': {},
273 'journal_entries_after_closing': {
274 'session_journal_entry': {
275 'line_ids': [
276 {'account_id': self.sales_account.id, 'partner_id': False, 'debit': 0, 'credit': 7153.90, 'reconciled': False, 'amount_currency': -3576.95},
277 {'account_id': self.expense_account.id, 'partner_id': False, 'debit': 2375.99, 'credit': 0, 'reconciled': False, 'amount_currency': 2375.99},
278 {'account_id': self.cash_pm2.receivable_account_id.id, 'partner_id': False, 'debit': 7153.90, 'credit': 0, 'reconciled': True, 'amount_currency': 3576.95},
279 {'account_id': self.output_account.id, 'partner_id': False, 'debit': 0, 'credit': 2375.99, 'reconciled': True, 'amount_currency': -2375.99},
280 ],
281 },
282 'cash_statement': [
283 ((3576.95, ), {
284 'line_ids': [
285 {'account_id': self.cash_pm2.journal_id.default_account_id.id, 'partner_id': False, 'debit': 7153.90, 'credit': 0, 'reconciled': False, 'amount_currency': 3576.95},
286 {'account_id': self.cash_pm2.receivable_account_id.id, 'partner_id': False, 'debit': 0, 'credit': 7153.90, 'reconciled': True, 'amount_currency': -3576.95},
287 ]
288 }),
289 ],
290 'bank_payments': [],
291 },
292 })
293
294 def test_05_tax_base_amount(self):
295 self._run_test({
296 'payment_methods': self.cash_pm2,
297 'orders': [
298 {'pos_order_lines_ui_args': [(self.product7, 7)], 'uuid': '00100-010-0001'},
299 ],
300 'journal_entries_before_closing': {},
301 'journal_entries_after_closing': {
302 'session_journal_entry': {
303 'line_ids': [
304 {'account_id': self.tax_received_account.id, 'partner_id': False, 'debit': 0, 'credit': 3.43, 'reconciled': False, 'amount_currency': -1.715, 'tax_base_amount': 49},
305 {'account_id': self.sales_account.id, 'partner_id': False, 'debit': 0, 'credit': 49, 'reconciled': False, 'amount_currency': -24.5, 'tax_base_amount': 0},
306 {'account_id': self.cash_pm2.receivable_account_id.id, 'partner_id': False, 'debit': 52.43, 'credit': 0, 'reconciled': True, 'amount_currency': 26.215, 'tax_base_amount': 0},
307 ],
308 },
309 'cash_statement': [
310 ((26.215, ), {
311 'line_ids': [
312 {'account_id': self.cash_pm2.journal_id.default_account_id.id, 'partner_id': False, 'debit': 52.43, 'credit': 0, 'reconciled': False, 'amount_currency': 26.215},
313 {'account_id': self.cash_pm2.receivable_account_id.id, 'partner_id': False, 'debit': 0, 'credit': 52.43, 'reconciled': True, 'amount_currency': -26.215},
314 ]
315 }),
316 ],
317 'bank_payments': [],
318 },
319 })
320
321 def test_bank_journal_balance(self):
322 """Verify that debit and credit are balanced when adding a difference to the bank."""
323
324 # Make a sale paid by bank
325 self.other_currency_config.open_ui()
326 session_id = self.other_currency_config.current_session_id
327 order = self.env['pos.order'].create({
328 'company_id': self.env.company.id,
329 'session_id': session_id.id,
330 'partner_id': False,
331 'lines': [(0, 0, {
332 'name': 'OL/0001',
333 'product_id': self.product1.id,
334 'price_unit': 10.00,
335 'discount': 0,
336 'qty': 1,
337 'tax_ids': False,
338 'price_subtotal': 10.00,
339 'price_subtotal_incl': 10.00,
340 })],
341 'pricelist_id': self.other_currency_config.pricelist_id.id,
342 'amount_paid': 10.00,
343 'amount_total': 10.00,
344 'amount_tax': 0.0,
345 'amount_return': 0.0,
346 'to_invoice': False,
347 })
348
349 # Make payment
350 payment_context = {"active_ids": order.ids, "active_id": order.id}
351 order_payment = self.env['pos.make.payment'].with_context(**payment_context).create({
352 'amount': order.amount_total,
353 'payment_method_id': self.bank_pm2.id
354 })
355 order_payment.with_context(**payment_context).check()
356
357 # Close session with counted +10 for bank compared with expected
358 session_id.action_pos_session_closing_control(bank_payment_method_diffs={self.bank_pm2.id: 10.00}) # Real 20, expected 10, diff 10
359
360 # Check debit/credit session's balance
361 for move in session_id._get_related_account_moves():
362 debit = credit = 0.0
363 for line in move.line_ids:
364 debit += line.debit
365 credit += line.credit
366 self.assertEqual(tools.float_compare(debit, credit, precision_rounding=self.other_currency_config.currency_id.rounding), 0) # debit and credit should be equal
367
368 def test_with_session_check_product_cost(self):
369 def find_by(list_of_dicts, key, value):
370 return next((d for d in list_of_dicts if d.get(key) == value), None)
371
372 self.other_currency_config.open_ui()
373 product = self.other_currency_config.current_session_id.load_data([])['product.product']
374
375 self.assertAlmostEqual(find_by(product, 'id', self.product1.id)['lst_price'], 5.00)
376 self.assertAlmostEqual(find_by(product, 'id', self.product2.id)['lst_price'], 10.00)
377 self.assertAlmostEqual(find_by(product, 'id', self.product3.id)['lst_price'], 15.00)
378 self.assertAlmostEqual(find_by(product, 'id', self.product4.id)['lst_price'], 50.00)
379 self.assertAlmostEqual(find_by(product, 'id', self.product5.id)['lst_price'], 100.00)
380 self.assertAlmostEqual(find_by(product, 'id', self.product6.id)['lst_price'], 22.65)
381 self.assertAlmostEqual(find_by(product, 'id', self.product7.id)['lst_price'], 3.50)
382
383 def test_pos_data_standard_price_converted(self):
384 self.other_currency_config.open_ui()
385 res = self.other_currency_config.current_session_id.load_data({})
386 product1_data = next(filter(lambda product: product['display_name'] == "Product 1", res['product.product']))
387 self.assertEqual(product1_data['standard_price'], 2.5) # standard price should be converted