-
-
Save sharoonthomas/6464922 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_bins(self, cr, uid, bin_selection, storage_type, list_exclusions, qty_dict, context=None): | |
""" Find a list of locations based on user-defined criteria | |
:param :bin_selection Selection field, Bins with no assignment, bins with assignment only, or all | |
:param :storage_type Filter based on a specified storage type, i.e, overstock, backstock | |
:param :list_exclusions List of bin_ids to exclude from the search | |
:param :qty_dict Quantity in bin GT/LT threshold | |
@return list of bin_ids with travel sequence | |
""" | |
base_sql = "SELECT DISTINCT bin.id bin.sequence" \ | |
"\nFROM stock_location_bin bin " \ | |
"\nLEFT JOIN stock_inventory stock ON stock.bin_id = bin.id" | |
#First = Whether or not to use WHERE/AND | |
first = True | |
#Bin Selection Show Empty(no assignment) | |
if bin_selection == 'empty': | |
if first: | |
first = False | |
operator = self.get_operator(cr, uid, first) | |
base_sql += "\n%s stock.bin_id IS NULL" % operator | |
#Bin must have an assignment | |
elif bin_selection == 'not_empty': | |
if first: | |
first = False | |
operator = self.get_operator(cr, uid, first) | |
base_sql += "\n%s stock.bin_id IS NOT NULL" % operator | |
#Storage type, Dynamic, Overstock, etc | |
if storage_type and storage_type != 'all': | |
if first: | |
first = False | |
operator = self.get_operator(cr, uid, first) | |
base_sql += " \n%s bin.storage_type = '%s'" % (operator, storage_type) | |
#List of location ids to exclude from the search | |
if list_exclusions and list_exclusions != []: | |
if first: | |
first = False | |
operator = self.get_operator(cr, uid, first) | |
if len(list_exclusions) == 1: | |
query += "\n%s bin.id != %s" % (operator, str(list_exclusions[0])) | |
else: | |
query += "\n%s bin.id NOT IN %s" % (operator, str(tuple(list_exclusions))) | |
#If user selects quantity > or < it will find existing locs with that threshold | |
if qty_dict: | |
if first: | |
first = False | |
operator = self.get_operator(cr, uid, first) | |
base_sql += "\n%s stock.qty_onhand %s %s" % (operator, qty_dict['operator'], qty_dict['value']) | |
cr.execute(base_sql) | |
results = cr.fetchall() | |
return [id for id in results] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment