-
-
Notifications
You must be signed in to change notification settings - Fork 605
/
test_pos.py
64 lines (60 loc) · 2.28 KB
/
test_pos.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
from odoo import fields
from odoo.exceptions import ValidationError
from odoo.tests.common import TransactionCase
class TestPos(TransactionCase):
def setUp(self):
super().setUp()
self.pos_config = self.env.ref('point_of_sale.pos_config_main').copy({
'name': 'Block PoS Session with Stock Error',
'allow_session_closing_with_stock_errors': False,
})
self.product_tracking = self.env.ref(
'point_of_sale.desk_organizer'
).copy({
'name': 'Product with Tracking',
'tracking': 'serial',
})
def test_session_closing_with_errors(self):
pos_session = self.env['pos.session'].create({
'config_id': self.pos_config.id,
})
# We create an order that will generate errors
# (the product requires a serial number)
pos_order = self.env['pos.order'].create({
'session_id': pos_session.id,
'lines': [(0, 0, {
'name': 'OL/0001',
'product_id': self.product_tracking.id,
'tax_ids': False,
'qty': 1.0,
'price_unit': 1000,
'price_subtotal': 1000,
'price_subtotal_incl': 1000,
})],
'amount_total': 1000.0,
'amount_tax': 0.0,
'amount_paid': 1000.0,
'amount_return': 0.0,
})
# Register order payment
pos_order.add_payment({
'amount': 1000,
'payment_date': fields.Datetime.now(),
'statement_id': pos_session.statement_ids[0].id,
'payment_name': 'PAY',
'journal': pos_session.statement_ids[0].journal_id.id,
})
# Set ending balance in statement
pos_session.statement_ids[0].write({
'balance_end_real': pos_session.statement_ids[0].balance_end
})
pos_order.action_pos_order_paid()
# Blocked because we have errors
with self.assertRaises(ValidationError):
pos_session.action_pos_session_close()
# Enable closing with errors
self.pos_config.write({
'allow_session_closing_with_stock_errors': True,
})
# Should be possible to close now
pos_session.action_pos_session_close()