|
@@ -4,7 +4,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
-from decimal import Decimal, InvalidOperation
|
|
|
from itertools import chain
|
|
|
from typing import (
|
|
|
Union,
|
|
@@ -28,6 +27,7 @@ from urwid import (
|
|
|
Text,
|
|
|
)
|
|
|
|
|
|
+from ..data.decimal_util import decimal_or_none
|
|
|
from ..data.dataframe_util import get_caption, get_time_range, stats
|
|
|
from ..data.QueryManager import QueryManager
|
|
|
from .grouped_widget_util import (
|
|
@@ -241,15 +241,8 @@ class TransactionEditor(FocusWidget):
|
|
|
organic = None if data['organic'] == 'mixed' else data['organic']
|
|
|
|
|
|
product, unit = data['product'] or None, data['unit'] or None
|
|
|
- try:
|
|
|
- price = Decimal(data['price'])
|
|
|
- except InvalidOperation:
|
|
|
- price = None
|
|
|
-
|
|
|
- try:
|
|
|
- quantity = Decimal(data['quantity'])
|
|
|
- except InvalidOperation:
|
|
|
- quantity = None
|
|
|
+ price = decimal_or_none(data['price'])
|
|
|
+ quantity = decimal_or_none(data['quantity'])
|
|
|
|
|
|
if None in (product, unit):
|
|
|
self.rating.update_rating(None, None, None, unit)
|
|
@@ -346,26 +339,7 @@ class TransactionEditor(FocusWidget):
|
|
|
)))
|
|
|
self.organic_checkbox = self.checkboxes['organic']
|
|
|
connect_signal(self.organic_checkbox, 'postchange', lambda _,v: self.update())
|
|
|
- layout = [
|
|
|
- [ 'ts', 'store', ],
|
|
|
- [ 'organic', 'product', ],
|
|
|
- [ 'category', 'group', ],
|
|
|
- ]
|
|
|
- side_pane = [
|
|
|
- 'unit',
|
|
|
- 'quantity',
|
|
|
- 'price',
|
|
|
- ]
|
|
|
- bottom_pane = [
|
|
|
- 'description',
|
|
|
- 'dbview',
|
|
|
- ]
|
|
|
- badge = [
|
|
|
- 'rating',
|
|
|
- 'spread',
|
|
|
- 'marker',
|
|
|
- ]
|
|
|
-
|
|
|
+
|
|
|
_widgets = dict(chain(*list(map(lambda x: x.items(), [
|
|
|
self.edit_fields, self.text_fields, self.checkboxes
|
|
|
])
|
|
@@ -401,17 +375,15 @@ class TransactionEditor(FocusWidget):
|
|
|
'bottom_button_bar': Columns(
|
|
|
[(8, self.buttons['done']), Divider(), (9, self.buttons['clear'])]
|
|
|
),
|
|
|
- 'badge': Pile(map(
|
|
|
- lambda x: _widgets[x] if x is not None else Divider,
|
|
|
- badge
|
|
|
- )),
|
|
|
+ 'badge': Pile([
|
|
|
+ _widgets[x] for x in ['rating', 'spread', 'marker']
|
|
|
+ ]),
|
|
|
})
|
|
|
self.components.update({
|
|
|
'bottom_pane': Columns([
|
|
|
- Pile(map(
|
|
|
- lambda x: _widgets[x] if x is not None else Divider(),
|
|
|
- bottom_pane
|
|
|
- )),
|
|
|
+ Pile([
|
|
|
+ _widgets[x] for x in ['description', 'dbview']
|
|
|
+ ]),
|
|
|
(self.graph.total_width+2, Pile([
|
|
|
LineBox(
|
|
|
AttrMap(self.components['badge'], 'badge'),
|
|
@@ -440,21 +412,19 @@ class TransactionEditor(FocusWidget):
|
|
|
})
|
|
|
|
|
|
self.components['side_pane'] = (12, Pile([
|
|
|
- _widgets[r] if r is not None else Divider() for r in side_pane
|
|
|
+ _widgets[r] for r in ['unit', 'quantity', 'price']
|
|
|
]))
|
|
|
- self.components['main_pane'] = []
|
|
|
- for _, r in enumerate(layout):
|
|
|
- col = []
|
|
|
- for c in r:
|
|
|
- if c is not None:
|
|
|
- if c == 'organic':
|
|
|
- continue
|
|
|
- col.append(_widgets[c])
|
|
|
- else:
|
|
|
- col.append(Divider())
|
|
|
- self.components['main_pane'].append(Columns(col))
|
|
|
-
|
|
|
- self.components['main_pane'] = Pile(self.components['main_pane'])
|
|
|
+
|
|
|
+ self.components['main_pane'] = Pile([
|
|
|
+ Columns([
|
|
|
+ _widgets[c] for c in ['ts', 'store']
|
|
|
+ ]),
|
|
|
+ _widgets['product'],
|
|
|
+ Columns([
|
|
|
+ _widgets[c] for c in ['category', 'group']
|
|
|
+ ])
|
|
|
+ ])
|
|
|
+
|
|
|
self.add_tag()
|
|
|
|
|
|
widget = Pile([
|