Fix product card chart rendering error when there is no shopping location (references #658)

This commit is contained in:
Bernd Bestel 2020-03-25 19:49:10 +01:00
parent a45317aea1
commit c3d4be352d
No known key found for this signature in database
GPG Key ID: 71BD34C0D4891300
4 changed files with 11 additions and 3 deletions

View File

@ -3767,7 +3767,7 @@
"format": "number" "format": "number"
}, },
"shopping_location": { "shopping_location": {
"type": "string" "$ref": "#/components/schemas/ShoppingLocation"
} }
} }
}, },

View File

@ -1762,3 +1762,6 @@ msgstr ""
msgid "Group ingredients by their product group" msgid "Group ingredients by their product group"
msgstr "" msgstr ""
msgid "Unknown shopping location"
msgstr ""

View File

@ -122,7 +122,12 @@ Grocy.Components.ProductCard.Refresh = function(productId)
var chart = Grocy.Components.ProductCard.PriceHistoryChart.data; var chart = Grocy.Components.ProductCard.PriceHistoryChart.data;
priceHistoryDataPoints.forEach((dataPoint) => priceHistoryDataPoints.forEach((dataPoint) =>
{ {
var key = dataPoint.shopping_location || "empty"; var key = __t("Unknown shopping location");
if (dataPoint.shopping_location)
{
key = dataPoint.shopping_location.name
}
if (!datasets[key]) { if (!datasets[key]) {
datasets[key] = [] datasets[key] = []
} }

View File

@ -178,7 +178,7 @@ class StockService extends BaseService
$returnData[] = array( $returnData[] = array(
'date' => $row->purchased_date, 'date' => $row->purchased_date,
'price' => $row->price, 'price' => $row->price,
'shopping_location' => FindObjectInArrayByPropertyValue($shoppingLocations, 'id', $row->shopping_location_id)->name, 'shopping_location' => FindObjectInArrayByPropertyValue($shoppingLocations, 'id', $row->shopping_location_id),
); );
} }
return $returnData; return $returnData;