From 785e3a243ae3d5d66b35d598e4f032b83131dc29 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Fr=C3=A9d=C3=A9ric=20van=20der=20Essen?= Date: Tue, 9 Dec 2014 21:38:52 +0100 Subject: [PATCH] [IMP] barcodes: use builtin python sets when it makes sense --- addons/point_of_sale/point_of_sale.py | 30 ++++++++++-------------------- addons/stock/stock.py | 26 +++++++++----------------- 2 files changed, 19 insertions(+), 37 deletions(-) diff --git a/addons/point_of_sale/point_of_sale.py b/addons/point_of_sale/point_of_sale.py index abae5f6..d30d754 100644 --- a/addons/point_of_sale/point_of_sale.py +++ b/addons/point_of_sale/point_of_sale.py @@ -22,6 +22,7 @@ import logging import time import uuid +import sets from openerp import tools, models from openerp.osv import fields, osv @@ -1466,25 +1467,14 @@ class barcode_rule(models.Model): _inherit = 'barcode.rule' def _get_type_selection(self): - types = super(barcode_rule,self)._get_type_selection() - - new_types = [ - ('weight','Weighted Product'), - ('price','Priced Product'), - ('discount','Discounted Product'), - ('client','Client'), - ('cashier','Cashier') - ] - - for (key, value) in new_types: - add = True - for (key2, value2) in types: - if key == key2: - add = False - break - if add: - types += [(key, value)] - - return types + types = sets.Set(super(barcode_rule,self)._get_type_selection()) + types.update([ + ('weight','Weighted Product'), + ('price','Priced Product'), + ('discount','Discounted Product'), + ('client','Client'), + ('cashier','Cashier') + ]) + return list(types) # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/stock/stock.py b/addons/stock/stock.py index 443ad6a..e6db4b5 100644 --- a/addons/stock/stock.py +++ b/addons/stock/stock.py @@ -23,6 +23,7 @@ from datetime import date, datetime from dateutil import relativedelta import json import time +import sets import openerp from openerp.osv import fields, osv @@ -4307,22 +4308,13 @@ class barcode_rule(models.Model): _inherit = 'barcode.rule' def _get_type_selection(self): - types = super(barcode_rule,self)._get_type_selection() - - new_types = [('weight','Weighted Product'), - ('location','Location'), - ('lot','Lot'), - ('package','Package')] - - for (key, value) in new_types: - add = True - for (key2, value2) in types: - if key == key2: - add = False - break - if add: - types += [(key, value)] - - return types + types = sets.Set(super(barcode_rule,self)._get_type_selection()) + types.update([ + ('weight','Weighted Product'), + ('location','Location'), + ('lot','Lot'), + ('package','Package') + ]) + return list(types) # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: -- 1.7.10.4