diff options
| author | Xavier Morel <xmo@odoo.com> | 2019-01-23 15:01:10 +0000 |
|---|---|---|
| committer | Raphael Collet <rco@odoo.com> | 2019-01-26 14:25:44 +0000 |
| commit | a0e05e2ab9055fa060b1f3b5adf7aa322e2617fd (patch) | |
| tree | 4fad9a0ed4593c927dbf03324e3b7b525f594b78 | |
| parent | c48c3e6155b73a86c2b8e42ad06cfb19d1919d70 (diff) | |
[IMP] fields: selection fields only use strings
closes odoo/odoo#29039
20 files changed, 72 insertions, 76 deletions
diff --git a/addons/account/models/company.py b/addons/account/models/company.py index 5ea0db1cd95..ea47862f89e 100644 --- a/addons/account/models/company.py +++ b/addons/account/models/company.py @@ -12,6 +12,22 @@ from odoo.tools.float_utils import float_round, float_is_zero from odoo.tools import date_utils +MONTH_SELECTION = [ + ('1', 'January'), + ('2', 'February'), + ('3', 'March'), + ('4', 'April'), + ('5', 'May'), + ('6', 'June'), + ('7', 'July'), + ('8', 'August'), + ('9', 'September'), + ('10', 'October'), + ('11', 'November'), + ('12', 'December'), +] + + class ResCompany(models.Model): _inherit = "res.company" @@ -20,7 +36,7 @@ class ResCompany(models.Model): #TODO check all the options/fields are in the views (settings + company form view) fiscalyear_last_day = fields.Integer(default=31, required=True) - fiscalyear_last_month = fields.Selection([(1, 'January'), (2, 'February'), (3, 'March'), (4, 'April'), (5, 'May'), (6, 'June'), (7, 'July'), (8, 'August'), (9, 'September'), (10, 'October'), (11, 'November'), (12, 'December')], default=12, required=True) + fiscalyear_last_month = fields.Selection(MONTH_SELECTION, default='12', required=True) period_lock_date = fields.Date(string="Lock Date for Non-Advisers", help="Only users with the 'Adviser' role can edit accounts prior to and inclusive of this date. Use it for period locking inside an open fiscal year, for example.") fiscalyear_lock_date = fields.Date(string="Lock Date", help="No users, including Advisers, can edit accounts prior to and inclusive of this date. Use it for fiscal year locking for example.") transfer_account_id = fields.Many2one('account.account', @@ -93,7 +109,7 @@ Best Regards,''')) def _check_fiscalyear_last_day(self): # if the user explicitly chooses the 29th of February we allow it: # there is no "fiscalyear_last_year" so we do not know his intentions. - if self.fiscalyear_last_day == 29 and self.fiscalyear_last_month == 2: + if self.fiscalyear_last_day == 29 and self.fiscalyear_last_month == '2': return if self.account_opening_date: @@ -101,7 +117,7 @@ Best Regards,''')) else: year = datetime.now().year - max_day = calendar.monthrange(year, self.fiscalyear_last_month)[1] + max_day = calendar.monthrange(year, int(self.fiscalyear_last_month))[1] if self.fiscalyear_last_day > max_day: raise ValidationError(_("Invalid fiscal year last day")) @@ -214,7 +230,7 @@ Best Regards,''')) } date_from, date_to = date_utils.get_fiscal_year( - current_date, day=self.fiscalyear_last_day, month=self.fiscalyear_last_month) + current_date, day=self.fiscalyear_last_day, month=int(self.fiscalyear_last_month)) date_from_str = date_from.strftime(DEFAULT_SERVER_DATE_FORMAT) date_to_str = date_to.strftime(DEFAULT_SERVER_DATE_FORMAT) @@ -357,7 +373,7 @@ Best Regards,''')) raise UserError(_("Please install a chart of accounts or create a miscellaneous journal before proceeding.")) today = datetime.today().date() - opening_date = today.replace(month=self.fiscalyear_last_month, day=self.fiscalyear_last_day) + timedelta(days=1) + opening_date = today.replace(month=int(self.fiscalyear_last_month), day=self.fiscalyear_last_day) + timedelta(days=1) if opening_date > today: opening_date = opening_date + relativedelta(years=-1) diff --git a/addons/account/tests/test_account_fiscal_year.py b/addons/account/tests/test_account_fiscal_year.py index 7fe5e6a966e..0bbf73249aa 100644 --- a/addons/account/tests/test_account_fiscal_year.py +++ b/addons/account/tests/test_account_fiscal_year.py @@ -28,7 +28,7 @@ class TestFiscalPosition(AccountingTestCase): '''Basic case with a fiscal year xxxx-01-01 - xxxx-12-31.''' company = self.env.ref('base.main_company') company.fiscalyear_last_day = 31 - company.fiscalyear_last_month = 12 + company.fiscalyear_last_month = '12' self.check_compute_fiscal_year( company, @@ -48,7 +48,7 @@ class TestFiscalPosition(AccountingTestCase): '''Case with a leap year ending the 29 February.''' company = self.env.ref('base.main_company') company.fiscalyear_last_day = 29 - company.fiscalyear_last_month = 2 + company.fiscalyear_last_month = '2' self.check_compute_fiscal_year( company, @@ -68,7 +68,7 @@ class TestFiscalPosition(AccountingTestCase): '''Case with a leap year ending the 28 February.''' company = self.env.ref('base.main_company') company.fiscalyear_last_day = 28 - company.fiscalyear_last_month = 2 + company.fiscalyear_last_month = '2' self.check_compute_fiscal_year( company, @@ -88,7 +88,7 @@ class TestFiscalPosition(AccountingTestCase): '''Case with custom fiscal years.''' company = self.env.ref('base.main_company') company.fiscalyear_last_day = 31 - company.fiscalyear_last_month = 12 + company.fiscalyear_last_month = '12' # Create custom fiscal year covering the 6 first months of 2017. self.env['account.fiscal.year'].create({ diff --git a/addons/account/wizard/setup_wizards.py b/addons/account/wizard/setup_wizards.py index 2aac7495fd5..cde10af75f1 100644 --- a/addons/account/wizard/setup_wizards.py +++ b/addons/account/wizard/setup_wizards.py @@ -16,8 +16,7 @@ class FinancialYearOpeningWizard(models.TransientModel): opening_date = fields.Date(string='Opening Date', required=True, related='company_id.account_opening_date', help="Date from which the accounting is managed in Odoo. It is the date of the opening entry.", readonly=False) fiscalyear_last_day = fields.Integer(related="company_id.fiscalyear_last_day", required=True, readonly=False, help="Fiscal year last day.") - fiscalyear_last_month = fields.Selection(selection=[(1, 'January'), (2, 'February'), (3, 'March'), (4, 'April'), (5, 'May'), (6, 'June'), (7, 'July'), (8, 'August'), (9, 'September'), (10, 'October'), (11, 'November'), (12, 'December')], - related="company_id.fiscalyear_last_month", readonly=False, + fiscalyear_last_month = fields.Selection(related="company_id.fiscalyear_last_month", readonly=False, required=True, help="Fiscal year last month.") @@ -33,7 +32,7 @@ class FinancialYearOpeningWizard(models.TransientModel): # fields is done one field at a time. for wiz in self: try: - date(2020, wiz.fiscalyear_last_month, wiz.fiscalyear_last_day) + date(2020, int(wiz.fiscalyear_last_month), wiz.fiscalyear_last_day) except ValueError: raise ValidationError( _('Incorrect fiscal year date: day is out of range for month. Month: %s; Day: %s') % diff --git a/addons/stock/models/res_config_settings.py b/addons/stock/models/res_config_settings.py index ebf7d339d39..3eca680cce7 100644 --- a/addons/stock/models/res_config_settings.py +++ b/addons/stock/models/res_config_settings.py @@ -8,9 +8,9 @@ class ResConfigSettings(models.TransientModel): _inherit = 'res.config.settings' module_procurement_jit = fields.Selection([ - (1, 'Immediately after sales order confirmation'), - (0, 'Manually or based on automatic scheduler') - ], "Reservation", + ('1', 'Immediately after sales order confirmation'), + ('0', 'Manually or based on automatic scheduler') + ], "Reservation", default='0', help="Reserving products manually in delivery orders or by running the scheduler is advised to better manage priorities in case of long customer lead times or/and frequent stock-outs.") module_product_expiry = fields.Boolean("Expiration Dates", help="Track following dates on lots & serial numbers: best before, removal, end of life, alert. \n Such dates are set automatically at lot/serial number creation based on values set on the product (in days).") diff --git a/addons/stock/wizard/stock_quantity_history.py b/addons/stock/wizard/stock_quantity_history.py index 595a5c8de88..e925073bc0c 100644 --- a/addons/stock/wizard/stock_quantity_history.py +++ b/addons/stock/wizard/stock_quantity_history.py @@ -9,15 +9,15 @@ class StockQuantityHistory(models.TransientModel): _description = 'Stock Quantity History' compute_at_date = fields.Selection([ - (0, 'Current Inventory'), - (1, 'At a Specific Date') - ], string="Compute", help="Choose to analyze the current inventory or from a specific date in the past.") + ('0', 'Current Inventory'), + ('1', 'At a Specific Date') + ], default='0', string="Compute", help="Choose to analyze the current inventory or from a specific date in the past.") date = fields.Datetime('Inventory at Date', help="Choose a date to get the inventory at that date", default=fields.Datetime.now) def open_table(self): self.ensure_one() - if self.compute_at_date: + if int(self.compute_at_date): tree_view_id = self.env.ref('stock.view_stock_product_tree').id form_view_id = self.env.ref('stock.product_form_view_procurement_button').id # We pass `to_date` in the context so that `qty_available` will be computed across diff --git a/addons/stock/wizard/stock_quantity_history.xml b/addons/stock/wizard/stock_quantity_history.xml index c464bf7b42d..bc18695e5c6 100644 --- a/addons/stock/wizard/stock_quantity_history.xml +++ b/addons/stock/wizard/stock_quantity_history.xml @@ -8,7 +8,7 @@ <group> <group> <field name="compute_at_date" widget="radio"/> - <field name="date" attrs="{'invisible': [('compute_at_date', '=', 0)]}"/> + <field name="date" attrs="{'invisible': [('compute_at_date', '=', '0')]}"/> </group> </group> <footer> @@ -25,7 +25,7 @@ <field name="view_mode">form</field> <field name="view_id" ref="view_stock_quantity_history"/> <field name="target">new</field> - <field name="context">{'default_compute_at_date': 0}</field> + <field name="context">{'default_compute_at_date': '0'}</field> </record> <menuitem id="menu_valuation" name="Inventory Report" parent="stock.menu_warehouse_report" sequence="100" action="action_stock_quantity_history"/> </odoo> diff --git a/addons/stock_account/views/stock_account_views.xml b/addons/stock_account/views/stock_account_views.xml index a9dbf024f2e..45abf2db497 100644 --- a/addons/stock_account/views/stock_account_views.xml +++ b/addons/stock_account/views/stock_account_views.xml @@ -58,7 +58,7 @@ <group> <group> <field name="compute_at_date" widget="radio"/> - <field name="date" attrs="{'invisible': [('compute_at_date', '=', 0)]}"/> + <field name="date" attrs="{'invisible': [('compute_at_date', '=', '0')]}"/> </group> </group> <footer> @@ -105,7 +105,7 @@ <field name="view_mode">form</field> <field name="view_id" ref="stock_account.view_stock_quantity_history"/> <field name="target">new</field> - <field name="context">{'default_compute_at_date': 0, 'valuation': True}</field> + <field name="context">{'default_compute_at_date': '0', 'valuation': True}</field> </record> <menuitem id="menu_valuation" name="Inventory Valuation" parent="stock.menu_warehouse_report" sequence="110" action="action_stock_inventory_valuation"/> diff --git a/addons/stock_account/wizard/stock_quantity_history.py b/addons/stock_account/wizard/stock_quantity_history.py index b8e010b04e5..59e5ab01c58 100644 --- a/addons/stock_account/wizard/stock_quantity_history.py +++ b/addons/stock_account/wizard/stock_quantity_history.py @@ -12,7 +12,7 @@ class StockQuantityHistory(models.TransientModel): self.env['stock.move']._run_fifo_vacuum() - if self.compute_at_date: + if int(self.compute_at_date): tree_view_id = self.env.ref('stock_account.view_stock_product_tree2').id form_view_id = self.env.ref('stock.product_form_view_procurement_button').id search_view_id = self.env.ref('stock_account.view_inventory_valuation_search').id diff --git a/addons/web/controllers/main.py b/addons/web/controllers/main.py index 57c86a2c6d6..853d008c802 100644 --- a/addons/web/controllers/main.py +++ b/addons/web/controllers/main.py @@ -599,6 +599,7 @@ class WebClient(http.Controller): lang_params = langs.read([ "name", "direction", "date_format", "time_format", "grouping", "decimal_point", "thousands_sep", "week_start"])[0] + lang_params['week_start'] = int(lang_params['week_start']) # Regional languages (ll_CC) must inherit/override their parent lang (ll), but this is # done server-side when the language is loaded, so we only need to load the user's lang. diff --git a/addons/web_editor/models/test_models.py b/addons/web_editor/models/test_models.py index d5ef48dc2af..282b703c03d 100644 --- a/addons/web_editor/models/test_models.py +++ b/addons/web_editor/models/test_models.py @@ -19,12 +19,6 @@ class ConverterTest(models.Model): binary = fields.Binary(attachment=False) date = fields.Date() datetime = fields.Datetime() - selection = fields.Selection([ - (1, "réponse A"), - (2, "réponse B"), - (3, "réponse C"), - (4, "réponse <D>"), - ]) selection_str = fields.Selection([ ('A', "Qu'il n'est pas arrivé à Toronto"), ('B', "Qu'il était supposé arriver à Toronto"), diff --git a/addons/web_editor/tests/test_converter.py b/addons/web_editor/tests/test_converter.py index bb778b07799..cfa62e52ac2 100644 --- a/addons/web_editor/tests/test_converter.py +++ b/addons/web_editor/tests/test_converter.py @@ -158,9 +158,6 @@ class TestConvertBack(common.TransactionCase): self.field_roundtrip('char', "foo bar") self.field_roundtrip('char', "ⒸⓄⓇⒼⒺ") - def test_selection(self): - self.field_roundtrip('selection', 3) - def test_selection_str(self): self.field_roundtrip('selection_str', 'B') diff --git a/odoo/addons/base/models/res_config.py b/odoo/addons/base/models/res_config.py index 32beb3b5742..ac2b9a153ae 100644 --- a/odoo/addons/base/models/res_config.py +++ b/odoo/addons/base/models/res_config.py @@ -355,7 +355,7 @@ class ResConfigSettings(models.TransientModel, ResConfigModuleInstallationMixin) By default 'group' is the group Employee. Groups are given by their xml id. The attribute 'group' may contain several xml ids, separated by commas. - * For a selection field like 'group_XXX' composed of 2 integers values ('0' and '1'), + * For a selection field like 'group_XXX' composed of 2 string values ('0' and '1'), ``execute`` adds/removes 'implied_group' to/from the implied groups of 'group', depending on the field's value. By default 'group' is the group Employee. Groups are given by their xml id. @@ -364,9 +364,9 @@ class ResConfigSettings(models.TransientModel, ResConfigModuleInstallationMixin) * For a boolean field like 'module_XXX', ``execute`` triggers the immediate installation of the module named 'XXX' if the field has value ``True``. - * For a selection field like 'module_XXX' composed of 2 integers values ('0' and '1'), + * For a selection field like 'module_XXX' composed of 2 string values ('0' and '1'), ``execute`` triggers the immediate installation of the module named 'XXX' - if the field has the integer value ``1``. + if the field has the value ``'1'``. * For a field with no specific prefix BUT an attribute 'config_parameter', ``execute``` will save its value in an ir.config.parameter (global setting for the @@ -419,7 +419,7 @@ class ResConfigSettings(models.TransientModel, ResConfigModuleInstallationMixin) [('name', '=', module_name.replace("module_", '')), ('state', 'in', ['to install', 'installed', 'to upgrade'])]) - if modules and not field_value: + if modules and not int(field_value): deps = modules.sudo().downstream_dependencies() dep_names = (deps | modules).mapped('shortdesc') message = '\n'.join(dep_names) @@ -508,13 +508,13 @@ class ResConfigSettings(models.TransientModel, ResConfigModuleInstallationMixin) for name, groups, implied_group in classified['group']: res[name] = all(implied_group in group.implied_ids for group in groups) if self._fields[name].type == 'selection': - res[name] = int(res[name]) + res[name] = str(int(res[name])) # True, False -> '1', '0' # modules: which modules are installed/to install for name, module in classified['module']: res[name] = module.state in ('installed', 'to install', 'to upgrade') if self._fields[name].type == 'selection': - res[name] = int(res[name]) + res[name] = str(int(res[name])) # True, False -> '1', '0' # config: get & convert stored ir.config_parameter (or default) WARNING_MESSAGE = "Error when converting value %r of field %s for ir.config.parameter %r" @@ -580,7 +580,7 @@ class ResConfigSettings(models.TransientModel, ResConfigModuleInstallationMixin) for name, groups, implied_group in classified['group']: if self[name] == current_settings[name]: continue - if self[name]: + if int(self[name]): groups.write({'implied_ids': [(4, implied_group.id)]}) else: groups.write({'implied_ids': [(3, implied_group.id)]}) @@ -625,7 +625,7 @@ class ResConfigSettings(models.TransientModel, ResConfigModuleInstallationMixin) to_uninstall_modules = self.env['ir.module.module'] lm = len('module_') for name, module in classified['module']: - if self[name]: + if int(self[name]): to_install.append((name[lm:], module)) else: if module and module.state in ('installed', 'to upgrade'): diff --git a/odoo/addons/base/models/res_lang.py b/odoo/addons/base/models/res_lang.py index 56fea211a11..534c8cb248c 100644 --- a/odoo/addons/base/models/res_lang.py +++ b/odoo/addons/base/models/res_lang.py @@ -33,13 +33,13 @@ class Lang(models.Model): direction = fields.Selection([('ltr', 'Left-to-Right'), ('rtl', 'Right-to-Left')], required=True, default='ltr') date_format = fields.Char(string='Date Format', required=True, default=DEFAULT_DATE_FORMAT) time_format = fields.Char(string='Time Format', required=True, default=DEFAULT_TIME_FORMAT) - week_start = fields.Selection([(1, 'Monday'), - (2, 'Tuesday'), - (3, 'Wednesday'), - (4, 'Thursday'), - (5, 'Friday'), - (6, 'Saturday'), - (7, 'Sunday')], string='First Day of Week', required=True, default=7) + week_start = fields.Selection([('1', 'Monday'), + ('2', 'Tuesday'), + ('3', 'Wednesday'), + ('4', 'Thursday'), + ('5', 'Friday'), + ('6', 'Saturday'), + ('7', 'Sunday')], string='First Day of Week', required=True, default='7') grouping = fields.Char(string='Separator Format', required=True, default='[]', help="The Separator Format should be like [,n] where 0 < n :starting from Unit digit. " "-1 will end the separation. e.g. [3,2,-1] will represent 106500 to be 1,06,500; " diff --git a/odoo/addons/base/wizard/base_import_language.py b/odoo/addons/base/wizard/base_import_language.py index 1017806119e..e39c36e89ae 100644 --- a/odoo/addons/base/wizard/base_import_language.py +++ b/odoo/addons/base/wizard/base_import_language.py @@ -41,5 +41,9 @@ class BaseLanguageImport(models.TransientModel): lang_name=this.name, context=this._context) except Exception as e: _logger.exception('File unsuccessfully imported, due to format mismatch.') - raise UserError(_('File not imported due to format mismatch or a malformed file. (Valid formats are .csv, .po, .pot)\n\nTechnical Details:\n%s') % tools.ustr(e)) + raise UserError( + _('File %r not imported due to format mismatch or a malformed file.' + ' (Valid formats are .csv, .po, .pot)\n\nTechnical Details:\n%s') % \ + (this.filename, tools.ustr(e)) + ) return True diff --git a/odoo/addons/test_converter/models.py b/odoo/addons/test_converter/models.py index 29a8bcefebf..1cb39b9cd47 100644 --- a/odoo/addons/test_converter/models.py +++ b/odoo/addons/test_converter/models.py @@ -15,12 +15,6 @@ class test_model(models.Model): binary = fields.Binary(attachment=False) date = fields.Date() datetime = fields.Datetime() - selection = fields.Selection([ - (1, "réponse A"), - (2, "réponse B"), - (3, "réponse C"), - (4, "réponse <D>"), - ]) selection_str = fields.Selection([ ('A', u"Qu'il n'est pas arrivé à Toronto"), ('B', u"Qu'il était supposé arriver à Toronto"), diff --git a/odoo/addons/test_converter/tests/test_html.py b/odoo/addons/test_converter/tests/test_html.py index bc157ab84e4..cf3f4c198ec 100644 --- a/odoo/addons/test_converter/tests/test_html.py +++ b/odoo/addons/test_converter/tests/test_html.py @@ -234,10 +234,6 @@ class TestBinaryExport(TestBasicExport): class TestSelectionExport(TestBasicExport): def test_selection(self): - converter = self.get_converter('selection') - value = converter(4) - self.assertEqual(value, e(u"réponse <D>")) - converter = self.get_converter('selection_str') value = converter('C') self.assertEqual(value, u"Qu'est-ce qu'il fout ce maudit pancake, tabernacle ?") diff --git a/odoo/addons/test_impex/models.py b/odoo/addons/test_impex/models.py index 45cf4af4402..726bf9041c0 100644 --- a/odoo/addons/test_impex/models.py +++ b/odoo/addons/test_impex/models.py @@ -25,7 +25,7 @@ MODELS = [ ('date', fields.Date()), ('datetime', fields.Datetime()), ('text', fields.Text()), - ('selection', fields.Selection([(1, "Foo"), (2, "Bar"), (3, "Qux"), (4, '')])), + ('selection', fields.Selection([('1', "Foo"), ('2', "Bar"), ('3', "Qux"), ('4', '')])), ('selection.function', fields.Selection(selection_fn)), # just relate to an integer ('many2one', fields.Many2one('export.integer')), @@ -143,7 +143,7 @@ class SelectionWithDefault(models.Model): _description = 'Export Selection With Default' const = fields.Integer(default=4) - value = fields.Selection([(1, "Foo"), (2, "Bar")], default=2) + value = fields.Selection([('1', "Foo"), ('2', "Bar")], default='2') class RecO2M(models.Model): diff --git a/odoo/addons/test_impex/tests/test_export.py b/odoo/addons/test_impex/tests/test_export.py index 264db66e992..3fc071e7454 100644 --- a/odoo/addons/test_impex/tests/test_export.py +++ b/odoo/addons/test_impex/tests/test_export.py @@ -276,7 +276,7 @@ class test_selection(CreatorCase): """ selections export the *label* for their value """ self.assertEqual( - self.export(2), + self.export('2'), [[u"Bar"]]) def test_localized_export(self): @@ -291,7 +291,7 @@ class test_selection(CreatorCase): 'value': value }) self.assertEqual( - self.export(2, context={'lang': 'fr_FR'}), + self.export('2', context={'lang': 'fr_FR'}), [[u'titi']]) diff --git a/odoo/addons/test_impex/tests/test_load.py b/odoo/addons/test_impex/tests/test_load.py index 34d6aa97de0..2d28d11231a 100644 --- a/odoo/addons/test_impex/tests/test_load.py +++ b/odoo/addons/test_impex/tests/test_load.py @@ -438,7 +438,7 @@ class test_selection(ImporterCase): ]) self.assertEqual(len(result['ids']), 4) self.assertFalse(result['messages']) - self.assertEqual([3, 2, 1, 2], values(self.read())) + self.assertEqual(['3', '2', '1', '2'], values(self.read())) def test_imported_translated(self): self.add_translations( @@ -452,7 +452,7 @@ class test_selection(ImporterCase): self.assertEqual(len(result['ids']), 3) self.assertFalse(result['messages']) - self.assertEqual([3, 1, 2], values(self.read())) + self.assertEqual(['3', '1', '2'], values(self.read())) result = self.import_(['value'], [['Foo']], context={'lang': 'fr_FR'}) self.assertEqual(len(result['ids']), 1) @@ -465,7 +465,7 @@ class test_selection(ImporterCase): u"Value 'Baz' not found in selection field 'Value'", moreinfo="Foo Bar Qux 4".split())]) - result = self.import_(['value'], [[42]]) + result = self.import_(['value'], [['42']]) self.assertIs(result['ids'], False) self.assertEqual(result['messages'], [message( u"Value '42' not found in selection field 'Value'", @@ -495,7 +495,7 @@ class test_selection_with_default(ImporterCase): self.assertEqual( values(self.read()), - [2]) + ['2']) class test_selection_function(ImporterCase): diff --git a/odoo/fields.py b/odoo/fields.py index 6d462a1713d..5d1701447a4 100644 --- a/odoo/fields.py +++ b/odoo/fields.py @@ -1859,6 +1859,7 @@ class Selection(Field): <field-incremental-definition>`. """ type = 'selection' + column_type = ('varchar', pg_varchar()) _slots = { 'selection': None, # [(value, string), ...], function or method name 'validate': True, # whether validating upon write @@ -1867,18 +1868,12 @@ class Selection(Field): def __init__(self, selection=Default, string=Default, **kwargs): super(Selection, self).__init__(selection=selection, string=string, **kwargs) - @property - def column_type(self): - if (self.selection and - isinstance(self.selection, list) and - isinstance(self.selection[0][0], int)): - return ('int4', 'integer') - else: - return ('varchar', pg_varchar()) - def _setup_regular_base(self, model): super(Selection, self)._setup_regular_base(model) assert self.selection is not None, "Field %s without selection" % self + if isinstance(self.selection, list): + assert all(isinstance(v, str) for v, _ in self.selection), \ + "Field %s with non-str value in selection" % self def _setup_related_full(self, model): super(Selection, self)._setup_related_full(model) |
