Add flag symbol for country and subdivision

issue11599
review433291003
This commit is contained in:
Cédric Krier committed 2022-08-26 18:21:15 +02:00
1 parent 7462c67fcb
commit f2aa898f40
3 files changed
+25 -1

No files matched your search

+2
View File
@@ -1,3 +1,5 @@
* Add flag symbol for country and subdivision
Version 6.4.0 - 2022-05-02
* Bug fixes (see mercurial logs for details)
* Use Tryton's CDN to download postal codes
+20
View File
@@ -19,6 +19,7 @@ class Country(DeactivableMixin, ModelSQL, ModelView):
help="The 3 chars ISO country code.")
code_numeric = fields.Char('Numeric Code', select=True,
help="The ISO numeric country code.")
flag = fields.Function(fields.Char("Flag"), 'on_change_with_flag')
subdivisions = fields.One2Many('country.subdivision',
'country', 'Subdivisions')
@@ -49,6 +50,17 @@ class Country(DeactivableMixin, ModelSQL, ModelView):
cursor.execute(*data.delete(where=(data.module == 'country')
& (data.model == cls.__name__)))
@fields.depends('code')
def on_change_with_flag(self, name=None):
if self.code:
return ''.join(map(chr, map(lambda c: 127397 + ord(c), self.code)))
def get_rec_name(self, name):
name = self.name
if self.flag:
name = ' '.join([self.flag, self.name])
return name
@classmethod
def search_rec_name(cls, name, clause):
code_value = clause[2]
@@ -93,6 +105,7 @@ class Subdivision(DeactivableMixin, ModelSQL, ModelView):
help="The main identifier of the subdivision.")
code = fields.Char('Code', required=True, select=True,
help="The ISO code of the subdivision.")
flag = fields.Function(fields.Char("Flag"), 'on_change_with_flag')
type = fields.Selection([
(None, ""),
('administration', 'Administration'),
@@ -266,6 +279,13 @@ class Subdivision(DeactivableMixin, ModelSQL, ModelView):
# Migration from 6.2: remove type required
table_h.not_null_action('type', action='remove')
@fields.depends('code')
def on_change_with_flag(self, name=None):
if self.code:
return '🏴' + ''.join(map(chr, map(
lambda c: 917504 + ord(c),
self.code.replace('-', '').lower()))) + '\U000e007f'
@classmethod
def search_rec_name(cls, name, clause):
return ['OR',
+3 -1
View File
@@ -2,6 +2,8 @@
<!-- This file is part of Tryton. The COPYRIGHT file at the top level of
this repository contains the full copyright notices and license terms. -->
<tree>
<field name="name" expand="1"/>
<field name="name" expand="1">
<prefix name="flag"/>
</field>
<field name="code" optional="1"/>
</tree>