From 0db065083c2093e6194f5566eca4ca7ff53819b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Sun, 4 Oct 2020 00:35:23 +0200 Subject: [PATCH] Fallback to model name as title issue9596 review300381002 --- CHANGELOG | 1 + tryton/common/__init__.py | 4 ++-- tryton/common/common.py | 22 ++++++++++++++++++++++ tryton/gui/main.py | 1 + tryton/gui/window/board.py | 7 +++---- tryton/gui/window/form.py | 2 ++ tryton/gui/window/win_form.py | 4 +++- tryton/gui/window/win_search.py | 2 ++ 8 files changed, 36 insertions(+), 7 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 4d70bd57b7..29436328e2 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,4 @@ +* Fallback to model name as title * Manage deletable and writable state * Support e-mail template * Send e-mail via the server diff --git a/tryton/common/__init__.py b/tryton/common/__init__.py index 63e6d92cf6..712c6bc6db 100644 --- a/tryton/common/__init__.py +++ b/tryton/common/__init__.py @@ -1,7 +1,7 @@ # This file is part of Tryton. The COPYRIGHT file at the top level of # this repository contains the full copyright notices and license terms. from .common import ( - IconFactory, MODELACCESS, MODELHISTORY, VIEW_SEARCH, + IconFactory, MODELACCESS, MODELHISTORY, MODELNAME, VIEW_SEARCH, get_toplevel_window, get_sensible_widget, selection, file_selection, slugify, file_write, file_open, mailto, message, warning, userwarning, sur, sur_3b, ask, concurrency, error, to_xml, process_exception, Login, Logout, @@ -18,7 +18,7 @@ from .environment import EvalEnvironment from . import timedelta __all__ = [ - IconFactory, MODELACCESS, MODELHISTORY, VIEW_SEARCH, + IconFactory, MODELACCESS, MODELHISTORY, MODELNAME, VIEW_SEARCH, get_toplevel_window, get_sensible_widget, selection, file_selection, slugify, file_write, file_open, mailto, message, warning, userwarning, sur, sur_3b, ask, concurrency, error, to_xml, process_exception, Login, Logout, diff --git a/tryton/common/common.py b/tryton/common/common.py index 2fbe69d2da..c4987ac28f 100644 --- a/tryton/common/common.py +++ b/tryton/common/common.py @@ -228,6 +228,28 @@ class ModelHistory(object): MODELHISTORY = ModelHistory() +class ModelName: + _names = {} + + def load_names(self): + try: + self._names = rpc.execute( + 'model', 'ir.model', 'get_names', rpc.CONTEXT) + except TrytonServerError: + pass + + def get(self, model): + if not self._names: + self.load_names() + return self._names.get(model, '') + + def clear(self): + return self._names.clear() + + +MODELNAME = ModelName() + + class ViewSearch(object): searches = {} diff --git a/tryton/gui/main.py b/tryton/gui/main.py index 34f001c3a4..94f7239db6 100644 --- a/tryton/gui/main.py +++ b/tryton/gui/main.py @@ -532,6 +532,7 @@ class Main(Gtk.Application): self.favorite_unset() self.primary_menu.set_menu_model(self._get_primary_menu()) CONFIG['client.lang'] = prefs['language'] + common.MODELNAME.clear() # Set placeholder after language is set to get correct translation self.global_search_entry.set_placeholder_text(_("Action")) CONFIG.save() diff --git a/tryton/gui/window/board.py b/tryton/gui/window/board.py index 4841cb30c1..4968414b12 100644 --- a/tryton/gui/window/board.py +++ b/tryton/gui/window/board.py @@ -7,7 +7,7 @@ import xml.dom.minidom from tryton.signal_event import SignalEvent from tryton.gui import Main from tryton.gui.window.view_board import ViewBoard -from tryton.common import RPCExecute, RPCException +from tryton.common import RPCExecute, RPCException, MODELNAME from .tabcontent import TabContent @@ -35,9 +35,8 @@ class Board(SignalEvent, TabContent): self.model = model self.dialogs = [] if not name: - self.name = self.board.name - else: - self.name = name + name = MODELNAME.get(model) + self.name = name self.create_tabcontent() self.board.reload() diff --git a/tryton/gui/window/form.py b/tryton/gui/window/form.py index f714e19640..a517895c3e 100644 --- a/tryton/gui/window/form.py +++ b/tryton/gui/window/form.py @@ -48,6 +48,8 @@ class Form(SignalEvent, TabContent): self.screen = Screen(self.model, **attributes) self.screen.widget.show() + if not name: + name = common.MODELNAME.get(model) self.name = name self.create_tabcontent() diff --git a/tryton/gui/window/win_form.py b/tryton/gui/window/win_form.py index f5575db616..f6b0313c33 100644 --- a/tryton/gui/window/win_form.py +++ b/tryton/gui/window/win_form.py @@ -6,7 +6,7 @@ from gi.repository import Gdk, Gtk, Pango from .infobar import InfoBar import tryton.common as common -from tryton.common import TRYTON_ICON +from tryton.common import TRYTON_ICON, MODELNAME from tryton.common.domain_parser import quote from tryton.common.underline import set_underline from tryton.common.widget_style import widget_class @@ -30,6 +30,8 @@ class WinForm(NoModal, InfoBar): self.domain = domain self.context = context self.save_current = save_current + if not title: + title = MODELNAME.get(screen.model_name) self.title = title self.prev_view = self.screen.current_view self.screen.screen_container.alternate_view = True diff --git a/tryton/gui/window/win_search.py b/tryton/gui/window/win_search.py index 7b18f58d97..44ab9ee8cd 100644 --- a/tryton/gui/window/win_search.py +++ b/tryton/gui/window/win_search.py @@ -32,6 +32,8 @@ class WinSearch(NoModal): self.views_preload = views_preload self.sel_multi = sel_multi self.callback = callback + if not title: + title = common.MODELNAME.get(model) self.title = title self.exclude_field = exclude_field