Skip to content

Commit

Permalink
Check if qu_conversion_factor_purchase_to_stock exists (deprecated AP…
Browse files Browse the repository at this point in the history
…I call) #241
  • Loading branch information
Forceu committed Jun 2, 2024
1 parent 854da32 commit 83449c3
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions incl/api.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,16 @@ public static function parseProductInfoStock(array $infoArray): GrocyProduct {
$result->name = sanitizeString($infoArray["product"]["name"]);
$result->isTare = ($infoArray["product"]["enable_tare_weight_handling"] == "1");
$result->tareWeight = sanitizeString($infoArray["product"]["tare_weight"]);
$result->quFactor = sanitizeString($infoArray["product"]["qu_conversion_factor_purchase_to_stock"]);
$result->defaultBestBeforeDays = $infoArray["product"]["default_best_before_days"];
$result->creationDate = $infoArray["product"]["row_created_timestamp"];
$result->unit = sanitizeString($infoArray["quantity_unit_stock"]["name"]);
$result->barcodes = $infoArray["product_barcodes"];

if (isset($infoArray["product"]["qu_conversion_factor_purchase_to_stock"]))
$result->quFactor = sanitizeString($infoArray["product"]["qu_conversion_factor_purchase_to_stock"]);
else
$result->quFactor = 1;

if (sanitizeString($infoArray["stock_amount"]) != null)
$result->stockAmount = sanitizeString($infoArray["stock_amount"]);
return $result;
Expand Down Expand Up @@ -336,7 +340,7 @@ public static function getGrocyVersion(): ?string {
*/
public static function purchaseProduct(int $id, float $amount, string $bestbefore = null, string $price = null, LockGenerator &$fileLock = null, string $defaultBestBefore = null): bool {
$data = array(
'amount' => $amount,
'amount' => $amount,
'transaction_type' => 'purchase'
);

Expand Down Expand Up @@ -381,7 +385,7 @@ public static function purchaseProduct(int $id, float $amount, string $bestbefor
*/
public static function removeFromShoppinglist(int $productid, float $amount): void {
$data = json_encode(array(
'product_id' => $productid,
'product_id' => $productid,
'product_amount' => $amount
));
$url = API_SHOPPINGLIST . "remove-product";
Expand All @@ -405,7 +409,7 @@ public static function removeFromShoppinglist(int $productid, float $amount): vo
*/
public static function addToShoppinglist(int $productid, float $amount): void {
$data = json_encode(array(
'product_id' => $productid,
'product_id' => $productid,
'product_amount' => $amount
));
$url = API_SHOPPINGLIST . "add-product";
Expand Down Expand Up @@ -433,9 +437,9 @@ public static function consumeProduct(int $id, float $amount, bool $spoiled = fa
return;

$data = json_encode(array(
'amount' => $amount,
'amount' => $amount,
'transaction_type' => 'consume',
'spoiled' => $spoiled
'spoiled' => $spoiled
));

$url = API_STOCK . "/" . $id . "/consume";
Expand Down Expand Up @@ -465,8 +469,8 @@ public static function addBarcode(int $id, string $barcode, ?string $note): void

$data = json_encode(array(
"product_id" => $id,
"barcode" => $barcode,
"note" => $note
"barcode" => $barcode,
"note" => $note
));

$curl = new CurlGenerator(API_O_BARCODES, METHOD_POST, $data);
Expand Down Expand Up @@ -713,7 +717,7 @@ public static function executeChore(int $choreId): void {
$url = API_CHORE_EXECUTE . $choreId . "/execute";
$data = json_encode(array(
'tracked_time' => "",
'done_by' => ""
'done_by' => ""
));


Expand Down

0 comments on commit 83449c3

Please sign in to comment.