Make domain on one2many works for dialog and form view

This commit is contained in:
Cédric Krier committed 2008-06-12 12:38:38 +02:00
1 parent f31b6b6de9
commit 28313af445
2 files changed
+34 -11

No files matched your search

+12 -7
View File
@@ -297,13 +297,6 @@ class Screen(SignalEvent):
_parse_fields(node2, fields)
xml_dom = xml.dom.minidom.parseString(arch)
_parse_fields(xml_dom, fields)
for dom in self.domain:
if dom[0] in fields:
field_dom = str(fields[dom[0]].setdefault('domain',[]))
fields[dom[0]]['domain'] = field_dom[:1] + \
str(('id', dom[1], dom[2])) + ',' + field_dom[1:]
if dom[1] == '=':
fields[dom[0]]['readonly'] = True
for node in xml_dom.childNodes:
if node.localName == 'tree':
self.fields_view_tree = {'arch': arch, 'fields': fields}
@@ -316,6 +309,8 @@ class Screen(SignalEvent):
self.models.add_fields_custom(fields, self.models)
else:
self.models.add_fields(fields, self.models, context=context)
self.set_domain()
self.fields = self.models.fields
parser = WidgetParse(parent=self.parent, window=self.window)
@@ -329,6 +324,16 @@ class Screen(SignalEvent):
self.screen_container.set(view.widget)
return view
def set_domain(self):
fields = self.models.fields
for dom in self.domain:
if dom[0] in fields:
field_dom = str(fields[dom[0]].setdefault('domain',[]))
fields[dom[0]]['domain'] = field_dom[:1] + \
str(('id', dom[1], dom[2])) + ',' + field_dom[1:]
if dom[1] == '=':
fields[dom[0]]['readonly'] = True
def editable_get(self):
if hasattr(self.current_view, 'widget_tree'):
if hasattr(self.current_view.widget_tree, 'editable'):
@@ -108,7 +108,8 @@ def _create_menu(self):
class Dialog(object):
def __init__(self, model_name, parent, model=None, attrs=None,
model_ctx=None, window=None, default_get_ctx=None, readonly=False):
model_ctx=None, window=None, default_get_ctx=None, readonly=False,
domain=None):
if attrs is None:
attrs = {}
@@ -165,7 +166,8 @@ class Dialog(object):
self.dia.show_all()
self.screen = Screen(model_name, self.dia, view_type=[], parent=parent,
exclude_field=attrs.get('relation_field', None), readonly=readonly)
exclude_field=attrs.get('relation_field', None), readonly=readonly,
domain=domain)
self.screen.models._context.update(model_ctx)
if not model:
model = self.screen.new(context=default_get_ctx)
@@ -378,16 +380,18 @@ class One2Many(WidgetInterface):
self.screen.current_view.widget.set_sensitive(True)
else:
readonly = False
domain = []
if self._view.modelfield and self._view.model:
modelfield = self._view.modelfield
model = self._view.model
readonly = modelfield.get_state_attrs(model
).get('readonly', False)
domain = modelfield.domain_get(self._view.model)
dia = Dialog(self.attrs['relation'], parent=self._view.model,
attrs=self.attrs,
model_ctx=self.screen.models._context,
default_get_ctx=ctx, window=self._window,
readonly=readonly)
readonly=readonly, domain=domain)
res = True
while res:
res, value = dia.run()
@@ -401,14 +405,16 @@ class One2Many(WidgetInterface):
def _sig_edit(self, widget=None, event=None):
if self.screen.current_model:
readonly = False
domain = []
if self._view.modelfield and self._view.model:
modelfield = self._view.modelfield
model = self._view.model
readonly = modelfield.get_state_attrs(model
).get('readonly', False)
domain = modelfield.domain_get(self._view.model)
dia = Dialog(self.attrs['relation'], parent=self._view.model,
model=self.screen.current_model, attrs=self.attrs,
window=self._window, readonly=readonly)
window=self._window, readonly=readonly, domain=domain)
res, value = dia.run()
dia.destroy()
@@ -445,6 +451,18 @@ class One2Many(WidgetInterface):
if (self.screen.current_view.view_type == 'tree') \
and self.screen.editable_get():
self.screen.current_model = None
readonly = False
domain = []
if self._view.modelfield and self._view.model:
modelfield = self._view.modelfield
model = self._view.model
readonly = modelfield.get_state_attrs(model
).get('readonly', False)
domain = modelfield.domain_get(self._view.model)
if self.screen.domain != domain:
self.screen.domain = domain
self.screen.set_domain()
self.screen.models.readonly = readonly
self.screen.display()
return True