diff --git a/order_point.py b/order_point.py index ca5edba04b..06e025a85d 100644 --- a/order_point.py +++ b/order_point.py @@ -84,11 +84,13 @@ class OrderPoint(OSV): ids = self.search(cursor, user, query) return not bool(ids) - def check_uniqueness_field(self, type): - if type == 'purchase': - return 'warehouse_location' - elif type == 'internal': - return 'storage_location' + def type2field(self, type=None): + t2f = (('warehouse_location', 'purchase'), + ('storage_location', 'internal')) + if type == None: + return t2f + else: + return dict(t2f)[type] def check_uniqueness(self, cursor, user, ids): """ @@ -98,7 +100,7 @@ class OrderPoint(OSV): """ query = ['OR'] for op in self.browse(cursor, user, ids): - field = self.check_uniqueness_field(op.type) + field = self.type2field(op.type) arg = ['AND', (field, '=', op[field].id), ('id', '!=', op.id), @@ -135,8 +137,8 @@ class OrderPoint(OSV): def search_location(self, cursor, user, name, domain=None, context=None): ids = [] - for field in ('warehouse_location', 'storage_location'): - args = [] + for field, type in self.type2field(): + args = [('type', '=', type)] for _, operator, operand in domain: args.append((field, operator, operand)) ids.extend(self.search(cursor, user, args, context=context))