test_overdue.py 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. # -*- coding: utf-8 -*-
  2. # Part of Odoo. See LICENSE file for full copyright and licensing details.
  3. from odoo.tests import common, new_test_user
  4. from odoo import fields
  5. class TestFleet(common.TransactionCase):
  6. def test_search_renewal(self):
  7. """
  8. Should find the car with overdue contract or renewal due soon
  9. """
  10. user = new_test_user(self.env, "test base user", groups="base.group_user")
  11. brand = self.env["fleet.vehicle.model.brand"].create({
  12. "name": "Audi",
  13. })
  14. model = self.env["fleet.vehicle.model"].create({
  15. "brand_id": brand.id,
  16. "name": "A3",
  17. })
  18. car_1 = self.env["fleet.vehicle"].create({
  19. "model_id": model.id,
  20. "driver_id": user.partner_id.id,
  21. "plan_to_change_car": False
  22. })
  23. car_2 = self.env["fleet.vehicle"].create({
  24. "model_id": model.id,
  25. "driver_id": user.partner_id.id,
  26. "plan_to_change_car": False
  27. })
  28. Log = self.env['fleet.vehicle.log.contract']
  29. Log.create({
  30. 'vehicle_id': car_2.id,
  31. 'expiration_date': fields.Date.add(fields.Date.today(), days=10)
  32. })
  33. res = self.env["fleet.vehicle"].search([('contract_renewal_due_soon', '=', True), ('id', '=', car_2.id)])
  34. self.assertEqual(res, car_2)
  35. Log.create({
  36. 'vehicle_id': car_1.id,
  37. 'expiration_date': fields.Date.add(fields.Date.today(), days=-10)
  38. })
  39. res = self.env["fleet.vehicle"].search([('contract_renewal_overdue', '=', True), ('id', '=', car_1.id)])
  40. self.assertEqual(res, car_1)