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.

117 lines
4.4 KiB

  1. # -*- encoding: utf-8 -*-
  2. ##############################################################################
  3. #
  4. # Point Of Sale - Order Pricelist Change for Odoo
  5. # Copyright (C) 2014 GRAP (http://www.grap.coop)
  6. # @author Sylvain LE GAL (https://twitter.com/legalsylvain)
  7. #
  8. # This program is free software: you can redistribute it and/or modify
  9. # it under the terms of the GNU Affero General Public License as
  10. # published by the Free Software Foundation, either version 3 of the
  11. # License, or (at your option) any later version.
  12. #
  13. # This program is distributed in the hope that it will be useful,
  14. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. # GNU Affero General Public License for more details.
  17. #
  18. # You should have received a copy of the GNU Affero General Public License
  19. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. #
  21. ##############################################################################
  22. from openerp.tests.common import TransactionCase
  23. class TestPosOrderPricelistChange(TransactionCase):
  24. """Tests for Point Of Sale - Order Pricelist Change Module"""
  25. def setUp(self):
  26. super(TestPosOrderPricelistChange, self).setUp()
  27. self.imd_obj = self.env['ir.model.data']
  28. self.pp_obj = self.env['product.product']
  29. self.ppl_obj = self.env['product.pricelist']
  30. self.po_obj = self.env['pos.order']
  31. self.pol_obj = self.env['pos.order.line']
  32. self.pc_obj = self.env['pos.config']
  33. self.ps_obj = self.env['pos.session']
  34. self.pc = self.env.ref('point_of_sale.pos_config_main')
  35. self.rp_c2c = self.env.ref('base.res_partner_12')
  36. self.ppl_c2c = self.env.ref('product.list0')
  37. self.pp_usb = self.env.ref('product.product_product_48')
  38. self.rp_spe = self.env.ref(
  39. 'pos_order_pricelist_change.partner_surcharge')
  40. self.ppl_spe = self.env.ref(
  41. 'pos_order_pricelist_change.pricelist_surcharge')
  42. # Test Section
  43. def test_01_default_price_list(self):
  44. """[Regression Test] Sale with default Pricelist"""
  45. # Opening Session
  46. self.ps_obj.create({'config_id': self.pc.id})
  47. # create Pos Order
  48. po = self.po_obj.create({
  49. 'partner_id': self.rp_c2c.id,
  50. 'pricelist_id': self.ppl_c2c.id,
  51. 'lines': [[0, False, {
  52. 'product_id': self.pp_usb.id,
  53. 'qty': 1,
  54. }]],
  55. })
  56. res = po.lines[0].onchange_product_id(
  57. po.pricelist_id.id, po.lines[0].product_id.id, po.lines[0].qty)
  58. self.assertEquals(
  59. res['value']['price_subtotal'], self.pp_usb.list_price,
  60. "Incorrect price for default pricelist!")
  61. def test_02_partner_with_price_list_before(self):
  62. """[Regression Test] Sale with specific Pricelist"""
  63. # Opening Session
  64. self.ps_obj.create({'config_id': self.pc.id})
  65. # create Pos Order
  66. po = self.po_obj.create({
  67. 'partner_id': self.rp_spe.id,
  68. 'pricelist_id': self.ppl_spe.id,
  69. 'lines': [[0, False, {
  70. 'product_id': self.pp_usb.id,
  71. 'qty': 1,
  72. }]],
  73. })
  74. res = po.lines[0].onchange_product_id(
  75. po.pricelist_id.id, po.lines[0].product_id.id, po.lines[0].qty)
  76. self.assertEquals(
  77. res['value']['price_subtotal'], self.pp_usb.list_price + 10,
  78. "Incorrect price for specific pricelist!")
  79. def test_03_partner_with_price_list_after(self):
  80. """[Functional Test] Change pricelist after have set lines."""
  81. # Opening Session
  82. self.ps_obj.create({'config_id': self.pc.id})
  83. # create Pos Order
  84. po = self.po_obj.create({
  85. 'pricelist_id': self.ppl_c2c.id,
  86. 'lines': [[0, False, {
  87. 'product_id': self.pp_usb.id,
  88. 'qty': 1,
  89. }]],
  90. })
  91. res = po.onchange_pricelist_id()
  92. self.assertNotEquals(
  93. res.get('warning', False), False,
  94. "Need warning!")
  95. # Change now pricelist
  96. po.write({'pricelist_id': self.ppl_spe.id})
  97. po.action_recompute_pricelist()
  98. po = self.po_obj.browse(po.id)
  99. self.assertEquals(
  100. po.amount_total, self.pp_usb.list_price + 10,
  101. "Recompute with pricelist error.")