From 8a60934688e029d209c5fb5fb5766bfceab3f011 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Sun, 21 Aug 2011 11:14:58 +0200 Subject: [PATCH] Fix test on id root user has id=0 review77006 --- tryton/gui/window/view_form/model/field.py | 10 +++++----- tryton/gui/window/view_form/model/group.py | 6 +++--- tryton/gui/window/view_form/model/record.py | 11 +++++++---- tryton/gui/window/view_form/view/list.py | 2 +- 4 files changed, 16 insertions(+), 13 deletions(-) diff --git a/tryton/gui/window/view_form/model/field.py b/tryton/gui/window/view_form/model/field.py index 7ca5c6d148..def496f7c1 100644 --- a/tryton/gui/window/view_form/model/field.py +++ b/tryton/gui/window/view_form/model/field.py @@ -332,7 +332,7 @@ class M2OField(CharField): value = record.parent.id else: value = False - if value and isinstance(value, (int, long)) and value > 0: + if value and isinstance(value, (int, long)) and value >= 0: args = ('model', self.attrs['relation'], 'read', value, ['rec_name'], rpc.CONTEXT) try: @@ -468,7 +468,7 @@ class O2MField(CharField): for record2 in record.value[self.name]: if record2 in record_removed or record2 in record_deleted: continue - if record2.id > 0: + if record2.id >= 0: values = record2.get(check_load=check_load, get_readonly=readonly, get_modifiedonly=modified) if record2.modified and values: @@ -580,7 +580,7 @@ class O2MField(CharField): group.load_fields(fields_dict) if record.value.get(self.name): group.record_deleted.extend(x for x in record.value[self.name] - if x.id > 0) + if x.id >= 0) group.record_deleted.extend(record.value[self.name].record_deleted) group.record_removed.extend(record.value[self.name].record_removed) record.value[self.name] = group @@ -687,7 +687,7 @@ class O2MField(CharField): class M2MField(O2MField): def get_default(self, record): - return [x.id for x in record.value.get(self.name) or [] if x.id > 0] + return [x.id for x in record.value.get(self.name) or [] if x.id >= 0] def get_eval(self, record, check_load=True): return [x.id for x in record.value.get(self.name) or []] @@ -763,7 +763,7 @@ class ReferenceField(CharField): ref_id = int(ref_id) if not ref_id: ref_str = '' - if not ref_str and ref_id > 0: + if not ref_str and ref_id >= 0: args = ('model', ref_model, 'read', ref_id, ['rec_name'], rpc.CONTEXT) try: diff --git a/tryton/gui/window/view_form/model/group.py b/tryton/gui/window/view_form/model/group.py index 825b88068e..338cf67462 100644 --- a/tryton/gui/window/view_form/model/group.py +++ b/tryton/gui/window/view_form/model/group.py @@ -300,7 +300,7 @@ class Group(SignalEvent, list): def remove(self, record, remove=False, modified=True, signal=True, force_remove=False): idx = self.index(record) - if self[idx].id > 0: + if self[idx].id >= 0: if remove: if self[idx] in self.record_deleted: self.record_deleted.remove(self[idx]) @@ -315,7 +315,7 @@ class Group(SignalEvent, list): if modified: record.modified_fields.setdefault('id') record.signal('record-modified') - if not record.parent or self[idx].id <= 0 or force_remove: + if not record.parent or self[idx].id < 0 or force_remove: self._remove(self[idx]) if len(self): @@ -367,7 +367,7 @@ class Group(SignalEvent, list): new = [] for record in self: - if record.id <= 0: + if record.id < 0: new.append(record) ctx = context.copy() diff --git a/tryton/gui/window/view_form/model/record.py b/tryton/gui/window/view_form/model/record.py index 0101a9c747..a937e239a0 100644 --- a/tryton/gui/window/view_form/model/record.py +++ b/tryton/gui/window/view_form/model/record.py @@ -19,7 +19,10 @@ class Record(SignalEvent): def __init__(self, model_name, obj_id, group=None): super(Record, self).__init__() self.model_name = model_name - self.id = obj_id or Record.id + if obj_id is None: + self.id = Record.id + else: + self.id = obj_id if self.id < 0: Record.id -= 1 self._loaded = set() @@ -35,7 +38,7 @@ class Record(SignalEvent): self.autocompletion = {} def __getitem__(self, name, raise_exception=False): - if name not in self._loaded and self.id > 0: + if name not in self._loaded and self.id >= 0: ids = [self.id] if name == '*': loading = reduce( @@ -53,11 +56,11 @@ class Record(SignalEvent): idx + n < length) and n < 100: if idx - n >= 0: record = self.group[idx - n] - if name not in record._loaded and record.id > 0: + if name not in record._loaded and record.id >= 0: ids.append(record.id) if idx + n < length: record = self.group[idx + n] - if name not in record._loaded and record.id > 0: + if name not in record._loaded and record.id >= 0: ids.append(record.id) n += 1 if loading == 'eager': diff --git a/tryton/gui/window/view_form/view/list.py b/tryton/gui/window/view_form/view/list.py index 0b0723cf8a..d8d8983245 100644 --- a/tryton/gui/window/view_form/view/list.py +++ b/tryton/gui/window/view_form/view/list.py @@ -800,7 +800,7 @@ class ViewList(ParserView): def sel_ids_get(self): def _func_sel_get(store, path, iter, ids): record = store.on_get_iter(path) - if record and record.id > 0: + if record and record.id >= 0: ids.append(record.id) ids = [] sel = self.widget_tree.get_selection()