summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTorsten Grote <t@grobox.de>2020-03-03 17:02:50 -0300
committerTorsten Grote <t@grobox.de>2020-03-03 17:02:50 -0300
commitbfa76fdc0a5047f7d2531edb9d8fc2ec269cd3bc (patch)
tree55348b7d7220039a59c4c5ed9396106542043392
parent5cfc6b55bc8e140bdb290490733aa3ecbbba7a38 (diff)
downloadmerchant-terminal-android-bfa76fdc0a5047f7d2531edb9d8fc2ec269cd3bc.tar.gz
merchant-terminal-android-bfa76fdc0a5047f7d2531edb9d8fc2ec269cd3bc.tar.bz2
merchant-terminal-android-bfa76fdc0a5047f7d2531edb9d8fc2ec269cd3bc.zip
Stop caring about product_id and use our own unique IDs
-rw-r--r--app/src/main/java/net/taler/merchantpos/order/Definitions.kt37
1 files 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<String, String>?
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<String, String>?,
override val price: String,
- @JsonProperty("delivery_location")
override val location: String?,
val categories: List<Int>,
@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<String, String>?,
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<Int, Category>) {
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() {