taler-android

Android apps for GNU Taler (wallet, PoS, cashier)
Log | Files | Refs | README | LICENSE

commit 06fe73f9d53a2bb8e94fce4490d2f40613d38066
parent 4dc5b0624153041349611715f3c92cc2d7d7ed87
Author: Iván Ávalos <avalos@disroot.org>
Date:   Thu,  5 Dec 2024 13:52:47 +0100

[pos] Gracefully handle products with invalid category IDs

Diffstat:
Mmerchant-terminal/src/main/java/net/taler/merchantpos/order/OrderManager.kt | 16++++++++++------
Mmerchant-terminal/src/main/res/values/strings.xml | 1+
2 files changed, 11 insertions(+), 6 deletions(-)

diff --git a/merchant-terminal/src/main/java/net/taler/merchantpos/order/OrderManager.kt b/merchant-terminal/src/main/java/net/taler/merchantpos/order/OrderManager.kt @@ -61,6 +61,7 @@ class OrderManager(private val context: Context) : ConfigurationReceiver { // group products by categories productsByCategory.clear() + val unknownCategory = Category(-1, context.getString(R.string.product_category_uncategorized)) posConfig.products.forEach { product -> val productCurrency = product.price.currency if (productCurrency != currency) { @@ -70,13 +71,11 @@ class OrderManager(private val context: Context) : ConfigurationReceiver { ) } product.categories.forEach { categoryId -> - val category = posConfig.categories.find { it.id == categoryId } - if (category == null) { + val category = posConfig.categories.find { it.id == categoryId } ?: let { Log.e(TAG, "Product $product has unknown category $categoryId") - return context.getString( - R.string.config_error_product_category_id, product.description, categoryId - ) + unknownCategory } + if (productsByCategory.containsKey(category)) { productsByCategory[category]?.add(product) } else { @@ -86,7 +85,12 @@ class OrderManager(private val context: Context) : ConfigurationReceiver { } return if (productsByCategory.size > 0) { this.currency = currency - mCategories.postValue(posConfig.categories) + mCategories.postValue(posConfig.categories + + if(productsByCategory.containsKey(unknownCategory)) { + listOf(unknownCategory) + } else { + emptyList() + }) mProducts.postValue(productsByCategory[posConfig.categories[0]]) orders.clear() orderCounter = 0 diff --git a/merchant-terminal/src/main/res/values/strings.xml b/merchant-terminal/src/main/res/values/strings.xml @@ -9,6 +9,7 @@ <string name="menu_reload">Reload</string> <string name="product_image">Product image</string> + <string name="product_category_uncategorized">Uncategorized</string> <string name="order_label_title">Order #%s</string> <!-- The placeholder is the total order amount with currency -->