From 3ae73d572da02f888ee4d5b9cec7ea73b8744493 Mon Sep 17 00:00:00 2001 From: Martin Trigaux Date: Tue, 8 Oct 2013 12:21:35 +0200 Subject: [PATCH 1/4] [FIX] function fields: bound symbol methods of function field (type char) to the correct methods of the char field lp bug: https://launchpad.net/bugs/1208074 fixed bzr revid: mat@openerp.com-20131008102135-r7lqvky0vd75yo1q --- openerp/osv/fields.py | 40 ++++++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/openerp/osv/fields.py b/openerp/osv/fields.py index 8591346471c..0dff5ec5d88 100644 --- a/openerp/osv/fields.py +++ b/openerp/osv/fields.py @@ -208,27 +208,29 @@ class reference(_column): return model.name_get(cr, uid, [int(res_id)], context=context)[0][1] return tools.ustr(value) +# takes a string (encoded in utf8) and returns a string (encoded in utf8) +def _symbol_set_char(self, symb): + + #TODO: + # * we need to remove the "symb==False" from the next line BUT + # for now too many things rely on this broken behavior + # * the symb==None test should be common to all data types + if symb is None or symb == False: + return None + + # we need to convert the string to a unicode object to be able + # to evaluate its length (and possibly truncate it) reliably + u_symb = tools.ustr(symb) + return u_symb[:self.size].encode('utf8') + class char(_column): _type = 'char' def __init__(self, string="unknown", size=None, **args): _column.__init__(self, string=string, size=size or None, **args) - self._symbol_set = (self._symbol_c, self._symbol_set_char) - - # takes a string (encoded in utf8) and returns a string (encoded in utf8) - def _symbol_set_char(self, symb): - #TODO: - # * we need to remove the "symb==False" from the next line BUT - # for now too many things rely on this broken behavior - # * the symb==None test should be common to all data types - if symb is None or symb == False: - return None - - # we need to convert the string to a unicode object to be able - # to evaluate its length (and possibly truncate it) reliably - u_symb = tools.ustr(symb) - - return u_symb[:self.size].encode('utf8') + self._symbol_f = _symbol_set_char + # use lamda function to be able to get the field size + self._symbol_set = (self._symbol_c, lambda x: _symbol_set_char(self, x)) class text(_column): @@ -1085,6 +1087,12 @@ class function(_column): self._symbol_f = integer._symbol_f self._symbol_set = integer._symbol_set + if type == 'char': + self._symbol_c = char._symbol_c + self._symbol_f = char._symbol_f + self._symbol_set = (char._symbol_c, lambda x: _symbol_set_char(self, x)) + + def digits_change(self, cr): if self._type == 'float': if self.digits_compute: From 241c054b3528310de418f24224913cec0f988de2 Mon Sep 17 00:00:00 2001 From: Martin Trigaux Date: Tue, 8 Oct 2013 12:47:37 +0200 Subject: [PATCH 2/4] [IMP] correctly bound _symbol_f and redifine self._symbol_set_char to keep the API bzr revid: mat@openerp.com-20131008104737-eellli48re2pfmos --- openerp/osv/fields.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/openerp/osv/fields.py b/openerp/osv/fields.py index 0dff5ec5d88..d5c84702677 100644 --- a/openerp/osv/fields.py +++ b/openerp/osv/fields.py @@ -228,9 +228,10 @@ class char(_column): def __init__(self, string="unknown", size=None, **args): _column.__init__(self, string=string, size=size or None, **args) - self._symbol_f = _symbol_set_char + # self._symbol_set_char defined to keep the backward compatibility + self._symbol_f = self._symbol_set_char = lambda x: _symbol_set_char(self, x) # use lamda function to be able to get the field size - self._symbol_set = (self._symbol_c, lambda x: _symbol_set_char(self, x)) + self._symbol_set = (self._symbol_c, self._symbol_f) class text(_column): @@ -1089,9 +1090,8 @@ class function(_column): if type == 'char': self._symbol_c = char._symbol_c - self._symbol_f = char._symbol_f - self._symbol_set = (char._symbol_c, lambda x: _symbol_set_char(self, x)) - + self._symbol_f = lambda x: _symbol_set_char(self, x) + self._symbol_set = (self._symbol_c, self._symbol_f) def digits_change(self, cr): if self._type == 'float': From 9680b1cd39c30c1b9a6898358c0865ed2bf2e295 Mon Sep 17 00:00:00 2001 From: Martin Trigaux Date: Tue, 8 Oct 2013 12:54:12 +0200 Subject: [PATCH 3/4] [IMP] move comment to the right line bzr revid: mat@openerp.com-20131008105412-pqxpo2q12odjyqp4 --- openerp/osv/fields.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openerp/osv/fields.py b/openerp/osv/fields.py index d5c84702677..8084fa7aab6 100644 --- a/openerp/osv/fields.py +++ b/openerp/osv/fields.py @@ -229,8 +229,8 @@ class char(_column): def __init__(self, string="unknown", size=None, **args): _column.__init__(self, string=string, size=size or None, **args) # self._symbol_set_char defined to keep the backward compatibility - self._symbol_f = self._symbol_set_char = lambda x: _symbol_set_char(self, x) # use lamda function to be able to get the field size + self._symbol_f = self._symbol_set_char = lambda x: _symbol_set_char(self, x) self._symbol_set = (self._symbol_c, self._symbol_f) From a0059326fc2c845e460ab4cfed4af8bd1e9056be Mon Sep 17 00:00:00 2001 From: Martin Trigaux Date: Tue, 8 Oct 2013 13:16:31 +0200 Subject: [PATCH 4/4] [IMP] remove useless comment bzr revid: mat@openerp.com-20131008111631-y47f0y4wyf8hsf2g --- openerp/osv/fields.py | 1 - 1 file changed, 1 deletion(-) diff --git a/openerp/osv/fields.py b/openerp/osv/fields.py index 8084fa7aab6..1ebf5ecf71d 100644 --- a/openerp/osv/fields.py +++ b/openerp/osv/fields.py @@ -229,7 +229,6 @@ class char(_column): def __init__(self, string="unknown", size=None, **args): _column.__init__(self, string=string, size=size or None, **args) # self._symbol_set_char defined to keep the backward compatibility - # use lamda function to be able to get the field size self._symbol_f = self._symbol_set_char = lambda x: _symbol_set_char(self, x) self._symbol_set = (self._symbol_c, self._symbol_f)