Initial commit: Odoo 18.0-20251222 extra-addons
This commit is contained in:
3
base_time_window/tests/__init__.py
Executable file
3
base_time_window/tests/__init__.py
Executable file
@@ -0,0 +1,3 @@
|
||||
from . import test_time_weekday
|
||||
from . import test_time_window_mixin
|
||||
from . import test_weekday
|
||||
12
base_time_window/tests/test_models.py
Executable file
12
base_time_window/tests/test_models.py
Executable file
@@ -0,0 +1,12 @@
|
||||
from odoo import fields, models
|
||||
|
||||
|
||||
class TestTimeWindowModel(models.Model):
|
||||
_name = "test.time.window.model"
|
||||
_description = "Test Time Window Model"
|
||||
_inherit = "time.window.mixin"
|
||||
_time_window_overlap_check_field = "partner_id"
|
||||
|
||||
partner_id = fields.Many2one(
|
||||
"res.partner", required=True, index=True, ondelete="cascade"
|
||||
)
|
||||
16
base_time_window/tests/test_time_weekday.py
Executable file
16
base_time_window/tests/test_time_weekday.py
Executable file
@@ -0,0 +1,16 @@
|
||||
# Copyright 2024 sodexis
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from odoo.tests.common import TransactionCase
|
||||
|
||||
|
||||
class TestTimeWeekday(TransactionCase):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
super().setUpClass()
|
||||
cls.time_weekday = cls.env["time.weekday"]
|
||||
cls.time_weekday_saturday = cls.time_weekday.search([("name", "=", "5")])
|
||||
|
||||
def test_weekday_delete(cls):
|
||||
cls.time_weekday._get_id_by_name(cls.time_weekday_saturday.name)
|
||||
cls.time_weekday_saturday.unlink()
|
||||
88
base_time_window/tests/test_time_window_mixin.py
Executable file
88
base_time_window/tests/test_time_window_mixin.py
Executable file
@@ -0,0 +1,88 @@
|
||||
from odoo_test_helper import FakeModelLoader
|
||||
|
||||
from odoo.exceptions import ValidationError
|
||||
from odoo.tests.common import TransactionCase
|
||||
|
||||
|
||||
class TestTimeWindowMixin(TransactionCase):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
super().setUpClass()
|
||||
|
||||
cls.customer1 = cls.env["res.partner"].create({"name": "Test1"})
|
||||
cls.customer2 = cls.env["res.partner"].create({"name": "Test2"})
|
||||
cls.customer3 = cls.env["res.partner"].create({"name": "Test3"})
|
||||
|
||||
cls.weekday1 = cls.env["time.weekday"].search([("name", "=", "1")])
|
||||
cls.weekday2 = cls.env["time.weekday"].search([("name", "=", "2")])
|
||||
|
||||
cls.loader = FakeModelLoader(cls.env, cls.__module__)
|
||||
cls.loader.backup_registry()
|
||||
from .test_models import TestTimeWindowModel
|
||||
|
||||
cls.loader.update_registry((TestTimeWindowModel,))
|
||||
|
||||
@classmethod
|
||||
def tearDownClass(cls):
|
||||
cls.loader.restore_registry()
|
||||
super().tearDownClass()
|
||||
|
||||
def test_time_window_no_overlap(self):
|
||||
with self.assertRaises(ValidationError):
|
||||
self.record1 = self.env["test.time.window.model"].create(
|
||||
{
|
||||
"partner_id": self.customer1.id,
|
||||
"time_window_start": 9.0,
|
||||
"time_window_end": 12.0,
|
||||
}
|
||||
)
|
||||
|
||||
with self.assertRaises(ValidationError):
|
||||
self.env["test.time.window.model"].create(
|
||||
{
|
||||
"partner_id": self.customer2.id,
|
||||
"time_window_start": 15.0,
|
||||
"time_window_end": 13.0,
|
||||
"time_window_weekday_ids": self.weekday1.ids,
|
||||
}
|
||||
)
|
||||
|
||||
self.record2 = self.env["test.time.window.model"].create(
|
||||
{
|
||||
"partner_id": self.customer3.id,
|
||||
"time_window_start": 13.0,
|
||||
"time_window_end": 15.0,
|
||||
"time_window_weekday_ids": self.weekday1.ids,
|
||||
}
|
||||
)
|
||||
self.assertTrue(self.record2)
|
||||
|
||||
with self.assertRaises(ValidationError):
|
||||
self.record3 = self.env["test.time.window.model"].create(
|
||||
{
|
||||
"partner_id": self.customer3.id,
|
||||
"time_window_start": 15.0,
|
||||
"time_window_end": 25.0,
|
||||
"time_window_weekday_ids": self.weekday1.ids,
|
||||
}
|
||||
)
|
||||
|
||||
with self.assertRaises(ValidationError):
|
||||
self.record4 = self.env["test.time.window.model"].create(
|
||||
{
|
||||
"partner_id": self.customer3.id,
|
||||
"time_window_start": 0.998,
|
||||
"time_window_end": 22.0,
|
||||
"time_window_weekday_ids": self.weekday1.ids,
|
||||
}
|
||||
)
|
||||
|
||||
with self.assertRaises(ValidationError):
|
||||
self.record5 = self.env["test.time.window.model"].create(
|
||||
{
|
||||
"partner_id": self.customer3.id,
|
||||
"time_window_start": 25,
|
||||
"time_window_end": 22.0,
|
||||
"time_window_weekday_ids": self.weekday1.ids,
|
||||
}
|
||||
)
|
||||
61
base_time_window/tests/test_weekday.py
Executable file
61
base_time_window/tests/test_weekday.py
Executable file
@@ -0,0 +1,61 @@
|
||||
# Copyright 2024 Camptocamp SA
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl)
|
||||
from odoo.fields import Date
|
||||
from odoo.tests.common import TransactionCase
|
||||
|
||||
|
||||
class TestWeekday(TransactionCase):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
super().setUpClass()
|
||||
time_weekday_mapping = dict(cls.env["time.weekday"]._fields["name"].selection)
|
||||
for val, name in time_weekday_mapping.items():
|
||||
setattr(
|
||||
cls,
|
||||
name.lower(),
|
||||
cls.env["time.weekday"].search([("name", "=", val)], limit=1),
|
||||
)
|
||||
|
||||
def test_next_weekday_date(self):
|
||||
# 2024-01-01 is Monday, next Monday (including date_from) is 2024-01-01
|
||||
self.assertEqual(
|
||||
self.monday._get_next_weekday_date(Date.to_date("2024-01-01")),
|
||||
Date.to_date("2024-01-01"),
|
||||
)
|
||||
# 2024-01-01 is Monday, next Monday (excluding date_from) is 2024-01-08
|
||||
self.assertEqual(
|
||||
self.monday._get_next_weekday_date(
|
||||
Date.to_date("2024-01-01"), include_date_from=False
|
||||
),
|
||||
Date.to_date("2024-01-08"),
|
||||
)
|
||||
# 2024-01-01 is Monday, next Tuesday is 2024-01-02
|
||||
self.assertEqual(
|
||||
self.tuesday._get_next_weekday_date(Date.to_date("2024-01-01")),
|
||||
Date.to_date("2024-01-02"),
|
||||
)
|
||||
# 2024-01-01 is Monday, next Wednesday is 2024-01-03
|
||||
self.assertEqual(
|
||||
self.wednesday._get_next_weekday_date(Date.to_date("2024-01-01")),
|
||||
Date.to_date("2024-01-03"),
|
||||
)
|
||||
# 2024-01-01 is Monday, next Thursday is 2024-01-04
|
||||
self.assertEqual(
|
||||
self.thursday._get_next_weekday_date(Date.to_date("2024-01-01")),
|
||||
Date.to_date("2024-01-04"),
|
||||
)
|
||||
# 2024-01-01 is Monday, next Friday is 2024-01-05
|
||||
self.assertEqual(
|
||||
self.friday._get_next_weekday_date(Date.to_date("2024-01-01")),
|
||||
Date.to_date("2024-01-05"),
|
||||
)
|
||||
# 2024-01-01 is Monday, next Saturday is 2024-01-06
|
||||
self.assertEqual(
|
||||
self.saturday._get_next_weekday_date(Date.to_date("2024-01-01")),
|
||||
Date.to_date("2024-01-06"),
|
||||
)
|
||||
# 2024-01-01 is Monday, next Sunday is 2024-01-07
|
||||
self.assertEqual(
|
||||
self.sunday._get_next_weekday_date(Date.to_date("2024-01-01")),
|
||||
Date.to_date("2024-01-07"),
|
||||
)
|
||||
Reference in New Issue
Block a user