From 84d9edeb1eb8dd21f2d4e06bb22b213cb9d1f9dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Fri, 3 Dec 2010 18:00:06 +0100 Subject: [PATCH] Add One2One field --- CHANGELOG | 2 ++ tryton/gui/window/view_form/model/field.py | 5 +++++ tryton/gui/window/view_form/model/record.py | 2 +- tryton/gui/window/view_form/view/form_gtk/one2one.py | 7 +++++++ tryton/gui/window/view_form/view/form_gtk/parser.py | 2 ++ tryton/gui/window/view_form/view/list_gtk/parser.py | 4 ++++ tryton/gui/window/view_form/widget_search/form.py | 1 + tryton/gui/window/view_tree/view_tree.py | 4 ++-- 8 files changed, 24 insertions(+), 3 deletions(-) create mode 100644 tryton/gui/window/view_form/view/form_gtk/one2one.py diff --git a/CHANGELOG b/CHANGELOG index e7cbfa3694..a8dcb66036 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,5 @@ +* Add One2One field + Version 1.8.0 - 2010-11-01 * Bug fixes (see mercurial logs for details) * More fully integrate GTK menubar for Mac OS diff --git a/tryton/gui/window/view_form/model/field.py b/tryton/gui/window/view_form/model/field.py index af1fe4c944..49310d1222 100644 --- a/tryton/gui/window/view_form/model/field.py +++ b/tryton/gui/window/view_form/model/field.py @@ -332,6 +332,10 @@ class M2OField(CharField): return context +class O2OField(M2OField): + pass + + class O2MField(CharField): ''' internal = Group of the related objects @@ -666,4 +670,5 @@ TYPES = { 'boolean': BooleanField, 'datetime': DateTimeField, 'date': DateField, + 'one2one': O2OField, } diff --git a/tryton/gui/window/view_form/model/record.py b/tryton/gui/window/view_form/model/record.py index 8ae3ead0b3..59c6b84305 100644 --- a/tryton/gui/window/view_form/model/record.py +++ b/tryton/gui/window/view_form/model/record.py @@ -95,7 +95,7 @@ class Record(SignalEvent): ids, self.group.fields.keys() + \ [x + '.rec_name' for x in self.group.fields.keys() if self.group.fields[x].attrs['type'] \ - in ('many2one', 'reference')] + \ + in ('many2one', 'one2one', 'reference')] + \ ['_timestamp'], ctx) try: values = rpc.execute(*args) diff --git a/tryton/gui/window/view_form/view/form_gtk/one2one.py b/tryton/gui/window/view_form/view/form_gtk/one2one.py new file mode 100644 index 0000000000..3af021f7f5 --- /dev/null +++ b/tryton/gui/window/view_form/view/form_gtk/one2one.py @@ -0,0 +1,7 @@ +#This file is part of Tryton. The COPYRIGHT file at the top level of +#this repository contains the full copyright notices and license terms. +from many2one import Many2One + + +class One2One(Many2One): + pass diff --git a/tryton/gui/window/view_form/view/form_gtk/parser.py b/tryton/gui/window/view_form/view/form_gtk/parser.py index 12318c8e85..002e065bc2 100644 --- a/tryton/gui/window/view_form/view/form_gtk/parser.py +++ b/tryton/gui/window/view_form/view/form_gtk/parser.py @@ -827,6 +827,7 @@ from many2one import Many2One from url import Email, URL, CallTo, SIP from image import Image as Image2 from progressbar import ProgressBar +from one2one import One2One WIDGETS_TYPE = { @@ -853,4 +854,5 @@ WIDGETS_TYPE = { 'sip' : (SIP, 1, False, False), 'image' : (Image2, 1, False, False), 'progressbar': (ProgressBar, 1, False, False), + 'one2one': (One2One, 1, False, False), } diff --git a/tryton/gui/window/view_form/view/list_gtk/parser.py b/tryton/gui/window/view_form/view/list_gtk/parser.py index efbbd002f9..817d66b0c7 100644 --- a/tryton/gui/window/view_form/view/list_gtk/parser.py +++ b/tryton/gui/window/view_form/view/list_gtk/parser.py @@ -572,6 +572,9 @@ class M2O(Char): else: return False, None +class O2O(M2O): + pass + class UnsettableColumn(Exception): def __init__(self): @@ -911,4 +914,5 @@ CELLTYPES = { 'sip': Char, 'progressbar': ProgressBar, 'reference': Reference, + 'one2one': O2O, } diff --git a/tryton/gui/window/view_form/widget_search/form.py b/tryton/gui/window/view_form/widget_search/form.py index 73f9f9243a..4f5a6b631c 100644 --- a/tryton/gui/window/view_form/widget_search/form.py +++ b/tryton/gui/window/view_form/widget_search/form.py @@ -317,4 +317,5 @@ WIDGETS_TYPE = { 'many2many': (char.Char, 2), 'callto': (char.Char, 2), 'sip': (char.Char, 2), + 'one2one': (char.Char, 2), } diff --git a/tryton/gui/window/view_tree/view_tree.py b/tryton/gui/window/view_tree/view_tree.py index fd7d31744c..44093e080f 100644 --- a/tryton/gui/window/view_tree/view_tree.py +++ b/tryton/gui/window/view_tree/view_tree.py @@ -90,7 +90,7 @@ class ViewTreeModel(gtk.GenericTreeModel, gtk.TreeSortable): pass obj[field] = common.datetime_strftime(obj[field], display_format) - elif field_type in ('many2one',): + elif field_type in ('many2one', 'one2one'): for obj in res_ids: if obj[field]: obj[field] = obj[field + '.rec_name'] @@ -144,7 +144,7 @@ class ViewTreeModel(gtk.GenericTreeModel, gtk.TreeSortable): tree = [] fields = self.fields_type.keys() for field_name in self.fields_type: - if self.fields_type[field_name]['type'] == 'many2one': + if self.fields_type[field_name]['type'] in ('many2one', 'one2one'): fields.append(field_name + '.rec_name') if self.view.get('field_childs', False): res = self._read(ids, fields + [self.view['field_childs']])