From 7d5e1bebe99494d032f3844195cb6ecc43b04acd Mon Sep 17 00:00:00 2001 From: Matteo Salvi Date: Tue, 28 Nov 2023 00:43:05 +0100 Subject: [PATCH] fix: missing shopping_location_id in rest request to add product stock in grocy --- library/grocy.productstock.pas | 12 +++++++----- library/kernel.application.pas | 5 +++-- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/library/grocy.productstock.pas b/library/grocy.productstock.pas index 2a82a40..c1afcbf 100644 --- a/library/grocy.productstock.pas +++ b/library/grocy.productstock.pas @@ -17,15 +17,17 @@ TGrocyProductStock = class(TSynAutoCreateFields) FBestBeforeDate: TDateTime; FPrice: string; FPurchasedDate: TDateTime; + FShoppingLocationId: string; FTransactionType: string; public constructor Create(Amount: string; BestBeforeDate: TDateTime; Price: string; - TransactionType: string; PurchasedDate: TDateTime); overload; + TransactionType: string; PurchasedDate: TDateTime; ShoppingLocationId: string); overload; published property Amount: string read FAmount write FAmount; property BestBeforeDate: TDateTime read FBestBeforeDate write FBestBeforeDate; property Price: string read FPrice write FPrice; property PurchasedDate: TDateTime read FPurchasedDate write FPurchasedDate; + property ShoppingLocationId: string read FShoppingLocationId write FShoppingLocationId; property TransactionType: string read FTransactionType write FTransactionType; end; @@ -34,20 +36,20 @@ implementation { TGrocyProductStock } constructor TGrocyProductStock.Create(Amount: string; BestBeforeDate: TDateTime; Price: string; - TransactionType: string; PurchasedDate: TDateTime); + TransactionType: string; PurchasedDate: TDateTime; ShoppingLocationId: string); begin inherited Create; FAmount := Amount; FBestBeforeDate := Trunc(BestBeforeDate); FPrice := StringReplace(Price, ',', '.', [rfReplaceAll]); - ; + FShoppingLocationId := ShoppingLocationId; FTransactionType := TransactionType; FPurchasedDate := Trunc(PurchasedDate); end; initialization Rtti.ByTypeInfo[TypeInfo(TGrocyProductStock)].Props.NameChanges( - ['Amount', 'BestBeforeDate', 'Price', 'PurchasedDate', 'TransactionType'], - ['amount', 'best_before_date', 'price', 'purchased_date', 'transaction_type']); + ['Amount', 'BestBeforeDate', 'Price', 'PurchasedDate', 'ShoppingLocationId', 'TransactionType'], + ['amount', 'best_before_date', 'price', 'purchased_date', 'shopping_location_id', 'transaction_type']); end. diff --git a/library/kernel.application.pas b/library/kernel.application.pas index 5719b05..ab5cfd4 100644 --- a/library/kernel.application.pas +++ b/library/kernel.application.pas @@ -183,7 +183,7 @@ procedure TLidlToGrocy.AddGrocyProductInStock(const LidlProduct: TItemsLine; TLogger.Info('Adding quantity (%s) in Grocy', [LidlProduct.Quantity]); GrocyProductStock := TGrocyProductStock.Create(LidlProduct.Quantity, IncDay(LidlTicket.Date, FConfiguration.GrocyDefaultBestBeforeDays), LidlProduct.CurrentUnitPrice, - 'purchase', LidlTicket.Date); + 'purchase', LidlTicket.Date, IntToStr(FConfiguration.GrocyShoppingLocationId)); try if not FGrocyService.AddProductInStock(GrocyProduct.Id, GrocyProductStock) then TLogger.Error('Error adding quantity to product in Grocy', []); @@ -222,7 +222,7 @@ function TLidlToGrocy.GetOFFProductInfo(var LidlProduct: TItemsLine): TOFFProduc try OFFProductInfo := TOpenFoodFactsService.GetProduct(LidlProduct.CodeInput); except - TLogger.Error('Failed OpenFoodFacts api call', []); + TLogger.Error('Product not found in OpenFoodFacts', []); end; end; @@ -303,6 +303,7 @@ procedure TLidlToGrocy.DoRun; end; FConfiguration.LidlTickets.Add(LidlTicket.BarCode); + FConfiguration.SaveConfig; TLogger.InfoExit('Completed processing', []);