Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(221)

Unified Diff: trytond/model/model.py

Issue 124056: Fix _getxxx2many_targets for issue1195 (Closed)
Patch Set: Fix for installation when Pool is not completly filled Created 14 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: trytond/model/model.py
===================================================================
--- a/trytond/model/model.py
+++ b/trytond/model/model.py
@@ -133,15 +133,45 @@
def _getxxx2many_targets(self):
if self.__xxx2many_targets:
return self.__xxx2many_targets
- res = [(x, getattr(y, 'model_name', None) or \
- getattr(y, 'target', None) or getattr(y, 'relation_name', None))
- for x, y in self._columns.iteritems()
- if y._type in ('one2many', 'many2many')]
- res += [(x, getattr(y, 'model_name', None) or \
- getattr(y, 'target', None) or getattr(y, 'relation_name', None))
- for _, (_, x, y) in self._inherit_fields.iteritems()
- if y._type in ('one2many', 'many2many')]
- self.__xxx2many_targets = res
+ to_cache = True
+
+ res = [(field_name, field.model_name)
+ for field_name, field in self._columns.iteritems()
+ if field._type == 'one2many']
+
+ for field_name, field in self._columns.iteritems():
+ if field._type != 'many2many':
+ continue
+ if hasattr(field, 'get_target'):
+ try:
+ model_name = field.get_target(self.pool)._name
+ except KeyError:
+ to_cache = False
+ continue
+ else:
+ model_name = field.model_name
+ res.append((field_name, model_name))
+
+ res += [(field_name, field.model_name)
+ for _, (_, field_name, field) in \
+ self._inherit_fields.iteritems()
+ if field._type == 'one2many']
+
+ for _, (_, field_name, field) in self._inherit_fields.iteritems():
+ if field._type != 'many2many':
+ continue
+ if hasattr(field, 'get_target'):
+ try:
+ model_name = field.get_target(self.pool)._name
+ except KeyError:
+ to_cache = False
+ continue
+ else:
+ model_name = field.model_name
+ res.append((field_name, model_name))
+
+ if to_cache:
+ self.__xxx2many_targets = res
return res
_xxx2many_targets = property(fget=_getxxx2many_targets)
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b