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
=== modified file 'openerp/osv/fields.py'
--- openerp/osv/fields.py 2013-06-20 13:10:57 +0000
+++ openerp/osv/fields.py 2013-10-08 11:16:45 +0000
@@ -208,27 +208,29 @@
208 return model.name_get(cr, uid, [int(res_id)], context=context)[0][1]208 return model.name_get(cr, uid, [int(res_id)], context=context)[0][1]
209 return tools.ustr(value)209 return tools.ustr(value)
210210
211# takes a string (encoded in utf8) and returns a string (encoded in utf8)
212def _symbol_set_char(self, symb):
213
214 #TODO:
215 # * we need to remove the "symb==False" from the next line BUT
216 # for now too many things rely on this broken behavior
217 # * the symb==None test should be common to all data types
218 if symb is None or symb == False:
219 return None
220
221 # we need to convert the string to a unicode object to be able
222 # to evaluate its length (and possibly truncate it) reliably
223 u_symb = tools.ustr(symb)
224 return u_symb[:self.size].encode('utf8')
225
211class char(_column):226class char(_column):
212 _type = 'char'227 _type = 'char'
213228
214 def __init__(self, string="unknown", size=None, **args):229 def __init__(self, string="unknown", size=None, **args):
215 _column.__init__(self, string=string, size=size or None, **args)230 _column.__init__(self, string=string, size=size or None, **args)
216 self._symbol_set = (self._symbol_c, self._symbol_set_char)231 # self._symbol_set_char defined to keep the backward compatibility
217232 self._symbol_f = self._symbol_set_char = lambda x: _symbol_set_char(self, x)
218 # takes a string (encoded in utf8) and returns a string (encoded in utf8)233 self._symbol_set = (self._symbol_c, self._symbol_f)
219 def _symbol_set_char(self, symb):
220 #TODO:
221 # * we need to remove the "symb==False" from the next line BUT
222 # for now too many things rely on this broken behavior
223 # * the symb==None test should be common to all data types
224 if symb is None or symb == False:
225 return None
226
227 # we need to convert the string to a unicode object to be able
228 # to evaluate its length (and possibly truncate it) reliably
229 u_symb = tools.ustr(symb)
230
231 return u_symb[:self.size].encode('utf8')
232234
233235
234class text(_column):236class text(_column):
@@ -1085,6 +1087,11 @@
1085 self._symbol_f = integer._symbol_f1087 self._symbol_f = integer._symbol_f
1086 self._symbol_set = integer._symbol_set1088 self._symbol_set = integer._symbol_set
10871089
1090 if type == 'char':
1091 self._symbol_c = char._symbol_c
1092 self._symbol_f = lambda x: _symbol_set_char(self, x)
1093 self._symbol_set = (self._symbol_c, self._symbol_f)
1094
1088 def digits_change(self, cr):1095 def digits_change(self, cr):
1089 if self._type == 'float':1096 if self._type == 'float':
1090 if self.digits_compute:1097 if self.digits_compute: