def add_acquisition(): form = AcquisitionForm() success_message = None error_message = None if form.validate_on_submit(): if request.method == 'POST': Acquisition.create(bn=escape(form.bn.data), title=escape(form.title.data), author=escape(form.author.data), publisher=escape(form.publisher.data), published_on=escape(form.published_on.data), tags=escape(form.tags.data), no_of_copies=escape(form.no_of_copies.data)) for x in range(0, int(form.no_of_copies.data)): Inventory.create(inventory_id=escape(form.bn.data) + escape('-') + escape(x), title=escape(form.title.data), author=escape(form.author.data), publisher=escape(form.publisher.data), published_on=escape(form.published_on.data), tags=escape(form.tags.data)) success_message = "Successfully added new book" return render_template("nav/acquisition.html", form=form, success_message=success_message, error_message=error_message) error_message = "Failed to add new book" return render_template("nav/acquisition.html", form=form, success_message=success_message, error_message=error_message)
class InventoryImporter(ImporterBase): """ Import the inventory to redis set of the UPCS hash of each data line keyed by UPC """ missing_upcs = 0 def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.inventory = Inventory(self.company.name) def pre_import_data(self): self.inventory.reset() super().pre_import_data() def import_data(self, *args, **kwargs): super().import_data(*args, **kwargs) def post_import_data(self): super().post_import_data() def process_row(self, row): upc = row['UPC'] # upc might be set to None # TODO: Move this check to the CSVRows model. We should filter all bad # data out there. This Importer should only take sanitized data and # save it to Redis. if upc: # store upc in redis set self.inventory.add_item(upc, row)
def __init__(self, company, fulfillment_service_id): self.company = company self.fulfillment_service_id = fulfillment_service_id self.inventory = Inventory(company.name) self.shop = ShopifyInterface( shop_url=company.shop_url, fulfillment_service_id=fulfillment_service_id) self._numb_products_updated = 0
def index(): # return jsonify(session['user']) book_count = Inventory.select().count() borrowed_count = Inventory.select().where( Inventory.status == 'Out').count() user_count = User.select().count() return render_template('nav/index.html', book_count=book_count, borrowed_count=borrowed_count, user_count=user_count)
def import_script_shutdown(**kwargs): pass log.debug('worker_shutting_down signal') dropbox_interface = DropboxInterface() # Deletes the cursor in Redis. dropbox_interface.shutdown() # Reset Inventory in Redis for all companies # get all companies companies = Company.objects.all() for c in companies: Inventory(c.name).reset()
class InventoryExporter(): """ Export the latest inventory data to the shops for each company. """ def __init__(self, company, fulfillment_service_id): self.company = company self.fulfillment_service_id = fulfillment_service_id self.inventory = Inventory(company.name) self.shop = ShopifyInterface( shop_url=company.shop_url, fulfillment_service_id=fulfillment_service_id) self._numb_products_updated = 0 def export_data(self): for variant_id, variant in self.shop.variants.items(): save_needed = False invalid_upcs = [] # check for a upc upc = variant.barcode # check for valid UPC if not is_upc_valid(upc): invalid_upcs.append(upc) continue self.shop.set_level_available(variant, self.get_quantity_by_upc(upc)) # TODO: Do I need to use this? Could I just leave the product_type # alone? # update the product collection for Theia only if self.company.name == 'Theia': # loop over the products for p_id, p in self.shop.products.items(): # is the product instock? if self.is_product_in_stock(p) and 'Bridal' not in p.tags: self.shop.update_product(p, 'product_type', 'Theia Shop') else: # out of stock, make sure it goes in the lookbook self.shop.update_product(p, 'product_type', 'Theia Collection') # Reset the current inventory. self.inventory.reset() log.info('Shopify Products Updated: {}'.format(self._numb_products_updated)) def get_quantity_by_upc(self, upc): try: quantity = self.inventory.get_item_value(upc, 'QUANTITY') except Exception as e: log.exception(e) log.warning('Unable to get quantity with upc: {}'.format(upc)) else: try: return int(quantity) except Exception as e: log.exception(e) log.warning( 'Unable to cast quantity value: {} to in for upc: {}'.format( quantity, upc)) return 0 def is_product_in_stock(self, product): # get a list of variants for this product variant_quantities = [ self.shop.get_level_available(v) for v in self.shop.variants.values() if v.product_id == product.id ] for q in variant_quantities: if q > 0: return True return False
def get_inventory(): return jsonify([row for row in Inventory.select(Inventory).dicts()])
def del_acquisition(): Reservation.drop_table() Acquisition.drop_table() Inventory.drop_table() return 'deleted'
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.inventory = Inventory(self.company.name)