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. # -*- 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. from odoo.tests import common
  5. from odoo import exceptions
  6. class TestContractVariableQuantity(common.SavepointCase):
  7. @classmethod
  8. def setUpClass(cls):
  9. super(TestContractVariableQuantity, cls).setUpClass()
  10. cls.partner = cls.env['res.partner'].create({
  11. 'name': 'Test partner',
  12. })
  13. cls.product = cls.env['product.product'].create({
  14. 'name': 'Test product',
  15. })
  16. cls.contract = cls.env['account.analytic.account'].create({
  17. 'name': 'Test Contract',
  18. 'partner_id': cls.partner.id,
  19. 'pricelist_id': cls.partner.property_product_pricelist.id,
  20. 'recurring_invoices': True,
  21. })
  22. cls.formula = cls.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. cls.contract_line = cls.env['account.analytic.invoice.line'].create({
  34. 'analytic_account_id': cls.contract.id,
  35. 'product_id': cls.product.id,
  36. 'name': 'Test',
  37. 'qty_type': 'variable',
  38. 'qty_formula_id': cls.formula.id,
  39. 'quantity': 1,
  40. 'uom_id': cls.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)