Эх сурвалжийг харах

allow setting preffered unit in UI

Daniel Sheffield 1 жил өмнө
parent
commit
4701781dd3

+ 8 - 6
app/activities/NewProduct.py

@@ -41,10 +41,12 @@ class NewProduct(WidgetPlaceholder):
         title = Text('Enter Product Info', align='center')
         self.fields = OrderedDict()
         self.autocomplete_cb = lambda widget, options: len(options) and widget._emit('open', options)
-        for f in ('product', 'category', 'group'):
+        for f in ('product', 'category', 'group', 'unit'):
             w = AutoCompleteEdit(('bg', f))
             self.fields[f] = w
             w.set_edit_text(under.data[f])
+            if f == 'unit':
+                continue
             connect_signal(w, 'change', lambda w, v: under.apply_changes(w.name, v))
             connect_signal(w, 'apply', lambda _, name: self.autocomplete_cb(
                 _, query_manager.unique_suggestions(name, **self.data)
@@ -74,7 +76,7 @@ class NewProduct(WidgetPlaceholder):
             AttrMap(body, 'bg'),
             self.original_widget,
             align='center', width=('relative', 40),
-            valign='middle', height=13,
+            valign='middle', height=16,
             min_width=20)
 
     @property
@@ -89,13 +91,13 @@ class NewProduct(WidgetPlaceholder):
             self.fields[k].set_edit_text(v)
 
     def insert_new_product(self):
-        product, category, group = [ self.fields[k].get_edit_text() for k in (
-            'product', 'category', 'group'
+        product, category, group, unit = [ self.fields[k].get_edit_text() for k in (
+            'product', 'category', 'group', 'unit'
         )]
         self.activity_manager.app.log.write(
-            f'{get_insert_product_statement(product, category, group)};\n'
+            f'{get_insert_product_statement(product, category, group, unit)};\n'
         )
-        self.query_manager.insert_new_product(product, category, group)
+        self.query_manager.insert_new_product(product, category, group, unit)
         self.activity_manager.show(self.under.update())
 
     def apply_choice(self, name, value):

+ 5 - 4
app/data/QueryManager.py

@@ -116,8 +116,9 @@ def suggestions(cur, statement, name, display, exclude=NON_IDENTIFIER_COLUMNS, *
         x, strict=[ k for k in kwargs if k != name ], **kwargs
     ), get_data(cur, statement, display))
 
-def get_insert_product_statement(product, category, group):
-    return f'CALL insert_product($prod${product}$prod$, $category${category}$category$, $group${group}$group$)'
+def get_insert_product_statement(product, category, group, unit):
+    unit_sql = f', $unit${unit}$unit$' if unit else ''
+    return f'CALL insert_product($prod${product}$prod$, $category${category}$category$, $group${group}$group${unit_sql})'
 
 class QueryManager(object):
 
@@ -146,8 +147,8 @@ class QueryManager(object):
         statement = get_transactions_statement(name, **kwargs)
         return unique_suggestions(self.cursor, statement, name, self.display, **kwargs)
 
-    def insert_new_product(self, product, category, group):
-        self.cursor.execute(get_insert_product_statement(product, category, group))
+    def insert_new_product(self, product, category, group, unit):
+        self.cursor.execute(get_insert_product_statement(product, category, group, unit))
 
     def get_preferred_unit(self, product):
         self.cursor.execute(SQL("""SELECT