Skip to content

Instantly share code, notes, and snippets.

@aliomattux
Created September 6, 2013 04:12
Show Gist options
  • Save aliomattux/6459481 to your computer and use it in GitHub Desktop.
Save aliomattux/6459481 to your computer and use it in GitHub Desktop.
def get_bins(self, cr, uid, bin_selection, storage_type, list_exclusions, qty_dict, context=None):
base_sql = "SELECT DISTINCT bin.id " \
"\nFROM stock_location_bin bin " \
"\nLEFT JOIN stock_inventory stock ON stock.bin_id = bin.id"
first = True
if bin_selection == 'empty':
if first:
first = False
operator = ' WHERE'
else:
operator = ' AND'
base_sql += "\n%s stock.bin_id IS NULL" % operator
elif bin_selection == 'not_empty':
if first:
first = False
operator = ' WHERE'
else:
operator = ' AND'
base_sql += "\n%s stock.bin_id IS NOT NULL" % operator
if storage_type and storage_type != 'all':
if first:
first = False
operator = ' WHERE'
else:
operator = ' AND'
base_sql += " \n%s bin.storage_type = '%s'" % (operator, storage_type)
if list_exclusions and list_exclusions != []:
if len(list_exclusions) == 1:
query += "\nAND bin.id != %s" % str(list_exclusions[0])
else:
query += "\nAND bin.id NOT IN %s" % str(tuple(list_exclusions))
if qty_dict:
if first:
first = False
operator = ' WHERE'
else:
operator = ' AND'
base_sql += "\n%s stock.qty_onhand %s %s" % (operator, qty_dict['operator'], qty_dict['value'])
return base_sql
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment