Просмотр исходного кода

update txn creation to include tags

Daniel Sheffield 2 лет назад
Родитель
Сommit
0be0dfd15b
1 измененных файлов с 5 добавлено и 1 удалено
  1. 5 1
      grocery_transactions.py

+ 5 - 1
grocery_transactions.py

@@ -92,10 +92,14 @@ class GroceryTransactionEditor(WidgetPlaceholder):
         price = data['price']
         product = data['product']
         organic = 'true' if data['organic'] is True else 'false'
+        tags = ', '.join([
+            f'$quot${v}$quot$' for t,v in data.items() if 'tags' in t
+        ])
+        tags = f", ARRAY[{tags}]" if tags else ''
         statement = \
             f"CALL insert_transaction('{ts}', $store${store}$store$, " \
             f"$descr${description}$descr$, {quantity}, $unit${unit}$unit$, " \
-            f"{price}, $produ${product}$produ$, {organic});\n"
+            f"{price}, $produ${product}$produ$, {organic}{tags});\n"
         self.log.write(statement)
         self.log.flush()
         self.cur.execute(statement)