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.

61 lines
2.2 KiB

  1. # -*- coding: utf-8 -*-
  2. # © 2016 Pedro M. Baeza <pedro.baeza@tecnativa.com>
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
  4. import odoo.tests
  5. from odoo import exceptions
  6. @odoo.tests.at_install(False)
  7. @odoo.tests.post_install(True)
  8. class TestContractVariableQuantity(odoo.tests.HttpCase):
  9. def setUp(self):
  10. super(TestContractVariableQuantity, self).setUp()
  11. self.partner = self.env['res.partner'].create({
  12. 'name': 'Test partner',
  13. })
  14. self.product = self.env['product.product'].create({
  15. 'name': 'Test product',
  16. })
  17. self.contract = self.env['account.analytic.account'].create({
  18. 'name': 'Test Contract',
  19. 'partner_id': self.partner.id,
  20. 'pricelist_id': self.partner.property_product_pricelist.id,
  21. 'recurring_invoices': True,
  22. })
  23. self.formula = self.env['contract.line.qty.formula'].create({
  24. 'name': 'Test formula',
  25. # For testing each of the possible variables
  26. 'code': 'env["res.users"]\n'
  27. 'context.get("lang")\n'
  28. 'user.id\n'
  29. 'line.qty_type\n'
  30. 'contract.id\n'
  31. 'invoice.id\n'
  32. 'result = 12',
  33. })
  34. self.contract_line = self.env['account.analytic.invoice.line'].create({
  35. 'analytic_account_id': self.contract.id,
  36. 'product_id': self.product.id,
  37. 'name': 'Test',
  38. 'qty_type': 'variable',
  39. 'qty_formula_id': self.formula.id,
  40. 'quantity': 1,
  41. 'uom_id': self.product.uom_id.id,
  42. 'price_unit': 100,
  43. 'discount': 50,
  44. })
  45. def test_check_invalid_code(self):
  46. with self.assertRaises(exceptions.ValidationError):
  47. self.formula.code = "sdsds"
  48. def test_check_no_return_value(self):
  49. with self.assertRaises(exceptions.ValidationError):
  50. self.formula.code = "user.id"
  51. def test_check_variable_quantity(self):
  52. self.contract._create_invoice()
  53. invoice = self.env['account.invoice'].search(
  54. [('contract_id', '=', self.contract.id)])
  55. self.assertEqual(invoice.invoice_line_ids[0].quantity, 12)