From f4577bf28bb607f48003b6bf1f84a2922aeaa866 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Fri, 29 Aug 2014 16:49:54 +0200 Subject: [PATCH] Manage field context on Group value issue4098 review11391004 --- CHANGELOG | 1 + tryton/gui/window/view_form/model/field.py | 5 +++-- tryton/gui/window/view_form/model/group.py | 7 +++++-- tryton/gui/window/view_form/model/record.py | 10 ++++++++++ 4 files changed, 19 insertions(+), 4 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 3604eff601..d3a36f56b7 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,4 @@ +* Manage field context on Group value * Add export of selection string * Load plugins from local user directory * Manage tree_state attribute diff --git a/tryton/gui/window/view_form/model/field.py b/tryton/gui/window/view_form/model/field.py index b4a9c14359..58c58dbec2 100644 --- a/tryton/gui/window/view_form/model/field.py +++ b/tryton/gui/window/view_form/model/field.py @@ -40,6 +40,7 @@ class Field(object): record.on_change([self.name]) record.on_change_with([self.name]) record.autocomplete_with(self.name) + record.set_field_context() def domains_get(self, record): screen_domain = domain_inversion(record.group.domain4inversion, @@ -444,7 +445,6 @@ class O2MField(Field): def __init__(self, attrs): super(O2MField, self).__init__(attrs) self.in_on_change = False - self.context = {} def sig_changed(self, record): if not self.in_on_change: @@ -479,11 +479,12 @@ class O2MField(Field): from group import Group parent_name = self.attrs.get('relation_field', '') fields = fields or {} + context = record.expr_eval(self.attrs.get('context', {})) group = Group(self.attrs['relation'], fields, parent=record, parent_name=parent_name, child_name=self.name, - context=self.context, + context=context, parent_datetime_field=self.attrs.get('datetime_field')) if not fields and record.model_name == self.attrs['relation']: group.fields = record.group.fields diff --git a/tryton/gui/window/view_form/model/group.py b/tryton/gui/window/view_form/model/group.py index ad60995b58..473f25d828 100644 --- a/tryton/gui/window/view_form/model/group.py +++ b/tryton/gui/window/view_form/model/group.py @@ -243,7 +243,8 @@ class Group(SignalEvent, list): self.current_idx = 0 return True - def _get_context(self): + @property + def context(self): ctx = self._context.copy() if self.parent: ctx.update(self.parent.context_get()) @@ -256,7 +257,9 @@ class Group(SignalEvent, list): )[self.parent_datetime_field] return ctx - context = property(_get_context) + @context.setter + def context(self, value): + self._context = value.copy() def add(self, record, position=-1, signal=True): if record.group is not self: diff --git a/tryton/gui/window/view_form/model/record.py b/tryton/gui/window/view_form/model/record.py index 28696c9785..46b48bc456 100644 --- a/tryton/gui/window/view_form/model/record.py +++ b/tryton/gui/window/view_form/model/record.py @@ -600,6 +600,16 @@ class Record(SignalEvent): res = [] self.autocompletion[fieldname] = res + def set_field_context(self): + from .group import Group + for name, field in self.group.fields.iteritems(): + value = self.value.get(name) + if not isinstance(value, Group): + continue + context = field.attrs.get('context') + if context: + value.context = self.expr_eval(context) + def get_attachment_count(self, reload=False): if self.id < 0: return 0