Merge lp:~openerp-dev/openobject-server/7.0-field-size-related-mat into lp:openobject-server/7.0

Proposed by Martin Trigaux (OpenERP)
Status: Merged
Merged at revision: 5094
Proposed branch: lp:~openerp-dev/openobject-server/7.0-field-size-related-mat
Merge into: lp:openobject-server/7.0
Diff against target: 61 lines (+23/-16)
1 file modified
openerp/osv/fields.py (+23/-16)
To merge this branch: bzr merge lp:~openerp-dev/openobject-server/7.0-field-size-related-mat
Reviewer Review Type Date Requested Status
Olivier Dony (Odoo) Approve
Review via email: mp+189813@code.launchpad.net

Description of the change

Bound symbol methods of function field (type char) to the correct methods of the char field

Allows to have automatic truncation of text to the chosen size (avoid needs for manual truncation, eg: bug lp:1208074)

To post a comment you must log in.
5096. By Martin Trigaux (OpenERP)

[IMP] move comment to the right line

Revision history for this message
Olivier Dony (Odoo) (odo-openerp) wrote :

Looks good to me now, thanks! (just a typo lamda/lambda in the comment - you can probably just drop it)

review: Approve
5097. By Martin Trigaux (OpenERP)

[IMP] remove useless comment

Revision history for this message
Martin Trigaux (OpenERP) (mat-openerp) wrote :

Merged into 7.0

revno: 5094 [merge]
revision-id: <email address hidden>

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'openerp/osv/fields.py'
2--- openerp/osv/fields.py 2013-06-20 13:10:57 +0000
3+++ openerp/osv/fields.py 2013-10-08 11:16:45 +0000
4@@ -208,27 +208,29 @@
5 return model.name_get(cr, uid, [int(res_id)], context=context)[0][1]
6 return tools.ustr(value)
7
8+# takes a string (encoded in utf8) and returns a string (encoded in utf8)
9+def _symbol_set_char(self, symb):
10+
11+ #TODO:
12+ # * we need to remove the "symb==False" from the next line BUT
13+ # for now too many things rely on this broken behavior
14+ # * the symb==None test should be common to all data types
15+ if symb is None or symb == False:
16+ return None
17+
18+ # we need to convert the string to a unicode object to be able
19+ # to evaluate its length (and possibly truncate it) reliably
20+ u_symb = tools.ustr(symb)
21+ return u_symb[:self.size].encode('utf8')
22+
23 class char(_column):
24 _type = 'char'
25
26 def __init__(self, string="unknown", size=None, **args):
27 _column.__init__(self, string=string, size=size or None, **args)
28- self._symbol_set = (self._symbol_c, self._symbol_set_char)
29-
30- # takes a string (encoded in utf8) and returns a string (encoded in utf8)
31- def _symbol_set_char(self, symb):
32- #TODO:
33- # * we need to remove the "symb==False" from the next line BUT
34- # for now too many things rely on this broken behavior
35- # * the symb==None test should be common to all data types
36- if symb is None or symb == False:
37- return None
38-
39- # we need to convert the string to a unicode object to be able
40- # to evaluate its length (and possibly truncate it) reliably
41- u_symb = tools.ustr(symb)
42-
43- return u_symb[:self.size].encode('utf8')
44+ # self._symbol_set_char defined to keep the backward compatibility
45+ self._symbol_f = self._symbol_set_char = lambda x: _symbol_set_char(self, x)
46+ self._symbol_set = (self._symbol_c, self._symbol_f)
47
48
49 class text(_column):
50@@ -1085,6 +1087,11 @@
51 self._symbol_f = integer._symbol_f
52 self._symbol_set = integer._symbol_set
53
54+ if type == 'char':
55+ self._symbol_c = char._symbol_c
56+ self._symbol_f = lambda x: _symbol_set_char(self, x)
57+ self._symbol_set = (self._symbol_c, self._symbol_f)
58+
59 def digits_change(self, cr):
60 if self._type == 'float':
61 if self.digits_compute: