Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] base_location: relax sql constraint #1020

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions base_location/models/res_city.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ class City(models.Model):
_sql_constraints = [
(
"name_state_country_uniq",
"UNIQUE(name, state_id, country_id)",
"You already have a city with that name in the same state."
"The city must have a unique name within "
"UNIQUE(name, zipcode, state_id, country_id)",
"You already have a city with that name and zipcode in the same state."
"The city must have a unique name and zipcode within "
"it's state and it's country",
)
]
6 changes: 5 additions & 1 deletion base_location/tests/test_base_location.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,23 @@ def setUpClass(cls):
"name": "Barcelona",
"state_id": cls.state_bcn.id,
"country_id": cls.env.ref("base.es").id,
"zipcode": "",
}
)
cls.city_madrid = city_obj.create(
{
"name": "Madrid",
"state_id": cls.state_madrid.id,
"country_id": cls.env.ref("base.es").id,
"zipcode": "",
}
)
cls.city_lausanne = city_obj.create(
{
"name": "Lausanne",
"state_id": cls.state_vd.id,
"country_id": cls.env.ref("base.ch").id,
"zipcode": "",
}
)
cls.lausanne = zip_obj.create({"name": "666", "city_id": cls.city_lausanne.id})
Expand Down Expand Up @@ -229,7 +232,7 @@ def test_name_search(self):
self.assertEqual(len(found_recs), 1)
self.assertEqual(found_recs[0][0], self.lausanne.id)

def test_zip_ql_constraints(self):
def test_zip_sql_constraints(self):
"""Test UNIQUE name within it's area for zips"""
with self.assertRaises(psycopg2.IntegrityError), mute_logger("odoo.sql_db"):
self.env["res.city.zip"].create(
Expand All @@ -244,5 +247,6 @@ def test_city_sql_contraint(self):
"name": "Barcelona",
"state_id": self.state_bcn.id,
"country_id": self.ref("base.es"),
"zipcode": "",
}
)