← Back to team overview

openerp-community-reviewer team mailing list archive

[Merge] lp:~camptocamp/stock-logistic-barcode/7.0-fix_1266277-afe into lp:stock-logistic-barcode

 

Alexandre Fayolle - camptocamp has proposed merging lp:~camptocamp/stock-logistic-barcode/7.0-fix_1266277-afe into lp:stock-logistic-barcode.

Requested reviews:
  Stock and Logistic Core Editors (stock-logistic-core-editors)
Related bugs:
  Bug #1266277 in Stock And Logistic Bar Code: "x_barcode_id"
  https://bugs.launchpad.net/stock-logistic-barcode/+bug/1266277

For more details, see:
https://code.launchpad.net/~camptocamp/stock-logistic-barcode/7.0-fix_1266277-afe/+merge/208562

add a test for the existance of the x_barcode_id field in the overloaded write and create methods. 

These methods can be called for instance during the configuration step before the attribute has been created, and they will crash with an AttributeError
-- 
https://code.launchpad.net/~camptocamp/stock-logistic-barcode/7.0-fix_1266277-afe/+merge/208562
Your team Stock and Logistic Core Editors is requested to review the proposed merge of lp:~camptocamp/stock-logistic-barcode/7.0-fix_1266277-afe into lp:stock-logistic-barcode.
=== modified file 'tr_barcode_config/barcode/barcode_osv.py'
--- tr_barcode_config/barcode/barcode_osv.py	2013-02-18 09:27:15 +0000
+++ tr_barcode_config/barcode/barcode_osv.py	2014-02-27 10:06:38 +0000
@@ -94,7 +94,7 @@
 
 class barcode_osv(orm.Model):
     _register = False
-    
+
     def __init__(self, pool, cr):
         installer_obj = pool.get('tr.barcode.settings')
         model_obj = pool.get('ir.model')
@@ -102,23 +102,23 @@
         model_ids = model_obj.search(cr, uid, [('model', '=', self._name)])
         installer_obj.create(cr, uid, {'models_ids': [(6,0,model_ids)]}, context=None)
         super(barcode_osv, self).__init__(pool, cr)
-    
+
     def create(self, cr, uid, vals, context=None):
         barcode_id = False
         res = super(orm.Model, self).create(cr, uid, vals, context=context)
-        
+
         #### modification because the orm create method seems to go into the write method so there is 2 barcode created instead of one ####
         obj = self.browse(cr, uid, res, context=context)
-        if not obj.x_barcode_id:
-            barcode_id = create_barcode(cr, uid, res, vals, self._name, context=context)
-        else:
-            barcode_id = obj.x_barcode_id.id
-        #############################################################        
-                
-        if barcode_id:
-            cr.execute(("UPDATE %s SET x_barcode_id = %s WHERE id = %s") %(self._table,barcode_id,res))
+        if hasattr(obj, 'x_barcode_id'):
+            if not obj.x_barcode_id:
+                barcode_id = create_barcode(cr, uid, res, vals, self._name, context=context)
+            else:
+                barcode_id = obj.x_barcode_id.id
+        #############################################################
+            if barcode_id:
+                cr.execute(("UPDATE %s SET x_barcode_id = %s WHERE id = %s") %(self._table,barcode_id,res))
         return res
-    
+
     def write(self, cr, uid, ids, vals, context=None):
         if context==None:
            context = {}
@@ -127,6 +127,8 @@
         barcode_obj = self.pool.get('tr.barcode')
         for obj in self.browse(cr, uid, ids, context=context):
             context.update({'obj_id':obj.id})
+            if not hasattr(obj, 'x_barcode_id'):
+                break # the module is not fully configured, quick exit
             if not obj.x_barcode_id:
                 barcode_ids = barcode_obj.search(cr, uid, [
                                             ('res_model', '=', self._name),
@@ -143,4 +145,4 @@
                 write_barcode(cr, uid, [obj.x_barcode_id.id], vals, self._name, context=context)
         return super(orm.Model, self).write(cr, uid, ids, vals, context=context)
 
-# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
\ No newline at end of file
+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:


Follow ups