Procházet zdrojové kódy

fix organic field not autofilling when is unique

Daniel Sheffield před 3 roky
rodič
revize
19abb1cbc4
1 změnil soubory, kde provedl 17 přidání a 3 odebrání
  1. 17 3
      grocery_transactions.py

+ 17 - 3
grocery_transactions.py

@@ -222,6 +222,10 @@ cols = [
 ]
 
 #cols.remove(None)
+NON_AUTOFILL_COLUMNS = [
+    'ts',
+    'store',
+]
 
 NON_IDENTIFIER_COLUMNS = [
     'ts',
@@ -232,6 +236,13 @@ NON_IDENTIFIER_COLUMNS = [
     'organic',
 ]
 
+IGNORE_MATCH_COLUMNS = [
+    'organic',
+    'quantity',
+    'price',
+    'unit',
+]
+
 display_map = {
     'ts': lambda x: f"{time.strftime('%Y-%m-%d %H:%M', (x.year, x.month, x.day, x.hour, x.minute, 0, 0, 0, 0))}",
     'price': lambda x: f"{x:.2f}",
@@ -252,11 +263,14 @@ def records(cursor, col_idx_map):
     cur.execute("SELECT * FROM transaction_view;")
 
 
-def record_matches(record, strict=None, **kwargs):
+def record_matches(record, ignore_match=IGNORE_MATCH_COLUMNS, strict=None, **kwargs):
     strict = strict or []
     for k,v in kwargs.items():
         if not v:
             continue
+
+        if k in ignore_match:
+            continue
         
         if k in strict and v.lower() != record[k].lower():
             return False
@@ -282,7 +296,7 @@ def suggestions(name, exclude=NON_IDENTIFIER_COLUMNS, **kwargs):
     )
     [ kwargs.pop(k) for k in exclude if k in kwargs]
     yield from filter(lambda x: record_matches(
-        x, strict=[ k for k in kwargs if k != name ], **kwargs
+        x, ignore_match=IGNORE_MATCH_COLUMNS, strict=[ k for k in kwargs if k != name ], _print=(name == 'organic' and False), **kwargs
     ), records(cur, col_idx_map))
 
 def show_or_exit(key):
@@ -520,7 +534,7 @@ class GroceryTransactionEditor(urwid.WidgetPlaceholder):
             name: value,
         })
         for k,v in self.data.items():
-            if k == name or v:
+            if k in NON_AUTOFILL_COLUMNS or k == name:
                 continue
             options = unique_suggestions(k, **self.data)
             if len(options) == 1 and k != 'ts':