|
@@ -240,14 +240,18 @@ class TransactionEditor(FocusWidget):
|
|
|
def update_historic_prices(self, data):
|
|
|
organic = None if data['organic'] == 'mixed' else data['organic']
|
|
|
#sort = '$/unit' if self.buttons['sort_price'].state else 'ts'
|
|
|
- product, unit = data['product'] or None, data['unit'] or None
|
|
|
+ product = data['product'] or None
|
|
|
+ unit = self.query_manager.get_preferred_unit(data['product']) or data['unit'] or 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)
|
|
|
return
|
|
|
|
|
|
+ if quantity is not None:
|
|
|
+ factor = self.query_manager.convert_unit(product, data['unit'], unit)
|
|
|
+ quantity = quantity * factor if factor is not None else None
|
|
|
+
|
|
|
df = self.query_manager.get_historic_prices_data(unit, product=product, organic=organic, sort='ts').dropna()
|
|
|
if df.empty:
|
|
|
self.rating.update_rating(None, None, None, unit)
|