OCA reporting engine fork for dev and update.
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.

31 lines
935 B

  1. # Copyright 2020 Creu Blanca
  2. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
  3. from odoo.tests.common import TransactionCase
  4. class TestFormula(TransactionCase):
  5. def test_computation(self):
  6. kpi = self.env["kpi.kpi"].create(
  7. {
  8. "name": "DEMO KPI",
  9. "widget": "number",
  10. "computation_method": "code",
  11. }
  12. )
  13. self.assertFalse(kpi.value)
  14. kpi.compute()
  15. self.assertEqual(kpi.value, {})
  16. kpi.code = """
  17. result = {}
  18. result['value'] = len(model.search([('id', '=', %s)]))
  19. result['previous'] = len(model.search([('id', '!=', %s)]))
  20. """ % (
  21. kpi.id,
  22. kpi.id,
  23. )
  24. kpi.compute()
  25. value = kpi.value
  26. self.assertTrue(value.get("value"))
  27. self.assertEqual(value.get("value"), 1)
  28. self.assertEqual(value.get("previous"), kpi.search_count([]) - 1)