Debian Codegraph @

addons/l10n_sa_pos/tests/test_sa_pos.py

raw
1 from odoo.addons.account.tests.common import AccountTestInvoicingCommon
2 from odoo.addons.point_of_sale.tests.common import TestPoSCommon
3 from odoo.addons.point_of_sale.tests.test_generic_localization import TestGenericLocalization
4 from odoo.tests import tagged
5 from odoo.addons.point_of_sale.tests.test_frontend import TestPointOfSaleHttpCommon
6 from odoo.addons.account_edi.tests.common import AccountEdiTestCommon
7
8
9 @tagged('post_install', '-at_install', 'post_install_l10n')
10 class TestGenericSA(TestGenericLocalization):
11 @classmethod
12 @AccountTestInvoicingCommon.setup_country('sa')
13 def setUpClass(cls):
14 super().setUpClass()
15 if cls.env['ir.module.module']._get('l10n_sa_edi').state == 'installed':
16 cls.skipTest(cls, "l10n_sa_edi should not be installed")
17 cls.main_pos_config.company_id.name = 'Generic SA'
18 cls.company.write({
19 'email': '[email protected]',
20 'phone': '+966 51 234 5678',
21 'street2': 'Testomania',
22 'vat': '311111111111113',
23 'state_id': cls.env['res.country.state'].create({
24 'name': 'Riyadh',
25 'code': 'RYA',
26 'country_id': cls.company.country_id.id
27 }),
28 'street': 'Al Amir Mohammed Bin Abdul Aziz Street',
29 'city': 'المدينة المنورة',
30 'zip': '42317',
31 })
32
33
34 @tagged('post_install_l10n', 'post_install', '-at_install')
35 class TestUi(TestPointOfSaleHttpCommon):
36
37 @classmethod
38 @AccountEdiTestCommon.setup_edi_format('l10n_sa_edi.edi_sa_zatca')
39 @AccountEdiTestCommon.setup_country('sa')
40 def setUpClass(cls):
41 super().setUpClass()
42 # Setup company
43 cls.company.write({
44 'name': 'SA Company Test',
45 'email': '[email protected]',
46 'phone': '+966 51 234 5678',
47 'street2': 'Testomania',
48 'vat': '311111111111113',
49 'state_id': cls.env['res.country.state'].create({
50 'name': 'Riyadh',
51 'code': 'RYA',
52 'country_id': cls.company.country_id.id
53 }),
54 'street': 'Al Amir Mohammed Bin Abdul Aziz Street',
55 'city': 'المدينة المنورة',
56 'zip': '42317',
57 })
58
59 def test_sa_qr_is_shown(self):
60 """
61 Tests that the Saudi Arabia's timezone is applied on the QR code generated at the
62 end of an order.
63 """
64 if self.env['ir.module.module']._get('l10n_sa_edi').state == 'installed':
65 self.skipTest("The needed configuration for e-invoices is not available")
66 self.main_pos_config.with_user(self.pos_admin).open_ui()
67 self.start_tour("/pos/ui?config_id=%d" % self.main_pos_config.id, 'test_sa_qr_is_shown', login="pos_admin")
68
69
70 @tagged('post_install_l10n', 'post_install', '-at_install')
71 class TestSaPosInvoice(TestPoSCommon, TestPointOfSaleHttpCommon):
72
73 def test_consolidate_invoices_for_same_customer(self):
74 """
75 Test that consolidated invoicing for multiple POS orders of the same customer
76 succeeds and sets the confirmation datetime for a Saudi Arabia company.
77 """
78 self.config = self.basic_config
79 self.env.company.country_id = self.env.ref('base.sa')
80
81 self.open_new_session()
82 pos_orders = sum(self._create_orders([
83 {
84 'pos_order_lines_ui_args': [(self.product_a, 1)],
85 'customer': self.customer,
86 'is_invoiced': False,
87 }
88 for _ in range(2)
89 ]).values(), self.env['pos.order'])
90
91 self.env['pos.make.invoice'].create({"consolidated_billing": True}).with_context({
92 "active_ids": pos_orders.ids
93 }).action_create_invoices()
94 invoice = pos_orders.account_move
95
96 self.assertTrue(invoice, "A consolidated invoice should have been created")
97 self.assertTrue(
98 invoice.l10n_sa_confirmation_datetime,
99 "The consolidated invoice should have l10n_sa_confirmation_datetime set"
100 )