Debian Codegraph @

addons/point_of_sale/tests/test_pos_invoice_consolidation.py

raw
1 from odoo import Command
2 from odoo.addons.point_of_sale.tests.common import CommonPosTest, TestPoSCommon
3 from odoo.tests.common import tagged
4
5
6 @tagged('post_install', '-at_install')
7 class TestPosInvoiceConsolidation(TestPoSCommon, CommonPosTest):
8
9 def setUp(cls):
10 super().setUp()
11 cls.config = cls.basic_config
12 cls.user1 = cls.env.user
13 cls.user2 = cls.simple_accountman
14 cls.user2.group_ids = [Command.link(cls.env.ref('point_of_sale.group_pos_user').id)]
15 cls.product1 = cls.create_product('Product 1', cls.categ_basic, 10.0)
16 cls.product2 = cls.create_product('Product 2', cls.categ_basic, 20.0)
17
18 def test_ignore_generated_invoices(self):
19 self.open_new_session()
20
21 with self.with_user(self.user1.login):
22 orders_user1 = self._create_orders([{
23 'pos_order_lines_ui_args': [(self.product1, 1)],
24 'customer': self.customer,
25 'is_invoiced': False,
26 'uuid': 'u1-order',
27 }])
28 # This flattens the dict into the recordset
29 orders_user1 = sum(orders_user1.values(), self.env['pos.order'])
30
31 with self.with_user(self.user2.login):
32 orders_user2 = self._create_orders([
33 {
34 'pos_order_lines_ui_args': [(self.product1, 2)],
35 'customer': self.customer,
36 'is_invoiced': False,
37 }, {
38 'pos_order_lines_ui_args': [(self.product2, 1)],
39 'customer': self.customer,
40 'is_invoiced': False,
41 }
42 ])
43 # This flattens the dict into the recordset
44 orders_user2 = sum(orders_user2.values(), self.env['pos.order'])
45
46 self.env['pos.make.invoice'].create({'consolidated_billing': True}).with_context(active_ids=orders_user1.ids).action_create_invoices()
47
48 invoice_user1 = orders_user1.account_move
49 invoice_user2 = orders_user2.account_move
50
51 self.assertEqual(len(invoice_user1), 1, "User 1 should have one invoice")
52 self.assertEqual(orders_user1.amount_total, invoice_user1.amount_total)
53
54 self.assertEqual(len(invoice_user2), 0, "User 2 should have no invoices")
55
56 all_orders = orders_user1 + orders_user2
57 self.env['pos.make.invoice'].create({'consolidated_billing': True}).with_context(active_ids=all_orders.ids).action_create_invoices()
58 invoice_user1 = orders_user1.account_move
59 invoice_user2 = orders_user2.account_move
60
61 self.assertEqual(len(invoice_user1), 1, "User 1 should have one invoice")
62 self.assertEqual(orders_user1.amount_total, invoice_user1.amount_total)
63
64 self.assertEqual(len(invoice_user2), 1, "User 2 should have one invoice")
65 self.assertEqual(sum(orders_user2.mapped('amount_total')), invoice_user2.amount_total)
66
67 def test_invoice_grouped_by_user_id(self):
68 self.open_new_session()
69
70 with self.with_user(self.user1.login):
71 orders_user1 = self._create_orders([{
72 'pos_order_lines_ui_args': [(self.product1, 1)],
73 'customer': self.customer,
74 'is_invoiced': False,
75 'uuid': 'u1-order',
76 }])
77 # This flattens the dict into the recordset
78 orders_user1 = sum(orders_user1.values(), self.env['pos.order'])
79
80 with self.with_user(self.user2.login):
81 orders_user2 = self._create_orders([
82 {
83 'pos_order_lines_ui_args': [(self.product1, 2)],
84 'customer': self.customer,
85 'is_invoiced': False,
86 }, {
87 'pos_order_lines_ui_args': [(self.product2, 1)],
88 'customer': self.customer,
89 'is_invoiced': False,
90 }
91 ])
92 # This flattens the dict into the recordset
93 orders_user2 = sum(orders_user2.values(), self.env['pos.order'])
94
95 all_orders = orders_user1 + orders_user2
96
97 # create consolidated invoice
98 self.env['pos.make.invoice'].create({'consolidated_billing': True}).with_context(active_ids=all_orders.ids).action_create_invoices()
99
100 invoice_user1 = orders_user1.account_move
101 invoice_user2 = orders_user2.account_move
102
103 self.assertEqual(len(invoice_user1), 1, "User 1 should have one invoice")
104 self.assertEqual(orders_user1.amount_total, invoice_user1.amount_total)
105
106 self.assertEqual(len(invoice_user2), 1, "User 2 should have one invoice")
107 self.assertEqual(sum(orders_user2.mapped('amount_total')), invoice_user2.amount_total)