Debian Codegraph @

addons/l10n_in_pos/tests/common.py

raw
1 # Part of Odoo. See LICENSE file for full copyright and licensing details.
2 from contextlib import contextmanager
3
4 from odoo.fields import Command
5 from odoo.addons.point_of_sale.tests.common import TestPoSCommon
6 from odoo.addons.account.tests.common import TestTaxCommon
7
8
9 class TestInPosBase(TestPoSCommon):
10 """
11 Base class for Indian GSTR and POS-related test cases.
12 This class sets up the company, products, and configuration required
13 for any test involving GSTR in a POS environment.
14 """
15 @classmethod
16 @TestTaxCommon.setup_country('in')
17 def setUpClass(cls):
18 super().setUpClass()
19 country_in_id = cls.env.ref("base.in").id
20 cls.company_data["company"].write({
21 "vat": "24AAGCC7144L6ZE",
22 "state_id": cls.env.ref("base.state_in_gj").id,
23 "street": "street1",
24 "city": "city1",
25 "zip": "123456",
26 "country_id": country_in_id,
27 "l10n_in_is_gst_registered": True,
28 })
29 cls.config = cls.basic_config
30 cls.gst_5 = cls.env['account.chart.template'].ref('sgst_sale_5')
31 cls.nil_rated = cls.env['account.chart.template'].ref('nil_rated_sale')
32
33 country_in = cls.env.ref('base.in')
34 state_in_gj = cls.env.ref('base.state_in_gj')
35
36 cls.partner_a.write({
37 'name': "Partner Intra State",
38 'vat': '24ABCPM8965E1ZE',
39 'state_id': state_in_gj.id,
40 'country_id': country_in.id,
41 'street': "Karansinhji Rd",
42 'street2': "Karanpara",
43 'city': "Rajkot",
44 'zip': "360001",
45 })
46
47 # Common product setup for POS tests
48 cls._setup_products()
49
50 @classmethod
51 def _setup_products(cls):
52 """Sets up products for POS testing with GST."""
53 cls.product_a.write({
54 'available_in_pos': True,
55 'l10n_in_hsn_code': '1111',
56 'list_price': 100,
57 'taxes_id': [Command.set(cls.gst_5.ids)], # Tax: 5
58 })
59 cls.product_b.write({
60 'available_in_pos': True,
61 'l10n_in_hsn_code': '2222',
62 'list_price': 200,
63 'taxes_id': [Command.set(cls.gst_5.ids)], # Tax: 10
64 })
65 cls.product_c = cls.env['product.product'].create({
66 'name': 'Product C',
67 'available_in_pos': True,
68 'list_price': 300,
69 'taxes_id': [Command.set(cls.nil_rated.ids)], # Tax: 0
70 })
71
72 @contextmanager
73 def with_pos_session(self):
74 """Opens a new POS session and ensures it is closed properly."""
75 session = self.open_new_session(0.0)
76 yield session
77 session.post_closing_cash_details(0.0)
78 session.close_session_from_ui()
79
80 def _create_order(self, ui_data):
81 """Helper to create a POS order from UI data."""
82 order_data = self.create_ui_order_data(**ui_data)
83 results = self.env['pos.order'].sync_from_ui([order_data])
84 return self.env['pos.order'].browse([o['id'] for o in results['pos.order']])
85
86 @classmethod
87 def _create_categ_anglo(cls):
88 # Stock Valuation support is currently not implemented for Indian localization.
89 # Once support is added, this method override will be removed.
90 return False