Improve entry flow a little

This commit is contained in:
Paul Brinkmeier 2024-05-14 16:43:04 +02:00
parent 63ffd98ae8
commit 91157f970d
3 changed files with 45 additions and 11 deletions

View File

@ -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" ]
]
]

View File

@ -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
)

View File

@ -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 }},
}
});
</script>