Reviewers: ,


Please review this at http://codereview.tryton.org/56001/

Affected files:
  M tryton/gui/window/view_form/model/field.py
  M tryton/gui/window/view_form/model/group.py


Index: tryton/gui/window/view_form/model/field.py
===================================================================

--- a/tryton/gui/window/view_form/model/field.py
+++ b/tryton/gui/window/view_form/model/field.py
@@ -42,7 +42,7 @@
         record.autocomplete_with(self.name)

     def domains_get(self, record):
-        screen_domain = domain_inversion(record.group.domain,
+        screen_domain = domain_inversion(record.group.domain4inversion,
             self.name, EvalEnvironment(record, False))
         if isinstance(screen_domain, bool) and not screen_domain:
             screen_domain = [('id', '=', False)]

Index: tryton/gui/window/view_form/model/group.py
===================================================================

--- a/tryton/gui/window/view_form/model/group.py
+++ b/tryton/gui/window/view_form/model/group.py
@@ -7,6 +7,7 @@
 from tryton.signal_event import SignalEvent
 import tryton.common as common
 from tryton.exceptions import TrytonServerError
+from tryton.common.domain_inversion import is_leaf


 class Group(SignalEvent, list):
@@ -18,6 +19,7 @@
         if domain is None:
             domain = []
         self.domain = domain
+        self.__domain4inversion = None
         self.lock_signal = False
         self.__window = window
         self.parent = parent
@@ -49,6 +51,30 @@

     window = property(__get_window, __set_window)

+    def clean4inversion(self, domain):
+        "This method will remove non relevant fields for domain inversion"
+        if domain == []:
+            return domain
+        head, tail = domain[0], domain[1:]
+        if head in ('AND', 'OR'):
+            return [head] + self.clean4inversion(tail)
+        elif is_leaf(head):
+            field, _, _ = head
+            if (field not in self.fields
+                    or not self.fields[field].attrs.get('readonly')):
+                return [head] + self.clean4inversion(tail)
+            else:
+                return self.clean4inversion(tail)
+        else:
+            return self.clean4inversion(head) + self.clean4inversion(tail)
+
+    def __get_domain4inversion(self):
+        if self.__domain4inversion is None:
+            self.__domain4inversion = self.clean4inversion(self.domain)
+        return self.__domain4inversion
+
+    domain4inversion = property(__get_domain4inversion)
+
     def insert(self, pos, record):
         assert record.group is self
         if pos >= 1:



--
[email protected] mailing list

Reply via email to