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.

60 lines
2.2 KiB

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