From bfa76fdc0a5047f7d2531edb9d8fc2ec269cd3bc Mon Sep 17 00:00:00 2001 From: Torsten Grote Date: Tue, 3 Mar 2020 17:02:50 -0300 Subject: Stop caring about product_id and use our own unique IDs --- .../net/taler/merchantpos/order/Definitions.kt | 37 ++++++++-------------- 1 file changed, 13 insertions(+), 24 deletions(-) diff --git a/app/src/main/java/net/taler/merchantpos/order/Definitions.kt b/app/src/main/java/net/taler/merchantpos/order/Definitions.kt index 1e6e37b..269b74a 100644 --- a/app/src/main/java/net/taler/merchantpos/order/Definitions.kt +++ b/app/src/main/java/net/taler/merchantpos/order/Definitions.kt @@ -21,11 +21,15 @@ data class Category( val localizedName: String get() = getLocalizedString(nameI18n, name) } +@JsonInclude(NON_NULL) abstract class Product { - abstract val id: String + @get:JsonProperty("product_id") + abstract val productId: String? abstract val description: String + @get:JsonProperty("description_i18n") abstract val descriptionI18n: Map? abstract val price: String + @get:JsonProperty("delivery_location") abstract val location: String? @get:JsonIgnore val localizedDescription: String @@ -33,13 +37,12 @@ abstract class Product { } data class ConfigProduct( - @JsonProperty("product_id") - override val id: String, + @JsonIgnore + val id: String = UUID.randomUUID().toString(), + override val productId: String?, override val description: String, - @JsonProperty("description_i18n") override val descriptionI18n: Map?, override val price: String, - @JsonProperty("delivery_location") override val location: String?, val categories: List, @JsonIgnore @@ -47,34 +50,20 @@ data class ConfigProduct( ) : Product() { val priceAsDouble by lazy { Amount.fromString(price).amount.toDouble() } - override fun equals(other: Any?): Boolean { - return other is ConfigProduct && id == other.id - } - - override fun hashCode(): Int { - var result = id.hashCode() - result = 31 * result + description.hashCode() - result = 31 * result + price.hashCode() - result = 31 * result + (location?.hashCode() ?: 0) - result = 31 * result + categories.hashCode() - return result - } + override fun equals(other: Any?) = other is ConfigProduct && id == other.id + override fun hashCode() = id.hashCode() } data class ContractProduct( - @JsonProperty("product_id") - override val id: String, + override val productId: String?, override val description: String, - @JsonInclude(NON_NULL) - @JsonProperty("description_i18n") override val descriptionI18n: Map?, override val price: String, - @JsonProperty("delivery_location") override val location: String?, val quantity: Int ) : Product() { constructor(product: ConfigProduct) : this( - product.id, + product.productId, product.description, product.descriptionI18n, product.price, @@ -112,7 +101,7 @@ data class Order(val id: Int, val availableCategories: Map) { val title: String = id.toString() val summary: String get() = getCategoryQuantities().map { (category: Category, quantity: Int) -> - "$quantity x ${category.localizedName}" + "$quantity x ${category.localizedName}" }.joinToString() val total: Double get() { -- cgit v1.2.3