Browse Source

fix crash when populating timstamp

Daniel Sheffield 2 years ago
parent
commit
074bbdafe9
1 changed files with 8 additions and 2 deletions
  1. 8 2
      app/activities/TransactionEditor.py

+ 8 - 2
app/activities/TransactionEditor.py

@@ -5,6 +5,8 @@
 #
 #
 # THIS SOFTWARE IS PROVIDED AS IS WITHOUT WARRANTY
 # THIS SOFTWARE IS PROVIDED AS IS WITHOUT WARRANTY
 import itertools
 import itertools
+from dateutil.parser import parse as parse_time
+from dateutil.parser._parser import ParserError
 from decimal import Decimal, InvalidOperation
 from decimal import Decimal, InvalidOperation
 from itertools import chain
 from itertools import chain
 from typing import Callable, Union
 from typing import Callable, Union
@@ -108,6 +110,10 @@ class TransactionEditor(FocusWidget):
     def update(self):
     def update(self):
         data = self.data
         data = self.data
         date, store = data['ts'], data['store']
         date, store = data['ts'], data['store']
+        try:
+            parse_time(date)
+        except ParserError:
+            date = None
         self.text_fields['dbview'].set_text(
         self.text_fields['dbview'].set_text(
             self.query_manager.get_session_transactions(date, store) if None not in (
             self.query_manager.get_session_transactions(date, store) if None not in (
                 date or None, store or None
                 date or None, store or None
@@ -186,7 +192,7 @@ class TransactionEditor(FocusWidget):
         if len(options):
         if len(options):
             widget._emit('open', options)
             widget._emit('open', options)
             return
             return
-        
+
         new_product_activity = self.activity_manager.get('new_product')
         new_product_activity = self.activity_manager.get('new_product')
         current_activity = self.activity_manager.current()
         current_activity = self.activity_manager.current()
         if current_activity is not new_product_activity and name in (
         if current_activity is not new_product_activity and name in (
@@ -194,7 +200,7 @@ class TransactionEditor(FocusWidget):
         ):
         ):
             self.new_product_callback(name)
             self.new_product_callback(name)
         return
         return
-    
+
     def new_product_callback(self, name):
     def new_product_callback(self, name):
         cur = self.activity_manager.current()
         cur = self.activity_manager.current()
         txn = self.activity_manager.get('transaction')
         txn = self.activity_manager.get('transaction')