Debian Codegraph @

addons/l10n_in_pos/tests/test_pos_flow.py

raw
1 from odoo.tests import tagged
2 from .common import TestInPosBase
3
4
5 @tagged('post_install_l10n', 'post_install', '-at_install')
6 class TestPosFlow(TestInPosBase):
7 """
8 Test class for GSTR-related POS functionality.
9 """
10
11 def test_invoice_order_after_session_closed(self):
12 """Test that an order can be invoiced after its session is closed.
13 Scenario:
14 1. Create a POS session and two orders:
15 - Order A: Not to be invoiced immediately.
16 - Order B: To be invoiced immediately.
17 2. Close the POS session.
18 3. Ensure:
19 - Both orders have `reversed_move_ids` unset.
20 4. Assign a partner to Order A and invoice it AFTER the session is closed.
21 - Confirm that `reversed_move_ids` is set accordingly.
22 """
23
24 with self.with_pos_session():
25 # Create a POS order without an invoice, simulating basic sale and payment
26 pos_order_going_to_invoice = self._create_order({
27 'pos_order_lines_ui_args': [
28 (self.product_a, 2.0), # 2 units of product A
29 (self.product_b, 2.0), # 2 units of product B
30 ],
31 'payments': [(self.bank_pm1, 630.0)], # Payment of 630 through bank payment method
32 })
33 # Create a POS order with an invoice and a linked customer
34 pos_order_with_invoice = self._create_order({
35 'pos_order_lines_ui_args': [
36 (self.product_a, 3.0), # 3 units of product A
37 (self.product_b, 3.0), # 3 units of product B
38 ],
39 'payments': [(self.bank_pm1, 945.0)], # Payment of 945 through bank payment method
40 'customer': self.partner_a,
41 })
42
43 # Initial state: no reversal moves for both orders
44 self.assertFalse(pos_order_going_to_invoice.reversed_move_ids,
45 "Order with 'to_invoice' = False should have no reversal moves after session is closed.")
46 self.assertFalse(pos_order_with_invoice.reversed_move_ids,
47 "Immediate invoiced order should have no reversal moves after session is closed.")
48
49 # Now, set a partner and invoice the order after the session is closed
50 # with self.with_pos_session() as session2:
51 pos_order_going_to_invoice.partner_id = self.partner_a
52 pos_order_going_to_invoice.action_pos_order_invoice()
53 # session2.action_pos_session_closing_control()
54
55 # Confirm that reversal move(s) are now set
56 reversal_moves = self.env['account.move'].search([('reversed_pos_order_id', '=', pos_order_going_to_invoice.id)])
57 self.assertEqual(pos_order_going_to_invoice.reversed_move_ids, reversal_moves,
58 "Reversal move should be set for the order invoiced after the session is closed.")
59 self.assertInvoiceValues(reversal_moves, [
60 {'product_id': self.product_a.id, 'l10n_in_hsn_code': '1111', 'product_uom_id': self.product_a.uom_id.id, 'debit': 200.0, 'credit': 0.0},
61 {'product_id': self.product_b.id, 'l10n_in_hsn_code': '2222', 'product_uom_id': self.product_b.uom_id.id, 'debit': 400.0, 'credit': 0.0},
62 {'product_id': False, 'l10n_in_hsn_code': False, 'product_uom_id': False, 'debit': 15.0, 'credit': 0.0},
63 {'product_id': False, 'l10n_in_hsn_code': False, 'product_uom_id': False, 'debit': 15.0, 'credit': 0.0},
64 {'product_id': False, 'l10n_in_hsn_code': False, 'product_uom_id': False, 'debit': 0.0, 'credit': 630.0},
65
66 ], {
67 'amount_untaxed': 0.0,
68 'amount_tax': 0.0,
69 'amount_total': 630.0,
70 })