Skip to content

Commit

Permalink
[MIG] base_time_window: Migration to 17.0
Browse files Browse the repository at this point in the history
  • Loading branch information
arulraj committed Oct 14, 2024
1 parent da8effe commit 376bc15
Show file tree
Hide file tree
Showing 9 changed files with 121 additions and 11 deletions.
1 change: 1 addition & 0 deletions base_time_window/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ Contributors

- Laurent Mignon <[email protected]>
- Akim Juillerat <[email protected]>
- SodexisTeam <[email protected]>

Trobz

Expand Down
2 changes: 1 addition & 1 deletion base_time_window/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{
"name": "Base Time Window",
"summary": "Base model to handle time windows",
"version": "16.0.1.0.0",
"version": "17.0.1.0.0",
"category": "Technical Settings",
"author": "ACSONE SA/NV, Camptocamp, Odoo Community Association (OCA)",
"license": "AGPL-3",
Expand Down
13 changes: 3 additions & 10 deletions base_time_window/models/time_weekday.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,6 @@ def _compute_display_name(self):
for record in self:
record.display_name = translated_values[record.name]

def name_get(self):
"""
WORKAROUND since Odoo doesn't handle properly records where name is
a selection
"""
return [(r.id, r.display_name) for r in self]

@api.model
@tools.ormcache("name")
def _get_id_by_name(self, name):
Expand All @@ -47,15 +40,15 @@ def _get_id_by_name(self, name):
@api.model_create_multi
def create(self, vals_list):
records = super().create(vals_list)
self._get_id_by_name.clear_cache(self)
self.env.registry.clear_cache() # _get_id_by_name
return records

def write(self, vals):
result = super().write(vals)
self._get_id_by_name.clear_cache(self)
self.env.registry.clear_cache() # _get_id_by_name
return result

Check warning on line 49 in base_time_window/models/time_weekday.py

View check run for this annotation

Codecov / codecov/patch

base_time_window/models/time_weekday.py#L47-L49

Added lines #L47 - L49 were not covered by tests

def unlink(self):
result = super().unlink()
self._get_id_by_name.clear_cache(self)
self.env.registry.clear_cache() # _get_id_by_name
return result
1 change: 1 addition & 0 deletions base_time_window/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
- Laurent Mignon \<<[email protected]>\>
- Akim Juillerat \<<[email protected]>\>
- SodexisTeam \<<[email protected]>\>

Trobz

Expand Down
1 change: 1 addition & 0 deletions base_time_window/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,7 @@ <h2><a class="toc-backref" href="#toc-entry-6">Contributors</a></h2>
<ul class="simple">
<li>Laurent Mignon &lt;<a class="reference external" href="mailto:laurent.mignon&#64;acsone.eu">laurent.mignon&#64;acsone.eu</a>&gt;</li>
<li>Akim Juillerat &lt;<a class="reference external" href="mailto:akim.juillerat&#64;camptocamp.com">akim.juillerat&#64;camptocamp.com</a>&gt;</li>
<li>SodexisTeam &lt;<a class="reference external" href="mailto:dev&#64;sodexis.com">dev&#64;sodexis.com</a>&gt;</li>
</ul>
<p>Trobz</p>
<ul class="simple">
Expand Down
3 changes: 3 additions & 0 deletions base_time_window/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from . import test_time_weekday
from . import test_time_window_mixin
from . import test_models
12 changes: 12 additions & 0 deletions base_time_window/tests/test_models.py
Original file line number Diff line number Diff line change
@@ -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 changes: 16 additions & 0 deletions base_time_window/tests/test_time_weekday.py
Original file line number Diff line number Diff line change
@@ -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()
83 changes: 83 additions & 0 deletions base_time_window/tests/test_time_window_mixin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
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.loader = FakeModelLoader(cls.env, cls.__module__)
cls.loader.backup_registry()
from .test_models import TestTimeWindowModel

cls.loader.update_registry((TestTimeWindowModel,))

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")])

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,
}
)

0 comments on commit 376bc15

Please sign in to comment.