diff --git a/tryton/gui/window/view_form/model/group.py b/tryton/gui/window/view_form/model/group.py index 0724c67e45..f09ce7e3cb 100644 --- a/tryton/gui/window/view_form/model/group.py +++ b/tryton/gui/window/view_form/model/group.py @@ -312,10 +312,10 @@ class Group(SignalEvent, list): if changed: self.signal('group-changed', changed) - def new(self, default=True, obj_id=None): + def new(self, default=True, obj_id=None, rec_name=None): record = Record(self.model_name, obj_id, group=self) if default: - record.default_get() + record.default_get(rec_name=rec_name) record.signal_connect(self, 'record-changed', self._record_changed) record.signal_connect(self, 'record-modified', self._record_modified) return record diff --git a/tryton/gui/window/view_form/model/record.py b/tryton/gui/window/view_form/model/record.py index 1d90d5120f..970db32bed 100644 --- a/tryton/gui/window/view_form/model/record.py +++ b/tryton/gui/window/view_form/model/record.py @@ -350,11 +350,13 @@ class Record(SignalEvent): root_group.reload(reload_ids) return True - def default_get(self): + def default_get(self, rec_name=None): if len(self.group.fields): + context = self.context_get() + context.setdefault('default_rec_name', rec_name) try: vals = RPCExecute('model', self.model_name, 'default_get', - self.group.fields.keys(), context=self.context_get()) + self.group.fields.keys(), context=context) except RPCException: return if (self.parent diff --git a/tryton/gui/window/view_form/screen/screen.py b/tryton/gui/window/view_form/screen/screen.py index 5e7bcb482a..5cc6d48ca5 100644 --- a/tryton/gui/window/view_form/screen/screen.py +++ b/tryton/gui/window/view_form/screen/screen.py @@ -530,7 +530,7 @@ class Screen(SignalEvent): return view - def new(self, default=True): + def new(self, default=True, rec_name=None): previous_view = self.current_view if self.current_view.view_type == 'calendar': selected_date = self.current_view.get_selected_date() @@ -542,7 +542,7 @@ class Screen(SignalEvent): group = self.current_record.group else: group = self.group - record = group.new(default) + record = group.new(default, rec_name=rec_name) group.add(record, self.new_model_position()) if previous_view.view_type == 'calendar': previous_view.set_default_date(record, selected_date) 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 b5a109ae11..4ec6a60b05 100644 --- a/tryton/gui/window/view_form/view/form_gtk/many2many.py +++ b/tryton/gui/window/view_form/view/form_gtk/many2many.py @@ -213,7 +213,7 @@ class Many2Many(Widget): self.focus_out = False WinForm(screen, callback, new=True, save_current=True, - title=self.attrs.get('string')) + title=self.attrs.get('string'), rec_name=self.wid_text.get_text()) def _readonly_set(self, value): self._readonly = value 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 72de22c0b0..e110dd2f43 100644 --- a/tryton/gui/window/view_form/view/form_gtk/many2one.py +++ b/tryton/gui/window/view_form/view/form_gtk/many2one.py @@ -169,7 +169,7 @@ class Many2One(Widget): screen.current_record.rec_name())) self.focus_out = True WinForm(screen, callback, new=True, save_current=True, - title=self.attrs.get('string')) + title=self.attrs.get('string'), rec_name=self.wid_text.get_text()) def sig_edit(self, entry=None, icon_pos=None, *args): model = self.get_model() 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 a6f40d6ed7..74e255cc5e 100644 --- a/tryton/gui/window/view_form/view/list_gtk/widget.py +++ b/tryton/gui/window/view_form/view/list_gtk/widget.py @@ -609,7 +609,7 @@ class M2O(GenericText): title=field.attrs.get('string')) else: WinForm(screen, open_callback, new=True, save_current=True, - title=field.attrs.get('string')) + title=field.attrs.get('string'), rec_name=text) def search_remote(self, record, relation, text, domain=None, context=None, callback=None): diff --git a/tryton/gui/window/win_form.py b/tryton/gui/window/win_form.py index 8ccf60a55f..f625bb756f 100644 --- a/tryton/gui/window/win_form.py +++ b/tryton/gui/window/win_form.py @@ -17,7 +17,7 @@ class WinForm(NoModal, InfoBar): def __init__(self, screen, callback, view_type='form', new=False, many=0, domain=None, context=None, - save_current=False, title=''): + save_current=False, title='', rec_name=None): NoModal.__init__(self) self.screen = screen self.callback = callback @@ -33,7 +33,7 @@ class WinForm(NoModal, InfoBar): self.screen.add_view_id(None, view_type) self.screen.switch_view(view_type=view_type) if new: - self.screen.new() + self.screen.new(rec_name=rec_name) self.win = gtk.Dialog(_('Link'), self.parent, gtk.DIALOG_DESTROY_WITH_PARENT) self.win.set_position(gtk.WIN_POS_CENTER_ON_PARENT)