def _move_off_item(self): ''' Called when the editor moves off an item. If the __active_item attribute is not None, we save the current edit window into the active item. If the __active_item attribute is None, and we have a stock item in the editor, we try to save it ''' if self.__active_item != None: # moving off an active item # Might have changed the stock reference self.__stock_item_editor.get_from_editor(self.__active_item) else: # creating a new item try: # make an empty stock item new_item = StockItem('empty', 10, 'empty') try: self.__stock_item_editor.get_from_editor(new_item) except: return self.__shop.store_new_stock_item(new_item) self.__stock_item_selector.populate_listbox( self.__shop.find_matching_with_tags(self.__search_set)) except: messagebox.showwarning('Save entry', 'Entry not saved')
def dress_generator(): ''' Retuns dress test items one at a time ''' stock_id = 1 for price in [100, 150, 200, 500]: for color in ['red', 'green', 'blue', 'yellow', 'pink']: color_tag = 'color:' + color for pattern in ['swirly', 'plain', 'spots']: pattern_tag = 'pattern:' + pattern for size in [8, 10, 12, 14, 16]: size_tag='size:' + str(size) id_string = 'DR' + str(stock_id) location_tag = 'loc:dress rail' tags = set(('dress',color_tag, pattern_tag, size_tag, location_tag)) tags_string = StockItem.get_text_from_tag_set(tags) item = StockItem(id_string, price, tags_string) stock_id = stock_id + 1 yield item
def test_StockItem_sell_stock(self): item = StockItem(stock_ref='Test', price=10, tags='test:tag') self.assertEqual(item.stock_level, 0) item.add_stock(10) self.assertEqual(item.stock_level, 10) item.sell_stock(2) self.assertEqual(item.stock_level, 8)
def test_StockItem_add_stock(self): item = StockItem(stock_ref='Test', price=10, tags='test:tag') self.assertEqual(item.stock_level, 0) item.add_stock(10) self.assertEqual(item.stock_level, 10) with self.assertRaises(Exception): item.add_stock(-1)
def create_new_stock_item(self): ''' Creates a new stock item. Gets the details of the item, creates it and then stores it in the shop ''' stock_ref = read_text('Enter stock reference: ') price = read_float_ranged(prompt='Enter price: ', min_value=StockItem.min_price, max_value=StockItem.max_price) tag_string = read_text('Enter tags (separated by commas): ') tags = StockItem.get_tag_set_from_text(tag_string) new_item = StockItem(stock_ref=stock_ref, price=price, tags=tags) try: self.__shop.store_new_stock_item(new_item) print('Item stored') except Exception as e: print('Item not stored ') print(e)
def do_tag_filter(self): print('Filter on tags') tag_string = read_text( 'Enter the tags to look for (separated by commas): ') search_tags = StockItem.get_tag_set_from_text(tag_string) items = self.__shop.find_matching_with_tags(search_tags) stock = map(str, items) stock_list = '\n'.join(stock) template = '''Matching items {0} ''' print(stock_list)
def do_tag_search(self): search_string = self.__tagSearchEnty.get() self.__search_set = StockItem.get_tag_set_from_text(search_string) self.__stock_item_selector.populate_listbox( self.__shop.find_matching_with_tags(self.__search_set))
def test_StockItem_init(self): item = StockItem(stock_ref='Test', price=10, tags='test:tag') self.assertEqual(item.stock_ref, 'Test') self.assertEqual(item.price, 10) self.assertEqual(item.stock_level, 0) self.assertEqual(item.tags, 'test:tag')