You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

74 lines
2.9 KiB

  1. # Copyright 2004-2018 Odoo SA
  2. # Copyright 2018 Lambda IS DOOEL <https://www.lambda-is.com>
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
  4. from odoo.api import Environment
  5. from odoo.tests import HttpCase
  6. class TestPOSLoyalty(HttpCase):
  7. def test_pos_loyalty(self):
  8. cr = self.registry.cursor()
  9. assert cr == self.registry.test_cr
  10. env = Environment(cr, self.uid, {})
  11. main_pos_config = env.ref('point_of_sale.pos_config_main')
  12. target_product = env.ref('point_of_sale.peche')
  13. free_product = env.ref('point_of_sale.Onions')
  14. customer = env.ref('base.res_partner_2')
  15. loyalty_program = env['loyalty.program'].create({
  16. 'name': 'foo',
  17. 'rule_ids': [(0, 0, {
  18. 'name': 'Peaches',
  19. 'type': 'product',
  20. 'product_id': target_product.id,
  21. 'pp_product': 10,
  22. })],
  23. 'reward_ids': [(0, 0, {
  24. 'name': 'Free Peaches',
  25. 'type': 'gift',
  26. 'gift_product_id': target_product.id,
  27. 'point_cost': 20,
  28. 'minimum_points': 20,
  29. }), (0, 0, {
  30. 'name': 'Free Onions',
  31. 'type': 'gift',
  32. 'gift_product_id': free_product.id,
  33. 'point_cost': 20,
  34. 'minimum_points': 20,
  35. })]
  36. })
  37. main_pos_config.write({'loyalty_id': loyalty_program.id})
  38. main_pos_config.open_session_cb()
  39. # needed because tests are run before the module is marked as
  40. # installed. In js web will only load qweb coming from modules
  41. # that are returned by the backend in module_boot. Without
  42. # this you end up with js, css but no qweb.
  43. env['ir.module.module'].search(
  44. [('name', '=', 'pos_loyalty')], limit=1).state = 'installed'
  45. cr.release()
  46. # Process an order with 2kg of Peaches which should
  47. # add 20 loyalty points
  48. self.phantom_js("/pos/web",
  49. "odoo.__DEBUG__.services['web_tour.tour'].run("
  50. "'test_pos_loyalty_acquire_points')",
  51. "odoo.__DEBUG__.services['web_tour.tour'].tours"
  52. ".test_pos_loyalty_acquire_points.ready",
  53. login="admin")
  54. self.assertEqual(customer.loyalty_points, 20)
  55. # Spend 20 loyalty points on "Free Peaches" reward
  56. self.phantom_js("/pos/web",
  57. "odoo.__DEBUG__.services['web_tour.tour'].run("
  58. "'test_pos_loyalty_spend_points')",
  59. "odoo.__DEBUG__.services['web_tour.tour'].tours"
  60. ".test_pos_loyalty_spend_points.ready",
  61. login="admin")
  62. customer_points = customer.read(
  63. ['loyalty_points'])[0]['loyalty_points']
  64. self.assertEqual(customer_points, 0)