|
@@ -8,9 +8,9 @@
|
|
import time
|
|
import time
|
|
import itertools
|
|
import itertools
|
|
import sys
|
|
import sys
|
|
|
|
+from typing import Union
|
|
import urwid
|
|
import urwid
|
|
from app.db_utils import (
|
|
from app.db_utils import (
|
|
- NON_IDENTIFIER_COLUMNS,
|
|
|
|
QueryManager,
|
|
QueryManager,
|
|
get_insert_product_statement
|
|
get_insert_product_statement
|
|
)
|
|
)
|
|
@@ -20,6 +20,7 @@ from app.activities import (
|
|
)
|
|
)
|
|
from app.activities.TransactionEditor import TransactionEditor
|
|
from app.activities.TransactionEditor import TransactionEditor
|
|
from app.activities.NewProduct import NewProduct
|
|
from app.activities.NewProduct import NewProduct
|
|
|
|
+from app.widgets import AutoCompleteEdit, AutoCompleteFloatEdit
|
|
|
|
|
|
try:
|
|
try:
|
|
from db_credentials import HOST, PASSWORD
|
|
from db_credentials import HOST, PASSWORD
|
|
@@ -77,9 +78,12 @@ display_map = {
|
|
}
|
|
}
|
|
display = lambda data, name: display_map[name](data) if name in display_map else data
|
|
display = lambda data, name: display_map[name](data) if name in display_map else data
|
|
|
|
|
|
-def _apply_choice_callback(activity_manager, base, name, widget, value):
|
|
|
|
|
|
+def _apply_choice_callback(
|
|
|
|
+ activity_manager: ActivityManager,
|
|
|
|
+ base: str, name: str, value: str
|
|
|
|
+):
|
|
base = activity_manager.get(base)
|
|
base = activity_manager.get(base)
|
|
- base.apply_choice(name)(widget, value)
|
|
|
|
|
|
+ base.apply_choice(name, value)
|
|
activity_manager.show(base.update())
|
|
activity_manager.show(base.update())
|
|
|
|
|
|
def _insert_new_product_callback(activity_manager, query_manager, product, category, group):
|
|
def _insert_new_product_callback(activity_manager, query_manager, product, category, group):
|
|
@@ -98,26 +102,24 @@ def _new_product_callback(
|
|
activity_manager.show(
|
|
activity_manager.show(
|
|
activity_manager.create(NewProduct, 'new_product',
|
|
activity_manager.create(NewProduct, 'new_product',
|
|
query_manager, cur, name, txn.data,
|
|
query_manager, cur, name, txn.data,
|
|
- lambda t, open_pop_up_cb: _autocomplete_callback(activity_manager, query_manager, 'new_product', t, data, open_pop_up_cb),
|
|
|
|
|
|
+ lambda w, t, data: _autocomplete_callback(activity_manager, query_manager, w, t, data),
|
|
txn.apply_changes,
|
|
txn.apply_changes,
|
|
lambda product, category, group: _insert_new_product_callback(
|
|
lambda product, category, group: _insert_new_product_callback(
|
|
activity_manager, query_manager, product, category, group),
|
|
activity_manager, query_manager, product, category, group),
|
|
lambda: activity_manager.show(cur),
|
|
lambda: activity_manager.show(cur),
|
|
- lambda name, widget, value: _apply_choice_callback(activity_manager, 'new_product', name, widget, value)
|
|
|
|
|
|
+ lambda name, value: _apply_choice_callback(activity_manager, 'new_product', name, value)
|
|
)
|
|
)
|
|
)
|
|
)
|
|
|
|
|
|
def _autocomplete_callback(
|
|
def _autocomplete_callback(
|
|
activity_manager: ActivityManager,
|
|
activity_manager: ActivityManager,
|
|
query_manager: QueryManager,
|
|
query_manager: QueryManager,
|
|
- base: str,
|
|
|
|
- name: str, data: dict,
|
|
|
|
- open_pop_up_cb,
|
|
|
|
|
|
+ widget: Union[AutoCompleteEdit, AutoCompleteFloatEdit],
|
|
|
|
+ name: str, data: dict
|
|
):
|
|
):
|
|
options = query_manager.unique_suggestions(name, **data)
|
|
options = query_manager.unique_suggestions(name, **data)
|
|
if len(options) > 0:
|
|
if len(options) > 0:
|
|
- open_pop_up_cb(options)
|
|
|
|
-
|
|
|
|
|
|
+ widget._emit('open', options)
|
|
elif len(options) == 0 and activity_manager.current() is not activity_manager.get('new_product'):
|
|
elif len(options) == 0 and activity_manager.current() is not activity_manager.get('new_product'):
|
|
if name in ('product', 'category', 'group'):
|
|
if name in ('product', 'category', 'group'):
|
|
_new_product_callback(activity_manager, query_manager, name, data)
|
|
_new_product_callback(activity_manager, query_manager, name, data)
|
|
@@ -137,7 +139,7 @@ class GroceryTransactionEditor(urwid.WidgetPlaceholder):
|
|
super().__init__(urwid.SolidFill(u'/'))
|
|
super().__init__(urwid.SolidFill(u'/'))
|
|
self.activity_manager = activity_manager
|
|
self.activity_manager = activity_manager
|
|
self.cur = cur
|
|
self.cur = cur
|
|
- txn = self.activity_manager.get('transaction')
|
|
|
|
|
|
+ txn: TransactionEditor = self.activity_manager.get('transaction')
|
|
|
|
|
|
with open(log, 'r') as f:
|
|
with open(log, 'r') as f:
|
|
date = None
|
|
date = None
|
|
@@ -159,8 +161,8 @@ class GroceryTransactionEditor(urwid.WidgetPlaceholder):
|
|
self.cur.execute(line)
|
|
self.cur.execute(line)
|
|
|
|
|
|
if None not in (date, store):
|
|
if None not in (date, store):
|
|
- txn._apply_choice('ts', date)
|
|
|
|
- txn._apply_choice('store', store)
|
|
|
|
|
|
+ txn.apply_choice('ts', date)
|
|
|
|
+ txn.apply_choice('store', store)
|
|
|
|
|
|
self.activity_manager.show(self)
|
|
self.activity_manager.show(self)
|
|
self.activity_manager.show(txn.update())
|
|
self.activity_manager.show(txn.update())
|
|
@@ -204,8 +206,8 @@ query_manager = QueryManager(cur, display)
|
|
activity_manager.create(TransactionEditor, 'transaction',
|
|
activity_manager.create(TransactionEditor, 'transaction',
|
|
query_manager, cols, grid_layout, side_pane, bottom_pane,
|
|
query_manager, cols, grid_layout, side_pane, bottom_pane,
|
|
lambda: _save_and_clear_callback(activity_manager),
|
|
lambda: _save_and_clear_callback(activity_manager),
|
|
- lambda name, data, open_pop_up_cb: _autocomplete_callback(activity_manager, query_manager, 'transaction', name, data, open_pop_up_cb),
|
|
|
|
- lambda name, widget, value: _apply_choice_callback(activity_manager, 'transaction', name, widget, value))
|
|
|
|
|
|
+ lambda widget, name, data: _autocomplete_callback(activity_manager, query_manager, widget, name, data),
|
|
|
|
+ lambda name, value: _apply_choice_callback(activity_manager, 'transaction', name, value))
|
|
|
|
|
|
app = GroceryTransactionEditor(activity_manager, cur, log)
|
|
app = GroceryTransactionEditor(activity_manager, cur, log)
|
|
|
|
|