diff --git a/addons/website/models/website_visitor.py b/addons/website/models/website_visitor.py index ca54d20d883..b4eccd5264e 100644 --- a/addons/website/models/website_visitor.py +++ b/addons/website/models/website_visitor.py @@ -38,7 +38,7 @@ class WebsiteVisitor(models.Model): # localisation and info country_id = fields.Many2one('res.country', 'Country', readonly=True) - country_flag = fields.Binary(related="country_id.image", string="Country Flag") + country_flag = fields.Char(related="country_id.image_url", string="Country Flag") lang_id = fields.Many2one('res.lang', string='Language', help="Language from the website when visitor has been created") timezone = fields.Selection(_tz_get, string='Timezone') email = fields.Char(string='Email', compute='_compute_email_phone') diff --git a/addons/website/tests/test_performance.py b/addons/website/tests/test_performance.py index 466167b436f..48763dc75b9 100644 --- a/addons/website/tests/test_performance.py +++ b/addons/website/tests/test_performance.py @@ -33,8 +33,6 @@ class UtilPerf(HttpCase): class TestStandardPerformance(UtilPerf): def test_10_perf_sql_img_controller(self): self.authenticate('demo', 'demo') - url = '/web/image/res.country/4/image' - self.assertEqual(self._get_url_hot_query(url), 4) url = '/web/image/res.users/2/image_256' self.assertEqual(self._get_url_hot_query(url), 8) diff --git a/addons/website/views/website_visitor_views.xml b/addons/website/views/website_visitor_views.xml index 9ec67f4503f..6a07151fd66 100644 --- a/addons/website/views/website_visitor_views.xml +++ b/addons/website/views/website_visitor_views.xml @@ -82,6 +82,7 @@ + @@ -109,10 +110,10 @@ -
- Country + +
+ Country
@@ -147,7 +148,8 @@ Country + t-att-src="record.country_flag.raw_value" + class="o_country_flag" alt="Country"/>
Active
@@ -196,7 +198,9 @@ -
+
+ +

@@ -227,7 +231,7 @@ - + diff --git a/addons/website_event_track_exhibitor/models/event_sponsor.py b/addons/website_event_track_exhibitor/models/event_sponsor.py index 4f812034e3e..878938f739a 100644 --- a/addons/website_event_track_exhibitor/models/event_sponsor.py +++ b/addons/website_event_track_exhibitor/models/event_sponsor.py @@ -92,11 +92,11 @@ class EventSponsor(models.Model): sponsor.is_in_opening_hours = opening_from <= now_tz < opening_to - @api.depends('partner_id.country_id.image') + @api.depends('partner_id.country_id.image_url') def _compute_country_flag_url(self): for sponsor in self: if sponsor.partner_id.country_id: - sponsor.country_flag_url = self.env['website'].image_url(sponsor.partner_id.country_id, 'image', size=256) + sponsor.country_flag_url = sponsor.partner_id.country_id.image_url else: sponsor.country_flag_url = False diff --git a/addons/website_forum/views/website_forum.xml b/addons/website_forum/views/website_forum.xml index d24ea064a5f..3e8e8aea253 100644 --- a/addons/website_forum/views/website_forum.xml +++ b/addons/website_forum/views/website_forum.xml @@ -1641,7 +1641,7 @@
diff --git a/odoo/addons/base/data/res_country_data.xml b/odoo/addons/base/data/res_country_data.xml index 2f35c017426..d436eb684d2 100644 --- a/odoo/addons/base/data/res_country_data.xml +++ b/odoo/addons/base/data/res_country_data.xml @@ -5,49 +5,42 @@ United Arab Emirates ae - Afghanistan af - Antigua and Barbuda ag - Anguilla ai - Albania al - Armenia am - @@ -55,7 +48,6 @@ Angola ao 0 - @@ -69,7 +61,6 @@ Argentina ar 1 - CUIT @@ -78,14 +69,12 @@ American Samoa as - Austria at - @@ -95,7 +84,6 @@ Australia au 1 - @@ -103,49 +91,42 @@ Aruba aw - Åland Islands ax - Azerbaijan az - Bosnia and Herzegovina ba - Barbados bb - Bangladesh bd - Belgium be - @@ -154,14 +135,12 @@ Burkina Faso bf - Bulgaria bg - VAT @@ -169,14 +148,12 @@ Bahrain bh - Burundi bi - @@ -184,35 +161,30 @@ Benin bj 0 - Saint Barthélémy bl - Bermuda bm - Brunei Darussalam bn - Bolivia bo - @@ -225,7 +197,6 @@ Brazil br - @@ -233,14 +204,12 @@ Bahamas bs - Bhutan bt - @@ -253,14 +222,12 @@ Botswana bw - Belarus by - @@ -268,7 +235,6 @@ Belize bz 0 - @@ -276,7 +242,6 @@ Canada ca 1 - @@ -285,35 +250,30 @@ Cocos (Keeling) Islands cc - Central African Republic cf - Democratic Republic of the Congo cd - Congo cg - Switzerland ch - @@ -321,35 +281,30 @@ Côte d'Ivoire ci - Cook Islands ck - Chile cl - Cameroon cm - China cn - @@ -358,7 +313,6 @@ Colombia co NIT - @@ -366,42 +320,36 @@ Costa Rica cr - Cuba cu - Cape Verde cv - Curaçao cw - Christmas Island cx - Cyprus cy - VAT @@ -409,7 +357,6 @@ Czech Republic cz - VAT @@ -417,7 +364,6 @@ Germany de - @@ -426,14 +372,12 @@ Djibouti dj - Denmark dk - @@ -442,14 +386,12 @@ Dominica dm - Dominican Republic do - @@ -458,21 +400,18 @@ Algeria dz - Ecuador ec - Estonia ee - VAT @@ -480,7 +419,6 @@ Egypt eg - @@ -493,14 +431,12 @@ Eritrea er - Spain es - @@ -509,14 +445,12 @@ Ethiopia et - Finland fi - @@ -525,35 +459,30 @@ Fiji fj - Falkland Islands fk - Micronesia fm - Faroe Islands fo - France fr - @@ -562,21 +491,18 @@ Gabon ga - Grenada gd - Georgia ge - @@ -589,42 +515,36 @@ Ghana gh - Gibraltar gi - Guernsey gg - Greenland gl - Gambia gm - Guinea gn - @@ -637,14 +557,12 @@ Equatorial Guinea gq - Greece gr - VAT @@ -652,14 +570,12 @@ South Georgia and the South Sandwich Islands gs - Guatemala gt - NIT @@ -667,21 +583,18 @@ Guam gu - Guinea-Bissau gw - Guyana gy - @@ -689,7 +602,6 @@ Hong Kong hk 0 - @@ -702,14 +614,12 @@ Honduras hn - Croatia hr - @@ -718,14 +628,12 @@ Haiti ht - Hungary hu - VAT @@ -734,7 +642,6 @@ Indonesia id 1 - NPWP @@ -743,7 +650,6 @@ Ireland ie 0 - VAT @@ -751,14 +657,12 @@ Israel il - Isle of Man im - @@ -766,7 +670,6 @@ India in 1 - @@ -775,28 +678,24 @@ British Indian Ocean Territory io - Iraq iq - Iran ir - Iceland is - @@ -804,7 +703,6 @@ Italy it 1 - VAT @@ -812,21 +710,18 @@ Jersey je - Jamaica jm - Jordan jo - @@ -834,7 +729,6 @@ Japan jp 1 - after @@ -843,105 +737,90 @@ Kenya ke - Kyrgyzstan kg - Cambodia kh - Kiribati ki - Comoros km - Saint Kitts and Nevis kn - North Korea kp - South Korea kr - Kuwait kw - Cayman Islands ky - Kazakhstan kz - Laos la - Lebanon lb - Saint Lucia lc - Liechtenstein li - @@ -949,28 +828,24 @@ Sri Lanka lk - Liberia lr - Lesotho ls - Lithuania lt - VAT @@ -978,7 +853,6 @@ Luxembourg lu - VAT @@ -986,7 +860,6 @@ Latvia lv - VAT @@ -994,14 +867,12 @@ Libya ly - Morocco ma - @@ -1009,20 +880,17 @@ Monaco mc - Moldova md - Montenegro me - @@ -1035,42 +903,36 @@ Madagascar mg - Marshall Islands mh - North Macedonia mk - Mali ml - Myanmar mm - Mongolia mn - @@ -1078,42 +940,36 @@ Macau mo 0 - Northern Mariana Islands mp - Martinique mq - Mauritania mr - Montserrat ms - Malta mt - VAT @@ -1121,7 +977,6 @@ Mauritius mu - @@ -1129,14 +984,12 @@ Maldives mv - Malawi mw - @@ -1144,7 +997,6 @@ Mexico mx 1 - RFC @@ -1153,63 +1005,54 @@ Malaysia my - Mozambique mz - Namibia na - New Caledonia nc - Niger ne - Norfolk Island nf - Nigeria ng - Nicaragua ni - Netherlands nl - @@ -1218,7 +1061,6 @@ Norway no - @@ -1226,42 +1068,36 @@ Nepal np - Nauru nr - Niue nu - New Zealand nz - Oman om - Panama pa - @@ -1269,42 +1105,36 @@ Peru pe - French Polynesia pf - Papua New Guinea pg - Philippines ph - Pakistan pk - Poland pl - @@ -1313,21 +1143,18 @@ Saint Pierre and Miquelon pm - Pitcairn Islands pn - Puerto Rico pr - @@ -1340,7 +1167,6 @@ Portugal pt - VAT @@ -1348,21 +1174,18 @@ Palau pw - Paraguay py - Qatar qa - @@ -1375,7 +1198,6 @@ Romania ro - VAT @@ -1383,56 +1205,48 @@ Serbia rs - Russian Federation ru - Rwanda rw - Saudi Arabia sa - Solomon Islands sb - Seychelles sc - Sudan sd - Sweden se - VAT @@ -1440,7 +1254,6 @@ Singapore sg - GST No. @@ -1448,14 +1261,12 @@ Saint Helena, Ascension and Tristan da Cunha sh - Slovenia si - VAT @@ -1469,7 +1280,6 @@ Slovakia sk - VAT @@ -1477,161 +1287,138 @@ Sierra Leone sl - San Marino sm - Senegal sn - Somalia so - Suriname sr - South Sudan ss - São Tomé and Príncipe st - El Salvador sv - Sint Maarten (Dutch part) sx - Syria sy - Swaziland sz - Turks and Caicos Islands tc - Chad td - French Southern Territories tf - Togo tg - Thailand th - Tajikistan tj - Tokelau tk - Turkmenistan tm - Tunisia tn - Tonga to - Timor-Leste tl - Turkey tr - @@ -1639,14 +1426,12 @@ Trinidad and Tobago tt - Tuvalu tv - @@ -1659,21 +1444,18 @@ Tanzania tz - Ukraine ua - Uganda ug - @@ -1681,7 +1463,6 @@ United Kingdom gb - VAT @@ -1696,7 +1477,6 @@ United States us 1 - @@ -1705,56 +1485,48 @@ Uruguay uy - Uzbekistan uz - Holy See (Vatican City State) va - Saint Vincent and the Grenadines vc - Venezuela ve - Virgin Islands (British) vg - Virgin Islands (USA) vi - Vietnam vn - @@ -1762,7 +1534,6 @@ Vanuatu vu - @@ -1775,14 +1546,12 @@ Samoa ws - Yemen ye - @@ -1795,28 +1564,24 @@ South Africa za - Zambia zm - Zimbabwe zw - Kosovo xk - diff --git a/odoo/addons/base/models/res_country.py b/odoo/addons/base/models/res_country.py index ad53687d981..dfcf758bdbd 100644 --- a/odoo/addons/base/models/res_country.py +++ b/odoo/addons/base/models/res_country.py @@ -10,6 +10,24 @@ from odoo.tools.translate import _ _logger = logging.getLogger(__name__) +FLAG_MAPPING = { + "GF": "fr", + "BV": "no", + "BQ": "nl", + "GP": "fr", + "HM": "au", + "YT": "fr", + "RE": "fr", + "MF": "fr", + "UM": "us", +} + +NO_FLAG_COUNTRIES = [ + "AQ", #Antarctica + "SJ", #Svalbard + Jan Mayen : separate jurisdictions : no dedicated flag +] + + class Country(models.Model): _name = 'res.country' _description = 'Country' @@ -37,7 +55,10 @@ class Country(models.Model): "(in reports for example), while this field is used to modify the input form for " "addresses.") currency_id = fields.Many2one('res.currency', string='Currency') - image = fields.Binary(attachment=True) + image_url = fields.Char( + compute="_compute_image_url", string="Flag", + help="Url of static flag image", + ) phone_code = fields.Integer(string='Country Calling Code') country_group_ids = fields.Many2many('res.country.group', 'res_country_res_country_group_rel', 'res_country_id', 'res_country_group_id', string='Country Groups') @@ -90,6 +111,15 @@ class Country(models.Model): self.ensure_one() return re.findall(r'\((.+?)\)', self.address_format) + @api.depends('code') + def _compute_image_url(self): + for country in self: + if not country.code or country.code in NO_FLAG_COUNTRIES: + country.image_url = False + else: + code = FLAG_MAPPING.get(country.code, country.code.lower()) + country.image_url = "/base/static/img/country_flags/%s.png" % code + class CountryGroup(models.Model): _description = "Country Group" diff --git a/odoo/addons/base/static/img/country_flags/eh.png b/odoo/addons/base/static/img/country_flags/eh.png new file mode 100644 index 00000000000..85a25c02920 Binary files /dev/null and b/odoo/addons/base/static/img/country_flags/eh.png differ diff --git a/odoo/addons/base/static/img/country_flags/ps.png b/odoo/addons/base/static/img/country_flags/ps.png new file mode 100644 index 00000000000..1899b5a3d0a Binary files /dev/null and b/odoo/addons/base/static/img/country_flags/ps.png differ diff --git a/odoo/addons/base/static/img/country_flags/tw.png b/odoo/addons/base/static/img/country_flags/tw.png new file mode 100644 index 00000000000..3c6b7d2a69b Binary files /dev/null and b/odoo/addons/base/static/img/country_flags/tw.png differ diff --git a/odoo/addons/base/static/img/country_flags/wf.png b/odoo/addons/base/static/img/country_flags/wf.png new file mode 100644 index 00000000000..497467d14b0 Binary files /dev/null and b/odoo/addons/base/static/img/country_flags/wf.png differ diff --git a/odoo/addons/base/views/ir_qweb_widget_templates.xml b/odoo/addons/base/views/ir_qweb_widget_templates.xml index 0671c8a04a3..19dc914372b 100644 --- a/odoo/addons/base/views/ir_qweb_widget_templates.xml +++ b/odoo/addons/base/views/ir_qweb_widget_templates.xml @@ -7,8 +7,8 @@ - - + + diff --git a/odoo/addons/base/views/res_country_views.xml b/odoo/addons/base/views/res_country_views.xml index 02bd9c78d5e..4b9673a797b 100644 --- a/odoo/addons/base/views/res_country_views.xml +++ b/odoo/addons/base/views/res_country_views.xml @@ -23,7 +23,7 @@
- +