[IMP]:product module sql queries to parameterized query
authornch@tinyerp.com <>
Tue, 24 Nov 2009 12:09:06 +0000 (17:39 +0530)
committernch@tinyerp.com <>
Tue, 24 Nov 2009 12:09:06 +0000 (17:39 +0530)
bzr revid: nch@tinyerp.com-20091124120906-ssum4kpo1g1klw3f

addons/product/pricelist.py
addons/product/product.py

index e44e906..0660884 100644 (file)
@@ -1,6 +1,6 @@
 # -*- coding: utf-8 -*-
 ##############################################################################
-#    
+#
 #    OpenERP, Open Source Management Solution
 #    Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
 #
@@ -15,7 +15,7 @@
 #    GNU Affero General Public License for more details.
 #
 #    You should have received a copy of the GNU Affero General Public License
-#    along with this program.  If not, see <http://www.gnu.org/licenses/>.     
+#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #
 ##############################################################################
 
@@ -83,12 +83,12 @@ class product_pricelist(osv.osv):
         pricelist_type_obj = self.pool.get('product.pricelist.type')
         pricelist_type_ids = pricelist_type_obj.search(cr, uid, [], order='name')
         pricelist_types = pricelist_type_obj.read(cr, uid, pricelist_type_ids, ['key','name'], context=context)
-        
+
         res = []
-        
+
         for type in pricelist_types:
             res.append((type['key'],type['name']))
-        
+
         return res
 #        cr.execute('select key,name from product_pricelist_type order by name')
 #        return cr.fetchall()
@@ -101,7 +101,7 @@ class product_pricelist(osv.osv):
         'version_id': fields.one2many('product.pricelist.version', 'pricelist_id', 'Pricelist Versions'),
         'currency_id': fields.many2one('res.currency', 'Currency', required=True),
     }
-    
+
     def name_get(self, cr, uid, ids, context={}):
         result= []
         if not all(ids):
@@ -110,7 +110,7 @@ class product_pricelist(osv.osv):
             name = pl.name + ' ('+ pl.currency_id.name + ')'
             result.append((pl.id,name))
         return result
-    
+
 
     def _get_currency(self, cr, uid, ctx):
         comp = self.pool.get('res.users').browse(cr, uid, uid).company_id
@@ -210,17 +210,16 @@ class product_pricelist(osv.osv):
                 elif res['base'] == -2:
                     where = []
                     if partner:
-                        where = [('name', '=', partner) ] 
+                        where = [('name', '=', partner) ]
                     sinfo = supplierinfo_obj.search(cr, uid,
                             [('product_id', '=', tmpl_id)] + where)
                     price = 0.0
                     if sinfo:
                         cr.execute('SELECT * ' \
                                 'FROM pricelist_partnerinfo ' \
-                                'WHERE suppinfo_id IN (' + \
-                                    ','.join(map(str, sinfo)) + ') ' \
-                                    'AND min_quantity <= %s ' \
-                                'ORDER BY min_quantity DESC LIMIT 1', (qty,))
+                                'WHERE suppinfo_id = ANY(%s)'
+                                'AND min_quantity <= %s ' \
+                                'ORDER BY min_quantity DESC LIMIT 1', (sinfo,qty,))
                         res2 = cr.dictfetchone()
                         if res2:
                             price = res2['price']
@@ -244,12 +243,12 @@ class product_pricelist(osv.osv):
                 # False means no valid line found ! But we may not raise an
                 # exception here because it breaks the search
                 price = False
-            result[id] = price            
+            result[id] = price
             if context and ('uom' in context):
                 product = product_obj.browse(cr, uid, prod_id)
                 uom = product.uos_id or product.uom_id
                 result[id] = self.pool.get('product.uom')._compute_price(cr,
-                        uid, uom.id, result[id], context['uom'])                
+                        uid, uom.id, result[id], context['uom'])
         return result
 
 product_pricelist()
@@ -331,16 +330,16 @@ class product_pricelist_item(osv.osv):
         'sequence': lambda *a: 5,
         'price_discount': lambda *a: 0,
     }
-    
+
     def _check_recursion(self, cr, uid, ids):
         for obj_list in self.browse(cr, uid, ids):
             if obj_list.base == -1:
                 main_pricelist = obj_list.price_version_id.pricelist_id.id
                 other_pricelist = obj_list.base_pricelist_id.id
                 if main_pricelist == other_pricelist:
-                    return False 
+                    return False
         return True
-    
+
     _columns = {
         'name': fields.char('Rule Name', size=64, help="Explicit rule name for this pricelist line."),
         'price_version_id': fields.many2one('product.pricelist.version', 'Price List Version', required=True, select=True),
@@ -367,11 +366,11 @@ class product_pricelist_item(osv.osv):
         'price_max_margin': fields.float('Max. Price Margin',
             digits=(16, int(config['price_accuracy']))),
     }
-    
+
     _constraints = [
         (_check_recursion, _('Error ! You cannot assign the Main Pricelist as Other Pricelist in PriceList Item!'), ['base_pricelist_id'])
     ]
-     
+
     def product_id_change(self, cr, uid, ids, product_id, context={}):
         if not product_id:
             return {}
index 509bd61..5026c99 100644 (file)
@@ -1,6 +1,6 @@
 # -*- coding: utf-8 -*-
 ##############################################################################
-#    
+#
 #    OpenERP, Open Source Management Solution
 #    Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
 #
@@ -15,7 +15,7 @@
 #    GNU Affero General Public License for more details.
 #
 #    You should have received a copy of the GNU Affero General Public License
-#    along with this program.  If not, see <http://www.gnu.org/licenses/>.     
+#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #
 ##############################################################################
 
@@ -208,7 +208,7 @@ class product_category(osv.osv):
     def _check_recursion(self, cr, uid, ids):
         level = 100
         while len(ids):
-            cr.execute('select distinct parent_id from product_category where id in ('+','.join(map(str, ids))+')')
+            cr.execute('select distinct parent_id from product_category where id =ANY(%s)',(ids,))
             ids = filter(None, map(lambda x:x[0], cr.fetchall()))
             if not level:
                 return False
@@ -394,8 +394,8 @@ class product_product(osv.osv):
         product = self.browse(cr, uid, [product_id], context)[0]
         for supinfo in product.seller_ids:
             if supinfo.name.id == partner_id:
-                return {'code': supinfo.product_code, 'name': supinfo.product_name, 'variants': ''}                
-        return {'code' : product.default_code, 'name' : product.name, 'variants': product.variants}                
+                return {'code': supinfo.product_code, 'name': supinfo.product_name, 'variants': ''}
+        return {'code' : product.default_code, 'name' : product.name, 'variants': product.variants}
 
     def _product_code(self, cr, uid, ids, name, arg, context={}):
         res = {}
@@ -408,7 +408,7 @@ class product_product(osv.osv):
         for p in self.browse(cr, uid, ids, context):
             data = self._get_partner_code_name(cr, uid, [], p.id, context.get('partner_id', None), context)
             if not data['variants']:
-                data['variants'] = p.variants            
+                data['variants'] = p.variants
             if not data['code']:
                 data['code'] = p.code
             if not data['name']:
@@ -444,7 +444,7 @@ class product_product(osv.osv):
         'packaging' : fields.one2many('product.packaging', 'product_id', 'Logistical Units', help="Gives the different ways to package the same product. This has no impact on the packing order and is mainly used if you use the EDI module."),
         'price_extra': fields.float('Variant Price Extra', digits=(16, int(config['price_accuracy']))),
         'price_margin': fields.float('Variant Price Margin', digits=(16, int(config['price_accuracy']))),
-        'pricelist_id': fields.dummy(string='Pricelist',relation='product.pricelist', type='many2one'),        
+        'pricelist_id': fields.dummy(string='Pricelist',relation='product.pricelist', type='many2one'),
     }
 
     def onchange_uom(self, cursor, user, ids, uom_id,uom_po_id):
@@ -542,7 +542,7 @@ class product_product(osv.osv):
             default = {}
         default = default.copy()
         default['name'] = product['name'] + _(' (copy)')
-        
+
         if context.get('variant',False):
             fields = ['product_tmpl_id', 'active', 'variants', 'default_code',
                     'price_margin', 'price_extra']
@@ -587,7 +587,7 @@ class product_packaging(osv.osv):
     }
 
     _order = 'sequence'
-    
+
     def name_get(self, cr, uid, ids, context={}):
         if not len(ids):
             return []