Răsfoiți Sursa

Various bugfixes

Pi 3 ani în urmă
părinte
comite
f2939dcea2
3 a modificat fișierele cu 22 adăugiri și 18 ștergeri
  1. 7 5
      db_utils.py
  2. 13 12
      price_check.py
  3. 2 1
      txn_view.py

+ 7 - 5
db_utils.py

@@ -75,15 +75,17 @@ def unique_suggestions(cur, statement, name, display, exclude=NON_IDENTIFIER_COL
     items = suggestions(cur, statement, name, display, exclude=exclude, **kwargs)
     ret = sorted(set(map(lambda x: x[name], items)))
     tables = {
-        'product': 'products',
-        'category': 'categories',
-        'group': 'groups',
-        'unit': 'store',
+        'product',
+        'category',
+        'group',
+        'unit',
+        'store',
     }
     if len(ret) > 0 or name not in tables:
         return ret
         
-    items = get_data(cur, get_table_statement(tables[name]), display)
+    items = (i for i in filter(lambda x: record_matches(x, **{ name: kwargs[name] }),
+    get_data(cur, get_table_statement(name), display)))
     return sorted(set(map(lambda x: x[name], items)))
 
 def suggestions(cur, statement, name, display, exclude=NON_IDENTIFIER_COLUMNS, **kwargs):

+ 13 - 12
price_check.py

@@ -229,8 +229,8 @@ class PriceCheck(urwid.WidgetPlaceholder):
     def update_rating(self, _avg, _min, _max, price=None, quantity=None):
         if None in (_avg, _min, _max):
             return
-        current = None if None in (price, quantity) else float(price/quantity)
-        size = 16
+        current = None if None in (price, quantity or None) else float(price/quantity)
+        size = 14
         chars = ['|', *['-']*(size - 2), '|' ]
         rating = [' ']*len(chars)
         _min, _max = min(_min, current or _min), max(_max, current or _max)
@@ -238,16 +238,17 @@ class PriceCheck(urwid.WidgetPlaceholder):
 
         for idx, (e, a) in enumerate(zip(ls, ls[1:])):
             if e <= _avg < a:
-                chars[max(idx-4,0)] = '['
-                chars[min(idx+4,len(chars)-1)] = ']'
-                for _idx, c in enumerate(f'{_avg:>7.2f}'):
-                    chars[max(idx-3+_idx,0)] = c
+                for c, (_idx,_) in zip('[{}]'.format(''.join(list(f'{_avg:>5.2f}')[:idx-3+5])), filter(lambda x: idx-3 < x[0], enumerate(chars))):
+                    chars[_idx] = c
+                chars[0] = '|'
+                chars[-1] = '|'
             
             if current is not None and e <= current < a:
                 rating[idx] = '^'
-        
-        self.text_fields['spread'].set_text(f"{_min:>7.2f}{''.join(chars)}{_max:<7.2f}")
-        self.text_fields['rating'].set_text(f"{' '*7}{''.join(rating)}{' '*7}")
+        if current == _max:
+            rating[-1] = '^'
+        self.text_fields['spread'].set_text(f"{_min:>5.2f}{''.join(chars)}{_max:<5.2f}")
+        self.text_fields['rating'].set_text(f"{' '*5}{''.join(rating)}{' '*5}")
         
     
     def update_historic_prices(self):
@@ -255,14 +256,14 @@ class PriceCheck(urwid.WidgetPlaceholder):
         sort = '$/unit' if self.buttons['sort_price'].state else 'ts'
         product, unit = self.data['product'] or None, self.data['unit'] or None
         try: 
-            price = Decimal(self.data['price']) or None
+            price = Decimal(self.data['price'])
         except InvalidOperation:
             price = None
         
         try:
-            quantity = Decimal(self.data['quantity']) or None
+            quantity = Decimal(self.data['quantity'])
         except InvalidOperation:
-            price = None
+            quantity = None
         
         if None not in (sort, product, unit):
             self.text_fields['dbview'].set_text(

+ 2 - 1
txn_view.py

@@ -20,7 +20,8 @@ def get_table_statement(alias):
         'product': 'products',
         'category': 'categories',
         'group': 'groups',
-        'unit': 'store',
+        'unit': 'units',
+        'store': 'stores',
     }
     return SQL("SELECT {column} AS {alias} FROM {table}").format(
         column=Identifier(tables[alias], 'name'),