Browse Source

fix organic checkbox state

Daniel Sheffield 2 years ago
parent
commit
6f3eb3bcc3
2 changed files with 9 additions and 11 deletions
  1. 3 6
      app/activities/TransactionEditor.py
  2. 6 5
      app/db_utils.py

+ 3 - 6
app/activities/TransactionEditor.py

@@ -59,20 +59,17 @@ class TransactionEditor(FocusWidget):
             name: value if name != 'organic' else {
                 'yes': True, 'no': False,
                 True: True, False: False,
-                'mixed': False
+                'mixed': '',
             }[value],
         })
 
     def apply_organic_state(self, w, state):
-        self.data['organic'] = state if state != 'mixed' else False
+        self.data['organic'] = state if state != 'mixed' else ''
 
     def clear(self):
         for k in self.data:
             if k in ('ts', 'store',):
                 continue
-            if k == 'organic':
-                self.data[k] = False
-                continue
             self.data[k] = ''
 
         return self.update()
@@ -86,7 +83,7 @@ class TransactionEditor(FocusWidget):
                 date or None, store or None
             ) else ''
         )
-        self.organic_checkbox.set_state(self.data['organic'])
+        self.organic_checkbox.set_state(self.data['organic'] if self.data['organic'] != '' else 'mixed')
         return self
 
     def focus_on_product(self):

+ 6 - 5
app/db_utils.py

@@ -72,10 +72,10 @@ def record_matches(record, strict=None, **kwargs):
     ):
         if not query:
             continue
-        
+
         if key in strict and query != candidate:
             return False
-        
+
         for term in query.split():
             if term not in candidate:
                 return False
@@ -99,10 +99,11 @@ def unique_suggestions(cur, statement, name, display, exclude=NON_IDENTIFIER_COL
     }
     if len(ret) > 0 or name not in tables:
         return ret
-        
+
     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)))
+        get_data(cur, get_table_statement(name), display)))
+    ret = sorted(set(map(lambda x: x[name], items)))
+    return ret
 
 def suggestions(cur, statement, name, display, exclude=NON_IDENTIFIER_COLUMNS, **kwargs):
     exclude = filter(