diff --git a/tryton/gui/window/form.py b/tryton/gui/window/form.py index 3f123fdd2a..644eeaa0ec 100644 --- a/tryton/gui/window/form.py +++ b/tryton/gui/window/form.py @@ -548,7 +548,7 @@ class Form(SignalEvent, TabContent): 'id': record_id, 'ids': record_ids, } - Action._exec_action(action, data, self.screen.group._context.copy()) + Action._exec_action(action, data, self.screen.local_context) def activate_save(self): self.buttons['save'].props.sensitive = self.screen.modified() diff --git a/tryton/gui/window/view_form/model/field.py b/tryton/gui/window/view_form/model/field.py index 097bb93e0f..7048a558c9 100644 --- a/tryton/gui/window/view_form/model/field.py +++ b/tryton/gui/window/view_form/model/field.py @@ -61,11 +61,11 @@ class Field(object): def validation_domains(self, record, pre_validate=None): return concat(*self.domains_get(record, pre_validate)) - def get_context(self, record, record_context=None): + def get_context(self, record, record_context=None, local=False): if record_context is not None: context = record_context.copy() else: - context = record.get_context() + context = record.get_context(local=local) context.update(record.expr_eval(self.attrs.get('context', {}))) return context @@ -444,8 +444,9 @@ class M2OField(Field): record.value.setdefault(self.name + '.', {})['rec_name'] = rec_name record.value[self.name] = value - def get_context(self, record, record_context=None): - context = super(M2OField, self).get_context(record, record_context) + def get_context(self, record, record_context=None, local=False): + context = super(M2OField, self).get_context( + record, record_context=record_context, local=local) if self.attrs.get('datetime_field'): context['_datetime'] = record.get_eval( )[self.attrs.get('datetime_field')] @@ -866,9 +867,9 @@ class ReferenceField(Field): record.value[self.name] = ref_model, ref_id record.value.setdefault(self.name + '.', {})['rec_name'] = rec_name - def get_context(self, record, record_context=None): + def get_context(self, record, record_context=None, local=False): context = super(ReferenceField, self).get_context( - record, record_context) + record, record_context, local=local) if self.attrs.get('datetime_field'): context['_datetime'] = record.get_eval( )[self.attrs.get('datetime_field')] diff --git a/tryton/gui/window/view_form/model/group.py b/tryton/gui/window/view_form/model/group.py index 436ae45be0..15a6423114 100644 --- a/tryton/gui/window/view_form/model/group.py +++ b/tryton/gui/window/view_form/model/group.py @@ -279,13 +279,24 @@ class Group(SignalEvent, list): @property def context(self): - ctx = rpc.CONTEXT.copy() + return self._get_context(local=False) + + @property + def local_context(self): + return self._get_context(local=True) + + def _get_context(self, local=False): + if not local: + ctx = rpc.CONTEXT.copy() + else: + ctx = {} if self.parent: - parent_context = self.parent.get_context() + parent_context = self.parent.get_context(local=local) ctx.update(parent_context) if self.child_name in self.parent.group.fields: field = self.parent.group.fields[self.child_name] - ctx.update(field.get_context(self.parent, parent_context)) + ctx.update(field.get_context( + self.parent, parent_context, local=local)) ctx.update(self._context) if self.parent_datetime_field: ctx['_datetime'] = self.parent.get_eval( diff --git a/tryton/gui/window/view_form/model/record.py b/tryton/gui/window/view_form/model/record.py index d1a873e694..e5941bc209 100644 --- a/tryton/gui/window/view_form/model/record.py +++ b/tryton/gui/window/view_form/model/record.py @@ -398,8 +398,11 @@ class Record(SignalEvent): invalid_fields = property(_get_invalid_fields) - def get_context(self): - return self.group.context + def get_context(self, local=False): + if not local: + return self.group.context + else: + return self.group.local_context def set_default(self, val, signal=True, validate=True): fieldnames = [] diff --git a/tryton/gui/window/view_form/screen/screen.py b/tryton/gui/window/view_form/screen/screen.py index 8c6fce19ec..d1305f87eb 100644 --- a/tryton/gui/window/view_form/screen/screen.py +++ b/tryton/gui/window/view_form/screen/screen.py @@ -256,7 +256,7 @@ class Screen(SignalEvent): self.clear() self.context_screen.display(set_cursor=True) return False - context = self.group._context.copy() + context = self.local_context context.update(self.context_screen.get_on_change_value()) self.new_group(context) @@ -362,6 +362,13 @@ class Screen(SignalEvent): context['context_model'] = self.context_screen.model_name return context + @property + def local_context(self): + context = self.group.local_context + if self.context_screen: + context['context_model'] = self.context_screen.model_name + return context + def __get_group(self): return self.__group @@ -467,7 +474,7 @@ class Screen(SignalEvent): 'model': self.model_name, 'id': self.current_record.id if self.current_record else None, 'ids': [r.id for r in self.selected_records], - }, context=self.group._context.copy(), warning=False) + }, context=self.local_context, warning=False) else: if not self.modified(): self.switch_view(view_type='form') @@ -1199,7 +1206,7 @@ class Screen(SignalEvent): if self.domain: query_string.append(('domain', json.dumps( self.domain, cls=JSONEncoder, separators=(',', ':')))) - context = self.group._context # Avoid rpc context + context = self.local_context # Avoid rpc context if context: query_string.append(('context', json.dumps( context, cls=JSONEncoder, separators=(',', ':'))))