Skip to content

Commit

Permalink
[MIG] partner_tag_smart_assignation: migration to 17.0
Browse files Browse the repository at this point in the history
  • Loading branch information
robinrolle committed Dec 3, 2024
1 parent 13149e7 commit bb78485
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 27 deletions.
2 changes: 1 addition & 1 deletion partner_tag_smart_assignation/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{
"name": "Smart Tagger",
"summary": "Smart tagger, module to have smart tags who " "update themselves alone",
"version": "16.0.1.0.0",
"version": "17.0.1.0.0",
"category": "Other",
"author": "Compassion CH, Odoo Community Association (OCA)",
"license": "AGPL-3",
Expand Down
24 changes: 13 additions & 11 deletions partner_tag_smart_assignation/tests/test_smart_tagger.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
from datetime import timedelta

from odoo import fields
from odoo.tests.common import SavepointCase
from odoo.tests.common import TransactionCase

logger = logging.getLogger(__name__)


class TestSmartTagger(SavepointCase):
class TestSmartTagger(TransactionCase):
@classmethod
def setUpClass(cls):
"""Load test data."""
Expand All @@ -23,6 +23,7 @@ def setUpClass(cls):
michel_fletcher + chao_wang + david_simpson + john_m_brown + charlie_bernard
)
cls.michel_fletcher = michel_fletcher
cls.david_simpson = david_simpson

def create_condition(self):
"""
Expand All @@ -34,7 +35,7 @@ def create_condition(self):
"user_id": False,
"model_id": "res.partner",
"active": True,
"domain": '[["name","ilike","o"]]',
"domain": '[["name","like","o"]]',
"context": "{}",
"sort": "[]",
"name": "SmartTagTestCondition",
Expand Down Expand Up @@ -75,7 +76,7 @@ def test_create_tag(self):
self.assertFalse(partner in smart_tag.partner_ids)

for partner in smart_tag.partner_ids:
self.assertTrue("o" in partner.name)
self.assertIn("o", partner.name)

def test_modify_partner(self):
"""
Expand All @@ -96,7 +97,7 @@ def test_modify_partner(self):
self.assertTrue(michael in smart_tag.partner_ids)

for partner in smart_tag.partner_ids:
self.assertTrue("o" in partner.name)
self.assertIn("o", partner.name)

def test_smart_tag_sql(self):
"""Test query SQL for smart tags"""
Expand Down Expand Up @@ -130,16 +131,17 @@ def test_check_validity_dates(self):
"""
Test if the valid_until functionality works correctly
"""

# Create a new tag with a 'valid_until' date set to yesterday
yesterday = fields.Date.to_string(fields.Date.today() - timedelta(days=1))

expired_tag = self.create_tag()
expired_tag.update({"valid_until": yesterday})
expired_tag.update_partner_tags()

# Reload the tags from the database
expired_tag.invalidate_cache()
# Run the method which is supposed to deactivate expired tags
self.env["res.partner.category"]._check_validity_dates()

# Invalidate cache for the specific record
expired_tag.invalidate_recordset()

# Check that the expired tag is now inactive
self.assertFalse(expired_tag.active)
Expand All @@ -154,8 +156,8 @@ def test_check_validity_dates(self):
# Run the method which is supposed to deactivate expired tags
self.env["res.partner.category"]._check_validity_dates()

# Reload the tags from the database
active_tag.invalidate_cache()
# Invalidate cache for the specific record
active_tag.invalidate_recordset()

# Check that the active tag is still active
self.assertTrue(active_tag.active)
21 changes: 6 additions & 15 deletions partner_tag_smart_assignation/views/smart_tagger_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@
<field name="author_id" />
<field name="department_ids" />
<field name="description" />
<field
name="valid_until"
attrs="{'invisible': [('smart', '=', False)],}"
/>
<field name="valid_until" invisible="smart == False" />
</field>
</field>
</record>
Expand Down Expand Up @@ -44,26 +41,20 @@
<field name="author_id" />
<field name="department_ids" widget="many2many_tags" />
<field name="description" />
<field
name="valid_until"
attrs="{'invisible': [('smart', '=', False)],}"
/>
<field
name="tag_filter_join_operator"
attrs="{'invisible': [('smart', '=', False)],}"
/>
<field name="valid_until" invisible="smart == False" />
<field name="tag_filter_join_operator" invisible="smart == False" />
<field
name="tag_filter_condition_id"
attrs="{'invisible': [('smart', '=', False)],}"
invisible="smart == False"
context="{'default_model_id':'res.partner'}"
/>
<field
name="tag_filter_partner_field"
attrs="{'invisible': ['|', ('smart', '=', False), ('tag_filter_condition_id', '=', False)],}"
invisible="smart == False or tag_filter_condition_id == False"
/>
<field
name="tag_filter_sql_query"
attrs="{'invisible': [('smart', '=', False)],}"
invisible="smart == False"
widget="ace"
/>
</field>
Expand Down

0 comments on commit bb78485

Please sign in to comment.