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.

59 lines
2.0 KiB

  1. # -*- coding: utf-8 -*-
  2. import openerp.tests.common as common
  3. from openerp.exceptions import ValidationError
  4. def create_simple_contract(self, discount=0):
  5. partner_id = self.ref('base.res_partner_2')
  6. product_id = self.ref('product.product_product_consultant')
  7. uom_id = self.ref('product.product_uom_hour')
  8. line_values = [(0, 0, {'quantity': 2.0,
  9. 'price_unit': 100.0,
  10. 'discount': discount,
  11. 'name': 'Database Administration 25',
  12. 'product_id': product_id,
  13. 'uom_id': uom_id,
  14. })]
  15. values = {
  16. 'name': 'Maintenance of Servers',
  17. 'partner_id': partner_id,
  18. 'type': 'contract',
  19. 'recurring_invoices': 1,
  20. 'recurring_interval': 1,
  21. 'recurring_invoice_line_ids': line_values,
  22. }
  23. return self.env['account.analytic.account']\
  24. .create(values)
  25. class TestContractDiscount(common.TransactionCase):
  26. def setUp(self):
  27. super(TestContractDiscount, self).setUp()
  28. def test_create_simple_contract_without_discount(self):
  29. """Create contract without discount"""
  30. create_simple_contract(self)
  31. def test_create_simple_contract_with_discount(self):
  32. """Create contract with discount"""
  33. create_simple_contract(self, 50)
  34. create_simple_contract(self, 100)
  35. def test_create_simple_contract_with_negative_discount(self):
  36. """Create contract with negative discount"""
  37. create_simple_contract(self, -10)
  38. def test_discount_greater_than_100_error(self):
  39. """Create or write contract with greater than 100 discount"""
  40. contract = create_simple_contract(self)
  41. lines = contract.recurring_invoice_line_ids
  42. with self.assertRaises(ValidationError):
  43. lines.write({'discount': 110})
  44. with self.assertRaises(ValidationError):
  45. create_simple_contract(self, 150)