From 9ad5916701898453bce3c940419e431de372e014 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Fri, 15 Feb 2008 15:29:44 +0100 Subject: [PATCH 1/3] Fix fields.Function to use string instead of address --- partner.py | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/partner.py b/partner.py index d94c1c344a..89f23c205b 100644 --- a/partner.py +++ b/partner.py @@ -21,25 +21,6 @@ class Category(OSV): _order = 'parent,name' _parent_name = 'parent' - def name_get(self, cursor, user, ids, context=None): - - if not len(ids): - return [] - categories = self.browse(cursor, user, ids, context=context) - res = [] - for category in categories: - if category.parent: - name = category.parent.name+' / '+ category.name - else: - name = category.name - res.append((category.id, name)) - return res - - def _name_get_fnc(self, cursor, user, obj_id, name, value, arg, - context=None): - res = self.name_get(cursor, user, ids, context) - return dict(res) - def check_recursion(self, cursor, user, ids, parent=None): return super(Category, self).check_recursion(cursor, user, ids,parent="parent") @@ -48,7 +29,7 @@ class Category(OSV): 'name': fields.Char('Category Name', required=True, size=64), 'parent': fields.Many2One('partner.category', 'Parent Category', select=True), - 'complete_name': fields.Function(_name_get_fnc, method=True, + 'complete_name': fields.Function('complete_name', type="char", string='Name'), 'childs': fields.One2Many('partner.category', 'parent', 'Childs Category'), @@ -62,7 +43,26 @@ class Category(OSV): _constraints = [ (check_recursion, 'Error ! You can not create recursive categories.', ['parent']) - ] + ] + + def complete_name(self, cursor, user, obj_id, name, value, arg, + context=None): + res = self.name_get(cursor, user, ids, context) + return dict(res) + + def name_get(self, cursor, user, ids, context=None): + + if not len(ids): + return [] + categories = self.browse(cursor, user, ids, context=context) + res = [] + for category in categories: + if category.parent: + name = category.parent.name+' / '+ category.name + else: + name = category.name + res.append((category.id, name)) + return res Category() From 6cbba646360a1ff119f1088fef166a09a30d4266 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Fri, 15 Feb 2008 15:51:23 +0100 Subject: [PATCH 2/3] Add copyright --- __init__.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/__init__.py b/__init__.py index 0f63679e72..b6f07ec224 100644 --- a/__init__.py +++ b/__init__.py @@ -1 +1,28 @@ +# Copyright (c) 2004-2007 TINY SPRL. (http://tiny.be) +# Copyright (c) 2007 Cedric Krier. +# Copyright (c) 2007 Bertrand Chenal. +# +# WARNING: This program as such is intended to be used by professional +# programmers who take the whole responsability of assessing all potential +# consequences resulting from its eventual inadequacies and bugs +# End users who are looking for a ready-to-use solution with commercial +# garantees and support are strongly adviced to contact a Free Software +# Service Company +# +# This program is Free Software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +# +############################################################################## + import partner From 9939cf078a390c1cba11bfcf568a95149614e55f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Fri, 15 Feb 2008 15:51:53 +0100 Subject: [PATCH 3/3] Use string for _constraints function --- partner.py | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/partner.py b/partner.py index 89f23c205b..3b40bc8faa 100644 --- a/partner.py +++ b/partner.py @@ -20,11 +20,6 @@ class Category(OSV): _description = __doc__ _order = 'parent,name' _parent_name = 'parent' - - def check_recursion(self, cursor, user, ids, parent=None): - return super(Category, self).check_recursion(cursor, user, - ids,parent="parent") - _columns = { 'name': fields.Char('Category Name', required=True, size=64), 'parent': fields.Many2One('partner.category', 'Parent Category', @@ -35,13 +30,11 @@ class Category(OSV): 'Childs Category'), 'active' : fields.Boolean('Active'), } - _defaults = { 'active' : lambda *a: 1, } - _constraints = [ - (check_recursion, + ('check_recursion', 'Error ! You can not create recursive categories.', ['parent']) ]