|
|
@ -2,7 +2,9 @@ |
|
|
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). |
|
|
|
|
|
|
|
from datetime import datetime, timedelta |
|
|
|
|
|
|
|
from mock import patch |
|
|
|
|
|
|
|
from odoo import fields |
|
|
|
from odoo.tests.common import SavepointCase |
|
|
|
|
|
|
@ -15,47 +17,65 @@ class CanICallCase(SavepointCase): |
|
|
|
super(CanICallCase, cls).setUpClass() |
|
|
|
cls.Calendar = cls.env["resource.calendar"].with_context(tz="UTC") |
|
|
|
cls.Partner = cls.env["res.partner"].with_context(tz="UTC") |
|
|
|
cls.some_mornings = cls.Calendar.create({ |
|
|
|
"name": "Some mornings", |
|
|
|
"attendance_ids": [ |
|
|
|
(0, 0, { |
|
|
|
"name": "Friday morning", |
|
|
|
"dayofweek": "4", |
|
|
|
"hour_from": 8, |
|
|
|
"hour_to": 12, |
|
|
|
}), |
|
|
|
(0, 0, { |
|
|
|
"name": "Next monday morning", |
|
|
|
"dayofweek": "0", |
|
|
|
"hour_from": 8, |
|
|
|
"hour_to": 12, |
|
|
|
"date_from": "2017-09-18", |
|
|
|
"date_to": "2017-09-18", |
|
|
|
}), |
|
|
|
], |
|
|
|
}) |
|
|
|
cls.some_evenings = cls.Calendar.create({ |
|
|
|
"name": "Some evenings", |
|
|
|
"attendance_ids": [ |
|
|
|
(0, 0, { |
|
|
|
"name": "Friday evening", |
|
|
|
"dayofweek": "4", |
|
|
|
"hour_from": 15, |
|
|
|
"hour_to": 19, |
|
|
|
}), |
|
|
|
(0, 0, { |
|
|
|
"name": "Next monday evening", |
|
|
|
"dayofweek": "0", |
|
|
|
"hour_from": 15, |
|
|
|
"hour_to": 19, |
|
|
|
"date_from": "2017-09-18", |
|
|
|
"date_to": "2017-09-18", |
|
|
|
}), |
|
|
|
], |
|
|
|
}) |
|
|
|
cls.dude = cls.Partner.create({ |
|
|
|
"name": "Dude", |
|
|
|
}) |
|
|
|
cls.some_mornings = cls.Calendar.create( |
|
|
|
{ |
|
|
|
"name": "Some mornings", |
|
|
|
"attendance_ids": [ |
|
|
|
( |
|
|
|
0, |
|
|
|
0, |
|
|
|
{ |
|
|
|
"name": "Friday morning", |
|
|
|
"dayofweek": "4", |
|
|
|
"hour_from": 8, |
|
|
|
"hour_to": 12, |
|
|
|
}, |
|
|
|
), |
|
|
|
( |
|
|
|
0, |
|
|
|
0, |
|
|
|
{ |
|
|
|
"name": "Next monday morning", |
|
|
|
"dayofweek": "0", |
|
|
|
"hour_from": 8, |
|
|
|
"hour_to": 12, |
|
|
|
"date_from": "2017-09-18", |
|
|
|
"date_to": "2017-09-18", |
|
|
|
}, |
|
|
|
), |
|
|
|
], |
|
|
|
} |
|
|
|
) |
|
|
|
cls.some_evenings = cls.Calendar.create( |
|
|
|
{ |
|
|
|
"name": "Some evenings", |
|
|
|
"attendance_ids": [ |
|
|
|
( |
|
|
|
0, |
|
|
|
0, |
|
|
|
{ |
|
|
|
"name": "Friday evening", |
|
|
|
"dayofweek": "4", |
|
|
|
"hour_from": 15, |
|
|
|
"hour_to": 19, |
|
|
|
}, |
|
|
|
), |
|
|
|
( |
|
|
|
0, |
|
|
|
0, |
|
|
|
{ |
|
|
|
"name": "Next monday evening", |
|
|
|
"dayofweek": "0", |
|
|
|
"hour_from": 15, |
|
|
|
"hour_to": 19, |
|
|
|
"date_from": "2017-09-18", |
|
|
|
"date_to": "2017-09-18", |
|
|
|
}, |
|
|
|
), |
|
|
|
], |
|
|
|
} |
|
|
|
) |
|
|
|
cls.dude = cls.Partner.create({"name": "Dude"}) |
|
|
|
cls.dude.phonecall_calendar_ids = cls.some_mornings |
|
|
|
|
|
|
|
def setUp(self): |
|
|
@ -69,22 +89,18 @@ class CanICallCase(SavepointCase): |
|
|
|
dude = dude.with_context(now=now) |
|
|
|
Partner = Partner.with_context(now=now) |
|
|
|
self.assertTrue(dude.phonecall_available) |
|
|
|
self.assertTrue(Partner.search([ |
|
|
|
("id", "=", dude.id), |
|
|
|
("phonecall_available", "=", True), |
|
|
|
])) |
|
|
|
self.assertTrue(Partner.search([ |
|
|
|
("id", "=", dude.id), |
|
|
|
("phonecall_available", "!=", False), |
|
|
|
])) |
|
|
|
self.assertFalse(Partner.search([ |
|
|
|
("id", "=", dude.id), |
|
|
|
("phonecall_available", "=", False), |
|
|
|
])) |
|
|
|
self.assertFalse(Partner.search([ |
|
|
|
("id", "=", dude.id), |
|
|
|
("phonecall_available", "!=", True), |
|
|
|
])) |
|
|
|
self.assertTrue( |
|
|
|
Partner.search([("id", "=", dude.id), ("phonecall_available", "=", True)]) |
|
|
|
) |
|
|
|
self.assertTrue( |
|
|
|
Partner.search([("id", "=", dude.id), ("phonecall_available", "!=", False)]) |
|
|
|
) |
|
|
|
self.assertFalse( |
|
|
|
Partner.search([("id", "=", dude.id), ("phonecall_available", "=", False)]) |
|
|
|
) |
|
|
|
self.assertFalse( |
|
|
|
Partner.search([("id", "=", dude.id), ("phonecall_available", "!=", True)]) |
|
|
|
) |
|
|
|
|
|
|
|
def allowed(self): |
|
|
|
# Test mocking datetime.now() |
|
|
@ -95,8 +111,7 @@ class CanICallCase(SavepointCase): |
|
|
|
# Test sending a datetime object in the context |
|
|
|
self._allowed(self.datetime) |
|
|
|
# Test sending a string in the context |
|
|
|
self._allowed( |
|
|
|
fields.Datetime.to_string(self.datetime)) |
|
|
|
self._allowed(fields.Datetime.to_string(self.datetime)) |
|
|
|
|
|
|
|
def _disallowed(self, now=None): |
|
|
|
dude, Partner = self.dude, self.Partner |
|
|
@ -104,22 +119,18 @@ class CanICallCase(SavepointCase): |
|
|
|
dude = dude.with_context(now=now) |
|
|
|
Partner = Partner.with_context(now=now) |
|
|
|
self.assertFalse(dude.phonecall_available) |
|
|
|
self.assertFalse(Partner.search([ |
|
|
|
("id", "=", dude.id), |
|
|
|
("phonecall_available", "=", True), |
|
|
|
])) |
|
|
|
self.assertFalse(Partner.search([ |
|
|
|
("id", "=", dude.id), |
|
|
|
("phonecall_available", "!=", False), |
|
|
|
])) |
|
|
|
self.assertTrue(Partner.search([ |
|
|
|
("id", "=", dude.id), |
|
|
|
("phonecall_available", "=", False), |
|
|
|
])) |
|
|
|
self.assertTrue(Partner.search([ |
|
|
|
("id", "=", dude.id), |
|
|
|
("phonecall_available", "!=", True), |
|
|
|
])) |
|
|
|
self.assertFalse( |
|
|
|
Partner.search([("id", "=", dude.id), ("phonecall_available", "=", True)]) |
|
|
|
) |
|
|
|
self.assertFalse( |
|
|
|
Partner.search([("id", "=", dude.id), ("phonecall_available", "!=", False)]) |
|
|
|
) |
|
|
|
self.assertTrue( |
|
|
|
Partner.search([("id", "=", dude.id), ("phonecall_available", "=", False)]) |
|
|
|
) |
|
|
|
self.assertTrue( |
|
|
|
Partner.search([("id", "=", dude.id), ("phonecall_available", "!=", True)]) |
|
|
|
) |
|
|
|
|
|
|
|
def disallowed(self): |
|
|
|
# Test mocking datetime.now() |
|
|
@ -130,8 +141,7 @@ class CanICallCase(SavepointCase): |
|
|
|
# Test sending a datetime object in the context |
|
|
|
self._disallowed(self.datetime) |
|
|
|
# Test sending a string in the context |
|
|
|
self._disallowed( |
|
|
|
fields.Datetime.to_string(self.datetime)) |
|
|
|
self._disallowed(fields.Datetime.to_string(self.datetime)) |
|
|
|
|
|
|
|
def test_friday_morning(self): |
|
|
|
"""I can call dude this morning""" |
|
|
@ -166,6 +176,6 @@ class CanICallCase(SavepointCase): |
|
|
|
"""I get aggregated schedules correctly.""" |
|
|
|
self.dude.phonecall_calendar_ids |= self.some_evenings |
|
|
|
all_attendances = (self.some_mornings | self.some_evenings).mapped( |
|
|
|
"attendance_ids") |
|
|
|
self.assertEqual( |
|
|
|
self.dude.phonecall_calendar_attendance_ids, all_attendances) |
|
|
|
"attendance_ids" |
|
|
|
) |
|
|
|
self.assertEqual(self.dude.phonecall_calendar_attendance_ids, all_attendances) |