← Back to team overview

openerp-dev-web team mailing list archive

[Merge] lp:~openerp-dev/openobject-server/6.0-opw-5480-ach into lp:openobject-server/6.0

 

Anup(OpenERP) has proposed merging lp:~openerp-dev/openobject-server/6.0-opw-5480-ach into lp:openobject-server/6.0.

Requested reviews:
  Olivier Dony (OpenERP) (odo)
  Jay Vora (OpenERP) (jvo-openerp)
Related bugs:
  Bug #772230 in OpenERP Server: "ir.attachment res_name : function _name_get_resname exceeds size limit"
  https://bugs.launchpad.net/openobject-server/+bug/772230

For more details, see:
https://code.launchpad.net/~openerp-dev/openobject-server/6.0-opw-5480-ach/+merge/59502

Hello,

     I have already faced this error few days back. I have found a fix for the same. I would like to mention few things that needs to be keep in mind.

1. The res_name is a functional field which is field by the name or say _rec_name of the source record. The _rec_name may not be a character field but as tools.ustr() is used this will work for all type of fields.

2. We can not change the size of the field according to the received data as it may cause problems. It's better to restrict the incoming data by restricting to the field's original size.

3. It may be the case that a user needs to view this field and wants more characters to be displayed than the existing 128 characters. So he can increase the size inheriting the object. SO we need to take the size of field we can not keep 128 hard coded. (That's why I have taken 'field.size').

Please share your views.


Thanks.
-- 
https://code.launchpad.net/~openerp-dev/openobject-server/6.0-opw-5480-ach/+merge/59502
Your team OpenERP R&D Team is subscribed to branch lp:~openerp-dev/openobject-server/6.0-opw-5480-ach.
=== modified file 'bin/addons/base/ir/ir_attachment.py'
--- bin/addons/base/ir/ir_attachment.py	2011-02-18 13:14:54 +0000
+++ bin/addons/base/ir/ir_attachment.py	2011-04-29 12:36:35 +0000
@@ -121,7 +121,7 @@
         return self.pool.get('ir.actions.act_window').for_xml_id(
             cr, uid, 'base', 'action_attachment', context=context)
 
-    def _name_get_resname(self, cr, uid, ids, object,method, context):
+    def _name_get_resname(self, cr, uid, ids, object, method, context):
         data = {}
         for attachment in self.browse(cr, uid, ids, context=context):
             model_object = attachment.res_model
@@ -129,7 +129,12 @@
             if model_object and res_id:
                 model_pool = self.pool.get(model_object)
                 res = model_pool.name_get(cr,uid,[res_id],context)
-                data[attachment.id] = (res and res[0][1]) or False
+                res_name = res and res[0][1] or False
+                if res_name:
+                    field = self._columns.get('res_name')
+                    if len(res_name )>field.size:
+                        res_name = res_name[:field.size-3] + '...' 
+                data[attachment.id] = res_name
             else:
                  data[attachment.id] = False
         return data


Follow ups