Skip to content

Commit

Permalink
fix: missing shopping_location_id in rest request to add product stoc…
Browse files Browse the repository at this point in the history
…k in grocy
  • Loading branch information
salvadorbs committed Nov 27, 2023
1 parent be95d7c commit 7d5e1be
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
12 changes: 7 additions & 5 deletions library/grocy.productstock.pas
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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.
5 changes: 3 additions & 2 deletions library/kernel.application.pas
Original file line number Diff line number Diff line change
Expand Up @@ -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', []);
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -303,6 +303,7 @@ procedure TLidlToGrocy.DoRun;
end;

FConfiguration.LidlTickets.Add(LidlTicket.BarCode);
FConfiguration.SaveConfig;

TLogger.InfoExit('Completed processing', []);

Expand Down

0 comments on commit 7d5e1be

Please sign in to comment.