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.

75 lines
2.8 KiB

  1. # Copyright 2016 Tecnativa - Pedro M. Baeza
  2. # Copyright 2018 Tecnativa - Carlos Dauden
  3. # Copyright 2018 ACSONE SA/NV
  4. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
  5. import odoo.tests
  6. from odoo import exceptions
  7. @odoo.tests.at_install(False)
  8. @odoo.tests.post_install(True)
  9. class TestContractVariableQuantity(odoo.tests.HttpCase):
  10. def setUp(self):
  11. super(TestContractVariableQuantity, self).setUp()
  12. self.partner = self.env['res.partner'].create({
  13. 'name': 'Test partner',
  14. })
  15. self.product = self.env['product.product'].create({
  16. 'name': 'Test product',
  17. })
  18. self.contract = self.env['account.analytic.account'].create({
  19. 'name': 'Test Contract',
  20. 'partner_id': self.partner.id,
  21. 'pricelist_id': self.partner.property_product_pricelist.id,
  22. 'recurring_invoices': True,
  23. })
  24. self.formula = self.env['contract.line.qty.formula'].create({
  25. 'name': 'Test formula',
  26. # For testing each of the possible variables
  27. 'code': 'env["res.users"]\n'
  28. 'context.get("lang")\n'
  29. 'user.id\n'
  30. 'line.qty_type\n'
  31. 'contract.id\n'
  32. 'invoice.id\n'
  33. 'result = 12',
  34. })
  35. self.contract_line = self.env['account.analytic.invoice.line'].create({
  36. 'contract_id': self.contract.id,
  37. 'product_id': self.product.id,
  38. 'name': 'Test',
  39. 'qty_type': 'variable',
  40. 'qty_formula_id': self.formula.id,
  41. 'quantity': 1,
  42. 'uom_id': self.product.uom_id.id,
  43. 'price_unit': 100,
  44. 'discount': 50,
  45. 'recurring_rule_type': 'monthly',
  46. 'recurring_interval': 1,
  47. 'date_start': '2016-02-15',
  48. 'recurring_next_date': '2016-02-29',
  49. })
  50. def test_check_invalid_code(self):
  51. with self.assertRaises(exceptions.ValidationError):
  52. self.formula.code = "sdsds"
  53. def test_check_no_return_value(self):
  54. with self.assertRaises(exceptions.ValidationError):
  55. self.formula.code = "user.id"
  56. def test_check_variable_quantity(self):
  57. self.contract.recurring_create_invoice()
  58. invoice = self.env['account.invoice'].search(
  59. [('contract_id', '=', self.contract.id)])
  60. self.assertEqual(invoice.invoice_line_ids[0].quantity, 12)
  61. def test_check_skip_zero_qty(self):
  62. self.formula.code = 'result=0'
  63. self.contract.skip_zero_qty = True
  64. invoice = self.contract.recurring_create_invoice()
  65. self.assertFalse(invoice.invoice_line_ids)
  66. self.contract.skip_zero_qty = False
  67. invoice = self.contract.recurring_create_invoice()
  68. self.assertAlmostEqual(invoice.invoice_line_ids[0].quantity, 0.0)