diff --git a/tryton/common/completion.py b/tryton/common/completion.py
index 95c9b726a5..0c2ceca98a 100644
--- a/tryton/common/completion.py
+++ b/tryton/common/completion.py
@@ -11,15 +11,17 @@ from tryton.exceptions import TrytonServerError, TrytonError
_ = gettext.gettext
-def get_completion():
+def get_completion(search=True, create=True):
"Return a EntryCompletion"
completion = gtk.EntryCompletion()
completion.set_match_func(lambda *a: True)
completion.set_model(gtk.ListStore(str, int))
completion.set_text_column(0)
completion.props.popup_set_width = False
- completion.insert_action_markup(0, _('Search...'))
- completion.insert_action_markup(1, _('Create...'))
+ if search:
+ completion.insert_action_markup(0, _('Search...'))
+ if create:
+ completion.insert_action_markup(1, _('Create...'))
return completion
diff --git a/tryton/gui/window/view_form/view/form_gtk/dictionary.py b/tryton/gui/window/view_form/view/form_gtk/dictionary.py
index f6e7ac31ec..8c2c84dbd8 100644
--- a/tryton/gui/window/view_form/view/form_gtk/dictionary.py
+++ b/tryton/gui/window/view_form/view/form_gtk/dictionary.py
@@ -333,7 +333,7 @@ class DictWidget(Widget):
hbox.pack_start(self.wid_text, expand=True, fill=True)
if int(self.attrs.get('completion', 1)):
- self.wid_completion = get_completion()
+ self.wid_completion = get_completion(search=False, create=False)
self.wid_completion.connect('match-selected',
self._completion_match_selected)
self.wid_text.set_completion(self.wid_completion)
diff --git a/tryton/gui/window/view_form/view/form_gtk/many2many.py b/tryton/gui/window/view_form/view/form_gtk/many2many.py
index 86bca97cb7..9d1271b32d 100644
--- a/tryton/gui/window/view_form/view/form_gtk/many2many.py
+++ b/tryton/gui/window/view_form/view/form_gtk/many2many.py
@@ -44,7 +44,9 @@ class Many2Many(Widget):
hbox.pack_start(self.wid_text, expand=True, fill=True)
if int(self.attrs.get('completion', 1)):
- self.wid_completion = get_completion()
+ self.wid_completion = get_completion(
+ create=self.attrs.get('create', True)
+ and common.MODELACCESS[self.attrs['relation']]['create'])
self.wid_completion.connect('match-selected',
self._completion_match_selected)
self.wid_completion.connect('action-activated',
diff --git a/tryton/gui/window/view_form/view/form_gtk/many2one.py b/tryton/gui/window/view_form/view/form_gtk/many2one.py
index 4eb646c9ff..14df990589 100644
--- a/tryton/gui/window/view_form/view/form_gtk/many2one.py
+++ b/tryton/gui/window/view_form/view/form_gtk/many2one.py
@@ -39,7 +39,9 @@ class Many2One(Widget):
self.focus_out = True
if int(self.attrs.get('completion', 1)):
- self.wid_completion = get_completion()
+ self.wid_completion = get_completion(
+ search=self.read_access,
+ create=self.create_access)
self.wid_completion.connect('match-selected',
self._completion_match_selected)
self.wid_completion.connect('action-activated',
diff --git a/tryton/gui/window/view_form/view/form_gtk/one2many.py b/tryton/gui/window/view_form/view/form_gtk/one2many.py
index a0ad4bc4e1..7844774afa 100644
--- a/tryton/gui/window/view_form/view/form_gtk/one2many.py
+++ b/tryton/gui/window/view_form/view/form_gtk/one2many.py
@@ -49,7 +49,10 @@ class One2Many(Widget):
hbox.pack_start(self.wid_text, expand=True, fill=True)
if int(self.attrs.get('completion', 1)):
- self.wid_completion = get_completion()
+ access = common.MODELACCESS[attrs['relation']]
+ self.wid_completion = get_completion(
+ search=access['read'] and access['write'],
+ create=attrs.get('create', True) and access['create'])
self.wid_completion.connect('match-selected',
self._completion_match_selected)
self.wid_completion.connect('action-activated',
@@ -288,7 +291,6 @@ class One2Many(Widget):
self._position
and self._position > 1))
if self.attrs.get('add_remove'):
- self.wid_text.set_sensitive(not self._readonly)
self.but_add.set_sensitive(bool(
not self._readonly
and not size_limit
@@ -299,6 +301,7 @@ class One2Many(Widget):
and self._position
and access['write']
and access['read']))
+ self.wid_text.set_sensitive(self.but_add.get_sensitive())
# New button must be added to focus chain to allow keyboard only
# creation when there is no existing record on form view.
diff --git a/tryton/gui/window/view_form/view/list_gtk/widget.py b/tryton/gui/window/view_form/view/list_gtk/widget.py
index 0c6d960326..052d2ef375 100644
--- a/tryton/gui/window/view_form/view/list_gtk/widget.py
+++ b/tryton/gui/window/view_form/view/list_gtk/widget.py
@@ -581,7 +581,8 @@ class M2O(GenericText):
relation = field.attrs['relation']
access = common.MODELACCESS[relation]
- if create and not access['create']:
+ if (create
+ and not (self.attrs.get('create', True) and access['create'])):
return
elif not access['read']:
return
@@ -631,7 +632,10 @@ class M2O(GenericText):
def set_completion(self, entry, path):
if entry.get_completion():
entry.set_completion(None)
- completion = get_completion()
+ access = common.MODELACCESS[self.attrs['relation']]
+ completion = get_completion(
+ search=access['read'],
+ create=self.attrs.get('create', True) and access['create'])
completion.connect('match-selected', self._completion_match_selected,
path)
completion.connect('action-activated',