Record bad scans in transaction; tweak snackbar etc.
This commit is contained in:
		
							parent
							
								
									39abb0d648
								
							
						
					
					
						commit
						4058f2df67
					
				
					 1 changed files with 47 additions and 14 deletions
				
			
		|  | @ -95,6 +95,7 @@ class POSView(WuttaView): | |||
| 
 | ||||
|         self.page.snack_bar = ft.SnackBar(ft.Text(f"CUSTOMER SET: {customer}", | ||||
|                                                   color='black', | ||||
|                                                   size=20, | ||||
|                                                   weight=ft.FontWeight.BOLD), | ||||
|                                           bgcolor='green', | ||||
|                                           duration=1500) | ||||
|  | @ -110,22 +111,22 @@ class POSView(WuttaView): | |||
|         else: | ||||
|             self.item_lookup() | ||||
| 
 | ||||
|     def attempt_add_product(self, uuid=None): | ||||
|     def attempt_add_product(self, uuid=None, record_badscan=False): | ||||
|         session = self.app.make_session() | ||||
|         handler = self.get_batch_handler() | ||||
|         batch = self.get_current_batch(session) | ||||
|         entry = self.main_input.value | ||||
| 
 | ||||
|         kw = {} | ||||
|         quantity = 1 | ||||
|         if self.set_quantity.data is not None: | ||||
|             kw['quantity'] = self.set_quantity.data | ||||
|             quantity = self.set_quantity.data | ||||
| 
 | ||||
|         product = None | ||||
|         if uuid: | ||||
|             product = session.get(self.model.Product, uuid) | ||||
|             assert product | ||||
| 
 | ||||
|         row = handler.process_entry(batch, product or entry, **kw) | ||||
|         row = handler.process_entry(batch, product or entry, quantity=quantity) | ||||
| 
 | ||||
|         if row: | ||||
|             session.commit() | ||||
|  | @ -135,8 +136,13 @@ class POSView(WuttaView): | |||
|             self.reset() | ||||
| 
 | ||||
|         else: | ||||
| 
 | ||||
|             if record_badscan: | ||||
|                 handler.record_badscan(batch, entry, quantity=quantity) | ||||
| 
 | ||||
|             self.page.snack_bar = ft.SnackBar(ft.Text(f"PRODUCT NOT FOUND: {entry}", | ||||
|                                                       color='black', | ||||
|                                                       size=20, | ||||
|                                                       weight=ft.FontWeight.BOLD), | ||||
|                                               bgcolor='yellow', | ||||
|                                               duration=1500) | ||||
|  | @ -208,6 +214,7 @@ class POSView(WuttaView): | |||
|                 session.close() | ||||
|                 self.page.snack_bar = ft.SnackBar(ft.Text(f"CUSTOMER NOT FOUND: {entry}", | ||||
|                                                           color='black', | ||||
|                                                           size=20, | ||||
|                                                           weight=ft.FontWeight.BOLD), | ||||
|                                                   bgcolor='yellow', | ||||
|                                                   duration=1500) | ||||
|  | @ -370,6 +377,7 @@ class POSView(WuttaView): | |||
|             dlg.open = False | ||||
|             self.page.snack_bar = ft.SnackBar(ft.Text("CUSTOMER REMOVED", | ||||
|                                                       color='black', | ||||
|                                                       size=20, | ||||
|                                                       weight=ft.FontWeight.BOLD), | ||||
|                                               bgcolor='yellow', | ||||
|                                               duration=1500) | ||||
|  | @ -422,6 +430,7 @@ class POSView(WuttaView): | |||
|         else: # customer not found | ||||
|             self.page.snack_bar = ft.SnackBar(ft.Text(f"CUSTOMER NOT FOUND: {entry}", | ||||
|                                                       color='black', | ||||
|                                                       size=20, | ||||
|                                                       weight=ft.FontWeight.BOLD), | ||||
|                                               bgcolor='yellow', | ||||
|                                               duration=1500) | ||||
|  | @ -504,6 +513,7 @@ class POSView(WuttaView): | |||
|                     quantity = self.set_quantity.data | ||||
|                     self.page.snack_bar = ft.SnackBar(ft.Text(f"QUANTITY ALREADY SET: {quantity}", | ||||
|                                                               color='black', | ||||
|                                                               size=20, | ||||
|                                                               weight=ft.FontWeight.BOLD), | ||||
|                                                       bgcolor='yellow', | ||||
|                                                       duration=1500) | ||||
|  | @ -525,6 +535,7 @@ class POSView(WuttaView): | |||
|                     else: | ||||
|                         self.page.snack_bar = ft.SnackBar(ft.Text(f"INVALID @ QUANTITY: {quantity}", | ||||
|                                                                   color='black', | ||||
|                                                                   size=20, | ||||
|                                                                   weight=ft.FontWeight.BOLD), | ||||
|                                                           bgcolor='yellow', | ||||
|                                                           duration=1500) | ||||
|  | @ -639,15 +650,15 @@ class POSView(WuttaView): | |||
|                 [ | ||||
|                     ft.Row( | ||||
|                         [ | ||||
|                             meta_button("MGR", bgcolor='blue', on_click=self.not_supported), | ||||
|                             meta_button("ITEM", bgcolor='blue', on_click=self.item_click), | ||||
|                             meta_button("VOID", bgcolor='red', on_click=self.void_click), | ||||
|                         ], | ||||
|                         spacing=0, | ||||
|                     ), | ||||
|                     ft.Row( | ||||
|                         [ | ||||
|                             meta_button("ITEM", bgcolor='blue', on_click=self.item_click), | ||||
|                             meta_button("CUST", bgcolor='blue', on_click=self.customer_click), | ||||
|                             meta_button("MGR", bgcolor='blue', on_click=self.not_supported), | ||||
|                         ], | ||||
|                         spacing=0, | ||||
|                     ), | ||||
|  | @ -797,6 +808,7 @@ class POSView(WuttaView): | |||
|         if feature: | ||||
|             text += f": {feature}" | ||||
|         self.page.snack_bar = ft.SnackBar(ft.Text(text, color='black', | ||||
|                                                   size=20, | ||||
|                                                   weight=ft.FontWeight.BOLD), | ||||
|                                           bgcolor='yellow', | ||||
|                                           duration=1500) | ||||
|  | @ -804,6 +816,11 @@ class POSView(WuttaView): | |||
|         self.page.update() | ||||
| 
 | ||||
|     def add_row_item(self, row): | ||||
| 
 | ||||
|         # TODO: row types ugh | ||||
|         if row.row_type not in ('sell',): | ||||
|             return | ||||
| 
 | ||||
|         quantity = self.app.render_quantity(row.quantity) | ||||
|         pretty_price = self.app.render_currency(row.txn_price) | ||||
|         self.items.controls.append( | ||||
|  | @ -903,17 +920,32 @@ class POSView(WuttaView): | |||
|     def tender_click(self, e): | ||||
|         model = self.model | ||||
|         session = self.app.make_session() | ||||
|         handler = self.get_batch_handler() | ||||
|         user = session.get(model.User, self.page.session.get('user_uuid')) | ||||
|         batch = handler.get_current_batch(user) | ||||
| 
 | ||||
|         # tender / execute batch | ||||
|         tender = e.control.content.value | ||||
|         handler.tender_and_execute(batch, user, tender) | ||||
|         session.commit() | ||||
|         session.close() | ||||
|         try: | ||||
|             handler = self.get_batch_handler() | ||||
|             user = session.get(model.User, self.page.session.get('user_uuid')) | ||||
|             batch = handler.get_current_batch(user) | ||||
|             handler.tender_and_execute(batch, user, tender) | ||||
| 
 | ||||
|         except Exception as error: | ||||
|             session.rollback() | ||||
|             log.exception("failed to execute batch") | ||||
|             self.page.snack_bar = ft.SnackBar(ft.Text(f"ERROR: {error}", | ||||
|                                                       color='black', | ||||
|                                                       size=20, | ||||
|                                                       weight=ft.FontWeight.BOLD), | ||||
|                                               bgcolor='red', | ||||
|                                               duration=1500) | ||||
|             self.page.snack_bar.open = True | ||||
| 
 | ||||
|         else: | ||||
|             session.commit() | ||||
|             self.clear_all() | ||||
|         finally: | ||||
|             session.close() | ||||
| 
 | ||||
|         self.clear_all() | ||||
|         self.reset() | ||||
| 
 | ||||
|     def clear_all(self): | ||||
|  | @ -925,5 +957,6 @@ class POSView(WuttaView): | |||
|         self.informed_refresh() | ||||
| 
 | ||||
|     def main_submit(self, e=None): | ||||
|         self.attempt_add_product() | ||||
|         if self.main_input.value: | ||||
|             self.attempt_add_product(record_badscan=True) | ||||
|         self.reset() | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Lance Edgar
						Lance Edgar