From a89fc8bf1ce16397882c917dc90e6fe13e1c20d3 Mon Sep 17 00:00:00 2001 From: Udo Spallek Date: Sat, 16 Nov 2024 21:18:38 +0100 Subject: [PATCH] Rename ir.model 'name' field into 'string' --- modules/quality/quality.py | 4 ++-- trytond/CHANGELOG | 1 + trytond/trytond/backend/postgresql/init.sql | 2 +- trytond/trytond/backend/sqlite/init.sql | 2 +- trytond/trytond/ir/model.py | 21 +++++++++++++++------ trytond/trytond/ir/view/model_form.xml | 4 ++-- trytond/trytond/ir/view/model_list.xml | 2 +- trytond/trytond/tests/test_ir.py | 10 +++++----- trytond/trytond/tests/test_modelsql.py | 2 +- 9 files changed, 29 insertions(+), 19 deletions(-) diff --git a/modules/quality/quality.py b/modules/quality/quality.py index 18a9e335f7..6f82c60542 100644 --- a/modules/quality/quality.py +++ b/modules/quality/quality.py @@ -469,7 +469,7 @@ class Inspection(Workflow, ModelSQL, ModelView): models = IrModel.search([ ('model', 'in', models), ]) - return [(None, '')] + [(m.model, m.name) for m in models] + return [(None, '')] + [(m.model, m.string) for m in models] @fields.depends('control', 'points') def on_change_control(self): @@ -695,7 +695,7 @@ class Alert(Workflow, ModelSQL, ModelView): models = IrModel.search([ ('model', 'in', models), ]) - return [(None, '')] + [(m.model, m.name) for m in models] + return [(None, '')] + [(m.model, m.string) for m in models] @classmethod @ModelView.button diff --git a/trytond/CHANGELOG b/trytond/CHANGELOG index e80f418c18..b75b2485d8 100644 --- a/trytond/CHANGELOG +++ b/trytond/CHANGELOG @@ -1,3 +1,4 @@ +* Rename ir.model 'name' field into 'string' Version 7.4.0 - 2024-11-04 -------------------------- diff --git a/trytond/trytond/backend/postgresql/init.sql b/trytond/trytond/backend/postgresql/init.sql index c537d89bc0..09882f4b35 100644 --- a/trytond/trytond/backend/postgresql/init.sql +++ b/trytond/trytond/backend/postgresql/init.sql @@ -10,7 +10,7 @@ CREATE TABLE ir_model ( id INTEGER GENERATED BY DEFAULT AS IDENTITY NOT NULL CONSTRAINT ir_model_id_positive CHECK(id >= 0), model VARCHAR NOT NULL, - name VARCHAR, + string VARCHAR, info TEXT, module VARCHAR, PRIMARY KEY(id) diff --git a/trytond/trytond/backend/sqlite/init.sql b/trytond/trytond/backend/sqlite/init.sql index 5da37b73c8..f36e162402 100644 --- a/trytond/trytond/backend/sqlite/init.sql +++ b/trytond/trytond/backend/sqlite/init.sql @@ -11,7 +11,7 @@ CREATE TABLE ir_configuration ( CREATE TABLE ir_model ( id INTEGER PRIMARY KEY AUTOINCREMENT, model VARCHAR, - name VARCHAR, + string VARCHAR, info TEXT, module VARCHAR, create_date TIMESTAMP, diff --git a/trytond/trytond/ir/model.py b/trytond/trytond/ir/model.py index 964ff8c4bc..e7692e61e9 100644 --- a/trytond/trytond/ir/model.py +++ b/trytond/trytond/ir/model.py @@ -47,12 +47,12 @@ class Model( ModelSQL, ModelView): "Model" __name__ = 'ir.model' - _order_name = 'model' - name = fields.Char('Model Description', translate=True, loading='lazy', + _rec_name = 'string' + string = fields.Char( + "String", translate=True, states={ 'readonly': Bool(Eval('module')), - }, - depends=['module']) + }) model = fields.Char('Model Name', required=True, states={ 'readonly': Bool(Eval('module')), @@ -85,6 +85,15 @@ class Model( 'global_search': RPC(timeout=_request_timeout), }) + @classmethod + def __register__(cls, module): + table_h = cls.__table_handler__(module) + + # Migration from 7.4: rename column name into string + table_h.column_rename('name', 'string') + + super().__register__(module) + @classmethod def register(cls, model, module_name): cursor = Transaction().connection.cursor() @@ -101,7 +110,7 @@ class Model( model_id, = cursor.fetchone() if not model_id: cursor.execute(*ir_model.insert( - [ir_model.model, ir_model.name, ir_model.info, + [ir_model.model, ir_model.string, ir_model.info, ir_model.module], [[ model.__name__, model._get_name(), model.__doc__, @@ -168,7 +177,7 @@ class Model( items = cls._get_names_cache.get('items') if items is None: models = cls.search([]) - items = [(m.model, m.name) for m in models] + items = [(m.model, m.string) for m in models] cls._get_names_cache.set('items', items) return items diff --git a/trytond/trytond/ir/view/model_form.xml b/trytond/trytond/ir/view/model_form.xml index 4d9f1921fc..dfe1ae0269 100644 --- a/trytond/trytond/ir/view/model_form.xml +++ b/trytond/trytond/ir/view/model_form.xml @@ -2,8 +2,8 @@
-