Manage field context on Group value
issue4098 review11391004
This commit is contained in:
1 parent
09fbe1c1d0
commit
f4577bf28b
4 files changed
+19
-4
No files matched your search
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in new issue
Block a user