From 91157f970df4d1804285edd945015ee7fbefe02f Mon Sep 17 00:00:00 2001 From: Paul Brinkmeier Date: Tue, 14 May 2024 16:43:04 +0200 Subject: [PATCH] Improve entry flow a little --- frontend/Entry.elm | 48 +++++++++++++++++++++++------- jon/entry.py | 3 ++ jon/templates/entry/new-order.html | 5 +++- 3 files changed, 45 insertions(+), 11 deletions(-) diff --git a/frontend/Entry.elm b/frontend/Entry.elm index 55b7355..027a489 100644 --- a/frontend/Entry.elm +++ b/frontend/Entry.elm @@ -133,8 +133,11 @@ type alias Context = type alias Globals = { locations : List Location + , defaultLocation : Location , groups : List Group + , defaultGroup : Group , taxGroups : List TaxGroup + , defaultTaxGroup : TaxGroup } type State @@ -158,7 +161,7 @@ type Msg = SetSearchTerm String | SubmitSearch | ReceiveSearchResults (Result Http.Error (List SearchResult)) - | GotoItemEditor SearchResult + | GotoItemEditor IEInit | SetBarcode String | SetName String | SetSalesUnits String @@ -169,6 +172,10 @@ type Msg | SetLocation String | SetTaxGroup String +type IEInit + = IEInitBarcode String + | IEInitSearchResult SearchResult + -- Update logic: State machine etc. update msg { globals, state } = @@ -190,7 +197,21 @@ updateState msg globals state = case state of ) ReceiveSearchResults (Ok searchResults) -> (ItemSearch { model | searchResults = searchResults }, Cmd.none) - GotoItemEditor searchResult -> + GotoItemEditor (IEInitBarcode barcode) -> + ( ItemEditor + { barcode = barcode + , name = "" + , calculator = Calculator.init 0 + , netUnitPrice = NumberInput.fromFloat 0 + , grossUnitPrice = NumberInput.fromFloat 0 + , salesUnits = NumberInput.fromInt 0 + , group = Select.init (.id >> String.fromInt) (.name) globals.defaultGroup globals.groups + , location = Select.init (.id >> String.fromInt) (.name) globals.defaultLocation globals.locations + , taxGroup = Select.init (.id >> String.fromInt) (.description) globals.defaultTaxGroup globals.taxGroups + } + , Cmd.none + ) + GotoItemEditor (IEInitSearchResult searchResult) -> case find (\tg -> tg.id == searchResult.taxGroupId) globals.taxGroups of Nothing -> (state, Cmd.none) Just taxGroup -> @@ -245,14 +266,21 @@ suggestedGrossPrice netPrice percentage = view { globals, state } = case state of ItemSearch model -> - fieldset [] - [ legend [] [ text "Vorlage für Auftrag wählen" ] - , Html.form [ onSubmit SubmitSearch ] - [ div [ class "form-input" ] - [ label [ for "search-term", title "Barcode oder Name" ] [ text "Suchbegriff" ] - , input [ onInput SetSearchTerm, value model.searchTerm, id "search-term" ] [] + div [] + [ div [] + [ if model.searchTerm == "" + then button [ disabled True ] [ text "Neuer Artikel" ] + else button [ onClick <| GotoItemEditor <| IEInitBarcode model.searchTerm ] [ text <| "Neuer Artikel mit Barcode " ++ model.searchTerm ] + ] + , fieldset [] + [ legend [] [ text "Vorlage für Auftrag wählen" ] + , Html.form [ onSubmit SubmitSearch ] + [ div [ class "form-input" ] + [ label [ for "search-term", title "Barcode oder Name" ] [ text "Suchbegriff" ] + , input [ onInput SetSearchTerm, value model.searchTerm, id "search-term" ] [] + ] + , table [] <| searchResultHeaders :: List.map viewSearchResult model.searchResults ] - , table [] <| searchResultHeaders :: List.map viewSearchResult model.searchResults ] ] ItemEditor model -> @@ -385,7 +413,7 @@ viewSearchResult model = , td [] [ text model.locationName ] , td [] [ text <| showBool model.available ] , td [] - [ Html.form [ onSubmit <| GotoItemEditor model ] + [ Html.form [ onSubmit <| GotoItemEditor <| IEInitSearchResult model ] [ button [] [ text "Als Vorlage verwenden" ] ] ] diff --git a/jon/entry.py b/jon/entry.py index 733f8f0..fc1de2c 100644 --- a/jon/entry.py +++ b/jon/entry.py @@ -94,10 +94,13 @@ def new_order(): with db.run_query("entry/get_tax_groups.sql") as cursor: tax_groups = cursor.fetchall() + selected_location = current_user.data.location + return render_template( "entry/new-order.html", groups=groups, locations=locations, + default_location=next(location for location in locations if location["id"] == selected_location["location_id"]) if selected_location is not None else locations[0], tax_groups=tax_groups ) diff --git a/jon/templates/entry/new-order.html b/jon/templates/entry/new-order.html index b986866..7a935ae 100644 --- a/jon/templates/entry/new-order.html +++ b/jon/templates/entry/new-order.html @@ -8,8 +8,11 @@ Elm.Entry.init({ node: document.querySelector('.entry-app'), flags: { locations: {{ to_json(locations) | safe }}, + defaultLocation: {{ to_json(default_location) | safe }}, groups: {{ to_json(groups) | safe }}, - taxGroups: {{ to_json(tax_groups) | safe }} + defaultGroup: {{ to_json(groups[0]) | safe }}, + taxGroups: {{ to_json(tax_groups) | safe }}, + defaultTaxGroup: {{ to_json(tax_groups[0]) | safe }}, } });