[FIX] base: make country code required

Steps to reproduce:
- Go to Contact-Configuration-Countries
- Remove the code of a country
- Create a new contact
- Select the country from which you deleted the code
- Put any vat number starting with country code you deleted

Issue:
Traceback

Cause:
in `_run_vat_test` we want to `country.code.lower()` -> country code does not exist

Solution:
Prevent the user to delete a country code by making the field required.

sentry-3923412146

closes odoo/odoo#113207

Signed-off-by: William André (wan) <wan@odoo.com>
This commit is contained in:
Yolann Sabaux
2023-03-07 11:11:42 +01:00
parent 34f5441a5f
commit afe6f967cd
8 changed files with 14 additions and 9 deletions
@@ -31,7 +31,7 @@ class TestIsMultiLang(odoo.tests.HttpCase):
it = self.env.ref('base.lang_it').sudo()
en = self.env.ref('base.lang_en').sudo()
be = self.env.ref('base.lang_fr_BE').sudo()
country1 = self.env['res.country'].create({'name': "My Super Country"})
country1 = self.env['res.country'].create({'name': "My Super Country", 'code': 'ZV'})
it.active = True
be.active = True
+1
View File
@@ -38,6 +38,7 @@ class Country(models.Model):
string='Country Name', required=True, translate=True)
code = fields.Char(
string='Country Code', size=2,
required=True,
help='The ISO country code in two chars. \nYou can use this field for quick search.')
address_format = fields.Text(string="Layout in Reports",
help="Display format to use for addresses belonging to this country.\n\n"
@@ -64,6 +64,7 @@ class TestFormCreate(TransactionCase):
def test_create_res_country(self):
country_form = Form(self.env['res.country'])
country_form.name = 'a country'
country_form.code = 'ZX'
country_form.save()
def test_create_res_lang(self):
+4 -2
View File
@@ -45,13 +45,13 @@ class TestORM(TransactionCase):
self.assertTrue(type(Model).display_name.automatic, "test assumption not satisfied")
# access regular field when another record from the same prefetch set has been deleted
records = Model.create([{'name': name} for name in ('Foo', 'Bar', 'Baz')])
records = Model.create([{'name': name[0], 'code': name[1]} for name in (['Foo', 'ZV'], ['Bar', 'ZX'], ['Baz', 'ZY'])])
for record in records:
record.name
record.unlink()
# access computed field when another record from the same prefetch set has been deleted
records = Model.create([{'name': name} for name in ('Foo', 'Bar', 'Baz')])
records = Model.create([{'name': name[0], 'code': name[1]} for name in (['Foo', 'ZV'], ['Bar', 'ZX'], ['Baz', 'ZY'])])
for record in records:
record.display_name
record.unlink()
@@ -285,12 +285,14 @@ class TestORM(TransactionCase):
Command.create({'name': 'West Foo', 'code': 'WF'}),
Command.create({'name': 'East Foo', 'code': 'EF'}),
],
'code': 'ZV',
}, {
'name': 'Bar',
'state_ids': [
Command.create({'name': 'North Bar', 'code': 'NB'}),
Command.create({'name': 'South Bar', 'code': 'SB'}),
],
'code': 'ZX',
}]
foo, bar = self.env['res.country'].create(vals_list)
self.assertEqual(foo.name, 'Foo')
+1 -1
View File
@@ -193,7 +193,7 @@ class TestPartner(TransactionCase):
def test_display_address_missing_key(self):
""" Check _display_address when some keys are missing. As a defaultdict is used, missing keys should be
filled with empty strings. """
country = self.env["res.country"].create({"name": "TestCountry", "address_format": "%(city)s %(zip)s"})
country = self.env["res.country"].create({"name": "TestCountry", "address_format": "%(city)s %(zip)s", "code": "ZV"})
partner = self.env["res.partner"].create({
"name": "TestPartner",
"country_id": country.id,
+1 -1
View File
@@ -166,7 +166,7 @@ class test_search(TransactionCase):
'ttype': 'boolean',
})
self.assertEqual('x_active', model_country._active_name)
country_ussr = model_country.create({'name': 'USSR', 'x_active': False})
country_ussr = model_country.create({'name': 'USSR', 'x_active': False, 'code': 'ZV'})
ussr_search = model_country.search([('name', '=', 'USSR')])
self.assertFalse(ussr_search)
ussr_search = model_country.with_context(active_test=False).search([('name', '=', 'USSR')])
@@ -661,8 +661,9 @@ class TestFields(TransactionCaseWithUserDemo):
def test_13_inverse_with_unlink(self):
""" test x2many delete command combined with an inverse field """
country1 = self.env['res.country'].create({'name': 'test country'})
country2 = self.env['res.country'].create({'name': 'other country'})
country1 = self.env['res.country'].create({'name': 'test country', 'code': 'ZV'})
country2 = self.env['res.country'].create({'name': 'other country', 'code': 'ZX'})
company = self.env['res.company'].create({
'name': 'test company',
'child_ids': [
@@ -254,7 +254,7 @@ class TestSchema(common.TransactionCase):
def test_10_char(self):
""" check the database representation of a char field """
model = self.env['res.country']
self.assertFalse(type(model).code.required)
self.assertTrue(type(model).code.required)
self.assertEqual(type(model).code.size, 2)
columns_data = self.get_columns_data(model._table)
self.assertEqual(columns_data['code'], {
@@ -263,7 +263,7 @@ class TestSchema(common.TransactionCase):
'column_name': u'code',
'data_type': u'character varying',
'datetime_precision': None,
'is_nullable': u'YES',
'is_nullable': u'NO',
'is_updatable': u'YES',
'numeric_precision': None,
'numeric_precision_radix': None,