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.

70 lines
2.6 KiB

  1. # -*- coding: utf-8 -*-
  2. # Copyright 2018 ACSONE SA/NV.
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  4. from odoo.tests.common import TransactionCase
  5. class TestSaleOrder(TransactionCase):
  6. def setUp(self):
  7. super(TestSaleOrder, self).setUp()
  8. self.product1 = self.env.ref('product.product_product_1')
  9. self.sale = self.env.ref('sale.sale_order_2')
  10. self.contract_template1 = self.env['contract.template'].create(
  11. {'name': 'Template 1'}
  12. )
  13. self.formula = self.env['contract.line.qty.formula'].create(
  14. {
  15. 'name': 'Test formula',
  16. # For testing each of the possible variables
  17. 'code': 'env["res.users"]\n'
  18. 'context.get("lang")\n'
  19. 'user.id\n'
  20. 'line.qty_type\n'
  21. 'contract.id\n'
  22. 'invoice.id\n'
  23. 'result = 12',
  24. }
  25. )
  26. self.product1.write(
  27. {
  28. 'is_contract': True,
  29. 'default_qty': 12,
  30. 'contract_template_id': self.contract_template1.id,
  31. 'qty_formula_id': self.formula.id,
  32. 'qty_type': 'variable',
  33. }
  34. )
  35. self.order_line1 = self.sale.order_line.filtered(
  36. lambda l: l.product_id == self.product1
  37. )
  38. def test_change_is_contract(self):
  39. product_tmpl = self.product1.product_tmpl_id
  40. product_tmpl.is_contract = False
  41. self.assertTrue(product_tmpl.qty_type)
  42. product_tmpl._change_is_contract()
  43. self.assertFalse(product_tmpl.qty_type)
  44. def test_onchange_product_id(self):
  45. self.order_line1.onchange_product()
  46. self.assertEqual(
  47. self.order_line1.qty_formula_id, self.product1.qty_formula_id
  48. )
  49. self.assertEqual(self.order_line1.qty_type, self.product1.qty_type)
  50. def test_action_confirm(self):
  51. self.order_line1.onchange_product()
  52. self.sale.action_confirm()
  53. contract = self.order_line1.contract_id
  54. contract_line = contract.contract_line_ids.filtered(
  55. lambda line: line.product_id == self.product1
  56. )
  57. self.assertEqual(
  58. contract_line.qty_formula_id, self.product1.qty_formula_id
  59. )
  60. self.assertEqual(contract_line.qty_type, self.product1.qty_type)
  61. self.assertEqual(contract_line.qty_type, 'variable')
  62. self.product1.product_tmpl_id.qty_type = 'fixed'
  63. contract_line._onchange_product_id_recurring_info()
  64. self.assertEqual(contract_line.qty_type, 'fixed')