test_frontend.py 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. # -*- coding: utf-8 -*-
  2. # Part of Odoo. See LICENSE file for full copyright and licensing details.
  3. import odoo.tests
  4. @odoo.tests.tagged('post_install', '-at_install')
  5. class TestFrontend(odoo.tests.HttpCase):
  6. def setUp(self):
  7. super().setUp()
  8. self.env = self.env(user=self.env.ref('base.user_admin'))
  9. account_obj = self.env['account.account']
  10. account_receivable = account_obj.create({'code': 'X1012',
  11. 'name': 'Account Receivable - Test',
  12. 'account_type': 'asset_receivable',
  13. 'reconcile': True})
  14. printer = self.env['restaurant.printer'].create({
  15. 'name': 'Kitchen Printer',
  16. 'proxy_ip': 'localhost',
  17. })
  18. drinks_category = self.env['pos.category'].create({'name': 'Drinks'})
  19. main_company = self.env.ref('base.main_company')
  20. second_cash_journal = self.env['account.journal'].create({
  21. 'name': 'Cash 2',
  22. 'code': 'CSH2',
  23. 'type': 'cash',
  24. 'company_id': main_company.id
  25. })
  26. self.env['pos.payment.method'].create({
  27. 'name': 'Cash 2',
  28. 'split_transactions': False,
  29. 'receivable_account_id': account_receivable.id,
  30. 'journal_id': second_cash_journal.id,
  31. })
  32. pos_config = self.env['pos.config'].create({
  33. 'name': 'Bar',
  34. 'module_pos_restaurant': True,
  35. 'is_table_management': True,
  36. 'iface_splitbill': True,
  37. 'iface_printbill': True,
  38. 'iface_orderline_notes': True,
  39. 'printer_ids': [(4, printer.id)],
  40. 'iface_start_categ_id': drinks_category.id,
  41. 'start_category': True,
  42. 'pricelist_id': self.env.ref('product.list0').id,
  43. })
  44. main_floor = self.env['restaurant.floor'].create({
  45. 'name': 'Main Floor',
  46. 'pos_config_id': pos_config.id,
  47. })
  48. table_05 = self.env['restaurant.table'].create({
  49. 'name': 'T5',
  50. 'floor_id': main_floor.id,
  51. 'seats': 4,
  52. 'position_h': 100,
  53. 'position_v': 100,
  54. })
  55. table_04 = self.env['restaurant.table'].create({
  56. 'name': 'T4',
  57. 'floor_id': main_floor.id,
  58. 'seats': 4,
  59. 'shape': 'square',
  60. 'position_h': 150,
  61. 'position_v': 100,
  62. })
  63. table_02 = self.env['restaurant.table'].create({
  64. 'name': 'T2',
  65. 'floor_id': main_floor.id,
  66. 'seats': 4,
  67. 'position_h': 250,
  68. 'position_v': 100,
  69. })
  70. second_floor = self.env['restaurant.floor'].create({
  71. 'name': 'Second Floor',
  72. 'pos_config_id': pos_config.id,
  73. })
  74. table_01 = self.env['restaurant.table'].create({
  75. 'name': 'T1',
  76. 'floor_id': second_floor.id,
  77. 'seats': 4,
  78. 'shape': 'square',
  79. 'position_h': 100,
  80. 'position_v': 150,
  81. })
  82. table_03 = self.env['restaurant.table'].create({
  83. 'name': 'T3',
  84. 'floor_id': second_floor.id,
  85. 'seats': 4,
  86. 'position_h': 100,
  87. 'position_v': 250,
  88. })
  89. self.env['ir.property']._set_default(
  90. 'property_account_receivable_id',
  91. 'res.partner',
  92. account_receivable,
  93. main_company,
  94. )
  95. test_sale_journal = self.env['account.journal'].create({
  96. 'name': 'Sales Journal - Test',
  97. 'code': 'TSJ',
  98. 'type': 'sale',
  99. 'company_id': main_company.id
  100. })
  101. cash_journal = self.env['account.journal'].create({
  102. 'name': 'Cash Test',
  103. 'code': 'TCJ',
  104. 'type': 'cash',
  105. 'company_id': main_company.id
  106. })
  107. pos_config.write({
  108. 'journal_id': test_sale_journal.id,
  109. 'invoice_journal_id': test_sale_journal.id,
  110. 'payment_method_ids': [(0, 0, {
  111. 'name': 'Cash restaurant',
  112. 'split_transactions': True,
  113. 'receivable_account_id': account_receivable.id,
  114. 'journal_id': cash_journal.id,
  115. })],
  116. })
  117. coke = self.env['product.product'].create({
  118. 'available_in_pos': True,
  119. 'list_price': 2.20,
  120. 'name': 'Coca-Cola',
  121. 'weight': 0.01,
  122. 'pos_categ_id': drinks_category.id,
  123. 'categ_id': self.env.ref('point_of_sale.product_category_pos').id,
  124. 'taxes_id': [(6, 0, [])],
  125. })
  126. water = self.env['product.product'].create({
  127. 'available_in_pos': True,
  128. 'list_price': 2.20,
  129. 'name': 'Water',
  130. 'weight': 0.01,
  131. 'pos_categ_id': drinks_category.id,
  132. 'categ_id': self.env.ref('point_of_sale.product_category_pos').id,
  133. 'taxes_id': [(6, 0, [])],
  134. })
  135. minute_maid = self.env['product.product'].create({
  136. 'available_in_pos': True,
  137. 'list_price': 2.20,
  138. 'name': 'Minute Maid',
  139. 'weight': 0.01,
  140. 'pos_categ_id': drinks_category.id,
  141. 'categ_id': self.env.ref('point_of_sale.product_category_pos').id,
  142. 'taxes_id': [(6, 0, [])],
  143. })
  144. pricelist = self.env['product.pricelist'].create({'name': 'Restaurant Pricelist'})
  145. pos_config.write({'pricelist_id': pricelist.id})
  146. self.pos_config = pos_config
  147. def test_01_pos_restaurant(self):
  148. self.pos_config.with_user(self.env.ref('base.user_admin')).open_ui()
  149. self.start_tour("/pos/ui?config_id=%d" % self.pos_config.id, 'pos_restaurant_sync', login="admin")
  150. self.assertEqual(1, self.env['pos.order'].search_count([('amount_total', '=', 4.4), ('state', '=', 'draft')]))
  151. self.assertEqual(1, self.env['pos.order'].search_count([('amount_total', '=', 4.4), ('state', '=', 'paid')]))
  152. self.start_tour("/pos/ui?config_id=%d" % self.pos_config.id, 'pos_restaurant_sync_second_login', login="admin")
  153. self.assertEqual(0, self.env['pos.order'].search_count([('amount_total', '=', 4.4), ('state', '=', 'draft')]))
  154. self.assertEqual(1, self.env['pos.order'].search_count([('amount_total', '=', 2.2), ('state', '=', 'draft')]))
  155. self.assertEqual(2, self.env['pos.order'].search_count([('amount_total', '=', 4.4), ('state', '=', 'paid')]))
  156. def test_02_others(self):
  157. self.pos_config.with_user(self.env.ref('base.user_admin')).open_ui()
  158. self.start_tour("/pos/ui?config_id=%d" % self.pos_config.id, 'SplitBillScreenTour', login="admin")
  159. self.start_tour("/pos/ui?config_id=%d" % self.pos_config.id, 'ControlButtonsTour', login="admin")
  160. self.start_tour("/pos/ui?config_id=%d" % self.pos_config.id, 'FloorScreenTour', login="admin")
  161. def test_04_ticket_screen(self):
  162. self.pos_config.with_user(self.env.ref('base.user_admin')).open_ui()
  163. self.start_tour("/pos/ui?config_id=%d" % self.pos_config.id, 'PosResTicketScreenTour', login="admin")
  164. def test_05_tip_screen(self):
  165. self.pos_config.write({'set_tip_after_payment': True, 'iface_tipproduct': True, 'tip_product_id': self.env.ref('point_of_sale.product_product_tip')})
  166. self.pos_config.with_user(self.env.ref('base.user_admin')).open_ui()
  167. self.start_tour("/pos/ui?config_id=%d" % self.pos_config.id, 'PosResTipScreenTour', login="admin")
  168. order1 = self.env['pos.order'].search([('pos_reference', 'ilike', '%-0001')])
  169. order2 = self.env['pos.order'].search([('pos_reference', 'ilike', '%-0002')])
  170. order3 = self.env['pos.order'].search([('pos_reference', 'ilike', '%-0003')])
  171. order4 = self.env['pos.order'].search([('pos_reference', 'ilike', '%-0004')])
  172. self.assertTrue(order1.is_tipped and order1.tip_amount == 0.40)
  173. self.assertTrue(order2.is_tipped and order2.tip_amount == 1.00)
  174. self.assertTrue(order3.is_tipped and order3.tip_amount == 1.50)
  175. self.assertTrue(order4.is_tipped and order4.tip_amount == 1.00)
  176. def test_06_split_bill_screen(self):
  177. self.pos_config.with_user(self.env.ref('base.user_admin')).open_ui()
  178. self.start_tour("/pos/ui?config_id=%d" % self.pos_config.id, 'SplitBillScreenTour2', login="admin")
  179. def test_07_refund_stay_current_table(self):
  180. self.pos_config.with_user(self.env.ref('base.user_admin')).open_ui()
  181. self.start_tour("/pos/ui?config_id=%d" % self.pos_config.id, 'RefundStayCurrentTableTour', login="admin")