forked from odoo/odoo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FIX] base: allow finding states by
display_name
That is how states are (might be?) exported, so it should be possible to find them the same way. closes odoo#158984 Task-id: 3644762 X-original-commit: 26df8e2 Signed-off-by: Xavier Morel (xmo) <[email protected]>
- Loading branch information
Showing
3 changed files
with
68 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
from odoo.tests import TransactionCase, tagged | ||
|
||
|
||
@tagged('-at_install', 'post_install') | ||
class TestResCountryState(TransactionCase): | ||
def test_find_by_name(self): | ||
"""It should be possible to find a state by its display name | ||
""" | ||
glorious_arstotzka = self.env['res.country'].create({ | ||
'name': 'Arstotzka', | ||
'code': 'AA', | ||
}) | ||
altan = self.env['res.country.state'].create({ | ||
'country_id': glorious_arstotzka.id, | ||
'code': 'AL', | ||
'name': 'Altan', | ||
}) | ||
|
||
for name in [ | ||
altan.name, | ||
altan.display_name, | ||
'Altan(AA)', | ||
'Altan ( AA )', | ||
'Altan (Arstotzka)', | ||
'Altan (Arst)', # dubious | ||
]: | ||
with self.subTest(name): | ||
self.assertEqual( | ||
self.env['res.country.state'].name_search(name, operator='='), | ||
[(altan.id, altan.display_name)] | ||
) | ||
|
||
# imitates basque provinces | ||
vescillo = self.env['res.country.state'].create({ | ||
'country_id': glorious_arstotzka.id, | ||
'code': 'VE', | ||
'name': "Vescillo (Vesilo)", | ||
}) | ||
for name in [ | ||
vescillo.name, | ||
vescillo.display_name, | ||
"vescillo", | ||
"vesilo", | ||
"vescillo (AA)", | ||
"vesilo (AA)", | ||
"vesilo (Arstotzka)", | ||
]: | ||
with self.subTest(name): | ||
# note operator for more flexible state name matching | ||
self.assertEqual( | ||
self.env['res.country.state'].name_search(name, operator='ilike'), | ||
[(vescillo.id, vescillo.display_name)] | ||
) |