Skip to content

Commit

Permalink
Very hopeful fix for #1
Browse files Browse the repository at this point in the history
  • Loading branch information
dominiczedler committed May 15, 2020
1 parent d5003ae commit 4e8a570
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class MissingItem {
private String name;

@SerializedName("amount_missing")
private double amountMissing;
private String amountMissing;

@SerializedName("is_partly_in_stock")
private int isPartlyInStock;
Expand All @@ -46,7 +46,11 @@ public String getName() {
}

public double getAmountMissing() {
return amountMissing;
if(amountMissing == null || amountMissing.isEmpty()) {
return 0;
} else {
return Double.parseDouble(amountMissing);
}
}

public int getIsPartlyInStock() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,16 @@ public class ProductDetails implements Parcelable {
private String lastUsed;

@SerializedName("stock_amount")
private double stockAmount;
private String stockAmount;

@SerializedName("stock_amount_opened")
private double stockAmountOpened;
private String stockAmountOpened;

@SerializedName("stock_amount_aggregated")
private double stockAmountAggregated;
private String stockAmountAggregated;

@SerializedName("stock_amount_opened_aggregated")
private double stockAmountOpenedAggregated;
private String stockAmountOpenedAggregated;

@SerializedName("quantity_unit_purchase")
private QuantityUnit quantityUnitPurchase;
Expand All @@ -68,7 +68,7 @@ public class ProductDetails implements Parcelable {
private int averageShelfLifeDays;

@SerializedName("spoil_rate_percent")
private double spoilRatePercent;
private String spoilRatePercent;

@SerializedName("is_aggregated_amount")
private int isAggregatedAmount;
Expand All @@ -77,17 +77,17 @@ public ProductDetails(Parcel parcel) {
product = parcel.readParcelable(Product.class.getClassLoader());
lastPurchased = parcel.readString();
lastUsed = parcel.readString();
stockAmount = parcel.readDouble();
stockAmountOpened = parcel.readDouble();
stockAmountAggregated = parcel.readDouble();
stockAmountOpenedAggregated = parcel.readDouble();
stockAmount = parcel.readString();
stockAmountOpened = parcel.readString();
stockAmountAggregated = parcel.readString();
stockAmountOpenedAggregated = parcel.readString();
quantityUnitPurchase = parcel.readParcelable(QuantityUnit.class.getClassLoader());
quantityUnitStock = parcel.readParcelable(QuantityUnit.class.getClassLoader());
lastPrice = parcel.readString();
nextBestBeforeDate = parcel.readString();
location = parcel.readParcelable(Location.class.getClassLoader());
averageShelfLifeDays = parcel.readInt();
spoilRatePercent = parcel.readDouble();
spoilRatePercent = parcel.readString();
isAggregatedAmount = parcel.readInt();
}

Expand All @@ -96,17 +96,17 @@ public void writeToParcel(Parcel dest, int flags) {
dest.writeParcelable(product, 0);
dest.writeString(lastPurchased);
dest.writeString(lastUsed);
dest.writeDouble(stockAmount);
dest.writeDouble(stockAmountOpened);
dest.writeDouble(stockAmountAggregated);
dest.writeDouble(stockAmountOpenedAggregated);
dest.writeString(stockAmount);
dest.writeString(stockAmountOpened);
dest.writeString(stockAmountAggregated);
dest.writeString(stockAmountOpenedAggregated);
dest.writeParcelable(quantityUnitPurchase, 0);
dest.writeParcelable(quantityUnitStock, 0);
dest.writeString(lastPrice);
dest.writeString(nextBestBeforeDate);
dest.writeParcelable(location, 0);
dest.writeInt(averageShelfLifeDays);
dest.writeDouble(spoilRatePercent);
dest.writeString(spoilRatePercent);
dest.writeInt(isAggregatedAmount);
}

Expand Down Expand Up @@ -136,19 +136,35 @@ public String getLastUsed() {
}

public double getStockAmount() {
return stockAmount;
if(stockAmount == null || stockAmount.isEmpty()) {
return 0;
} else {
return Double.parseDouble(stockAmount);
}
}

public double getStockAmountOpened() {
return stockAmountOpened;
if(stockAmountOpened == null || stockAmountOpened.isEmpty()) {
return 0;
} else {
return Double.parseDouble(stockAmountOpened);
}
}

public double getStockAmountAggregated() {
return stockAmountAggregated;
if(stockAmountAggregated == null || stockAmountAggregated.isEmpty()) {
return 0;
} else {
return Double.parseDouble(stockAmountAggregated);
}
}

public double getStockAmountOpenedAggregated() {
return stockAmountOpenedAggregated;
if(stockAmountOpenedAggregated == null || stockAmountOpenedAggregated.isEmpty()) {
return 0;
} else {
return Double.parseDouble(stockAmountOpenedAggregated);
}
}

public QuantityUnit getQuantityUnitPurchase() {
Expand Down Expand Up @@ -176,7 +192,11 @@ public int getAverageShelfLifeDays() {
}

public double getSpoilRatePercent() {
return spoilRatePercent;
if(spoilRatePercent == null || spoilRatePercent.isEmpty()) {
return 0;
} else {
return Double.parseDouble(spoilRatePercent);
}
}

public int getIsAggregatedAmount() {
Expand Down
56 changes: 36 additions & 20 deletions app/src/main/java/xyz/zedler/patrick/grocy/model/StockItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,19 @@
public class StockItem implements Parcelable {

@SerializedName("amount")
private double amount;
private String amount;

@SerializedName("amount_aggregated")
private double amountAggregated;
private String amountAggregated;

@SerializedName("best_before_date")
private String bestBeforeDate;

@SerializedName("amount_opened")
private double amountOpened;
private String amountOpened;

@SerializedName("amount_opened_aggregated")
private double amountOpenedAggregated;
private String amountOpenedAggregated;

@SerializedName("is_aggregated_amount")
private int isAggregatedAmount;
Expand All @@ -62,34 +62,34 @@ public StockItem(
int productId,
Product product
) {
this.amount = amount;
this.amountAggregated = amountAggregated;
this.amount = String.valueOf(amount);
this.amountAggregated = String.valueOf(amountAggregated);
this.bestBeforeDate = bestBeforeDate;
this.amountOpened = amountOpened;
this.amountOpenedAggregated = amountOpenedAggregated;
this.amountOpened = String.valueOf(amountOpened);
this.amountOpenedAggregated = String.valueOf(amountOpenedAggregated);
this.isAggregatedAmount = isAggregatedAmount;
this.productId = productId;
this.product = product;
}

private StockItem(Parcel parcel) {
amount = parcel.readDouble();
amountAggregated = parcel.readDouble();
amount = parcel.readString();
amountAggregated = parcel.readString();
bestBeforeDate = parcel.readString();
amountOpened = parcel.readDouble();
amountOpenedAggregated = parcel.readDouble();
amountOpened = parcel.readString();
amountOpenedAggregated = parcel.readString();
isAggregatedAmount = parcel.readInt();
productId = parcel.readInt();
product = parcel.readParcelable(Product.class.getClassLoader());
}

@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeDouble(amount);
dest.writeDouble(amountAggregated);
dest.writeString(amount);
dest.writeString(amountAggregated);
dest.writeString(bestBeforeDate);
dest.writeDouble(amountOpened);
dest.writeDouble(amountOpenedAggregated);
dest.writeString(amountOpened);
dest.writeString(amountOpenedAggregated);
dest.writeInt(isAggregatedAmount);
dest.writeInt(productId);
dest.writeParcelable(product, 0);
Expand All @@ -109,15 +109,23 @@ public StockItem[] newArray(int size) {
};

public double getAmountAggregated() {
return amountAggregated;
if(amountAggregated == null || amountAggregated.isEmpty()) {
return 0;
} else {
return Double.parseDouble(amountAggregated);
}
}

public String getBestBeforeDate() {
return bestBeforeDate;
}

public double getAmountOpenedAggregated() {
return amountOpenedAggregated;
if(amountOpenedAggregated == null || amountOpenedAggregated.isEmpty()) {
return 0;
} else {
return Double.parseDouble(amountOpenedAggregated);
}
}

public int getIsAggregatedAmount() {
Expand All @@ -133,11 +141,19 @@ public Product getProduct() {
}

public double getAmount() {
return amount;
if(amount == null || amount.isEmpty()) {
return 0;
} else {
return Double.parseDouble(amount);
}
}

public double getAmountOpened() {
return amountOpened;
if(amountOpened == null || amountOpened.isEmpty()) {
return 0;
} else {
return Double.parseDouble(amountOpened);
}
}

@Override
Expand Down

0 comments on commit 4e8a570

Please sign in to comment.