test_pos_controller.py 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. # -*- coding: utf-8 -*-
  2. # Part of Odoo. See LICENSE file for full copyright and licensing details.
  3. import odoo
  4. from odoo.addons.mail.tests.common import mail_new_test_user
  5. from odoo.addons.point_of_sale.tests.test_frontend import TestPointOfSaleHttpCommon
  6. @odoo.tests.tagged('post_install', '-at_install')
  7. class TestPoSController(TestPointOfSaleHttpCommon):
  8. def test_qr_code_receipt(self):
  9. """This test make sure that no user is created when a partner is set on the PoS order.
  10. It also makes sure that the invoice is correctly created.
  11. """
  12. self.authenticate(None, None)
  13. self.new_partner = self.env['res.partner'].create({
  14. 'name': 'AAA Partner',
  15. 'zip': '12345',
  16. 'country_id': self.env.ref('base.us').id,
  17. })
  18. self.product1 = self.env['product.product'].create({
  19. 'name': 'Test Product 1',
  20. 'type': 'product',
  21. 'list_price': 10.0,
  22. 'taxes_id': False,
  23. })
  24. self.main_pos_config.open_ui()
  25. self.pos_order = self.env['pos.order'].create({
  26. 'company_id': self.env.company.id,
  27. 'session_id': self.main_pos_config.current_session_id.id,
  28. 'partner_id': self.new_partner.id,
  29. 'access_token': '1234567890',
  30. 'lines': [(0, 0, {
  31. 'name': "OL/0001",
  32. 'product_id': self.product1.id,
  33. 'price_unit': 10,
  34. 'discount': 0.0,
  35. 'qty': 1.0,
  36. 'tax_ids': False,
  37. 'price_subtotal': 10,
  38. 'price_subtotal_incl': 10,
  39. })],
  40. 'amount_tax': 10,
  41. 'amount_total': 10,
  42. 'amount_paid': 10.0,
  43. 'amount_return': 10.0,
  44. })
  45. self.main_pos_config.current_session_id.close_session_from_ui()
  46. get_invoice_data = {
  47. 'access_token': self.pos_order.access_token,
  48. 'name': self.new_partner.name,
  49. 'email': "test@test.com",
  50. 'company_name': self.new_partner.company_name,
  51. 'vat': self.new_partner.vat,
  52. 'street': "Test street",
  53. 'city': "Test City",
  54. 'zipcode': self.new_partner.zip,
  55. 'country_id': self.new_partner.country_id.id,
  56. 'state_id': self.new_partner.state_id,
  57. 'phone': "123456789",
  58. 'csrf_token': odoo.http.Request.csrf_token(self)
  59. }
  60. self.url_open(f'/pos/ticket/validate?access_token={self.pos_order.access_token}', data=get_invoice_data)
  61. self.assertEqual(self.env['res.partner'].sudo().search_count([('name', '=', 'AAA Partner')]), 1)
  62. self.assertTrue(self.pos_order.is_invoiced, "The pos order should have an invoice")
  63. def test_qr_code_receipt_user_connected(self):
  64. """This test make sure that when the user is already connected he correctly gets redirected to the invoice."""
  65. self.partner_1 = self.env['res.partner'].create({
  66. 'name': 'Valid Lelitre',
  67. 'email': 'valid.lelitre@agrolait.com',
  68. })
  69. self.partner_1_user = mail_new_test_user(
  70. self.env,
  71. name=self.partner_1.name,
  72. login='partner_1',
  73. email=self.partner_1.email,
  74. groups='base.group_portal',
  75. )
  76. self.authenticate('partner_1', 'partner_1')
  77. self.product1 = self.env['product.product'].create({
  78. 'name': 'Test Product 1',
  79. 'type': 'product',
  80. 'list_price': 10.0,
  81. 'taxes_id': False,
  82. })
  83. self.main_pos_config.open_ui()
  84. self.pos_order = self.env['pos.order'].create({
  85. 'session_id': self.main_pos_config.current_session_id.id,
  86. 'company_id': self.env.company.id,
  87. 'access_token': '1234567890',
  88. 'lines': [(0, 0, {
  89. 'name': "OL/0001",
  90. 'product_id': self.product1.id,
  91. 'price_unit': 10,
  92. 'discount': 0.0,
  93. 'qty': 1.0,
  94. 'tax_ids': False,
  95. 'price_subtotal': 10,
  96. 'price_subtotal_incl': 10,
  97. })],
  98. 'amount_tax': 10,
  99. 'amount_total': 10,
  100. 'amount_paid': 10.0,
  101. 'amount_return': 10.0,
  102. })
  103. self.main_pos_config.current_session_id.close_session_from_ui()
  104. res = self.url_open(f'/pos/ticket/validate?access_token={self.pos_order.access_token}', timeout=30000)
  105. self.assertTrue(self.pos_order.is_invoiced, "The pos order should have an invoice")
  106. self.assertTrue("my/invoices" in res.url)