mirror of
https://github.com/grocy/grocy.git
synced 2025-04-29 01:32:38 +00:00
421 (#507)
* refactor to be stock/entry/{entryId} * Allow recipeform add productworkflow * on document ready stockdetail filter based on ProductPicker * openDate fixes for undo * RefreshStockDetailRow refresh location-id
This commit is contained in:
parent
101355cae2
commit
ef9f28d154
@ -124,11 +124,6 @@ class StockApiController extends BaseApiController
|
||||
throw new \Exception('Request body could not be parsed (probably invalid JSON format or missing/wrong Content-Type header)');
|
||||
}
|
||||
|
||||
if (!array_key_exists('id', $requestBody))
|
||||
{
|
||||
throw new \Exception('A stock row id is required');
|
||||
}
|
||||
|
||||
if (!array_key_exists('amount', $requestBody))
|
||||
{
|
||||
throw new \Exception('An amount is required');
|
||||
@ -152,7 +147,7 @@ class StockApiController extends BaseApiController
|
||||
$locationId = $requestBody['location_id'];
|
||||
}
|
||||
|
||||
$bookingId = $this->StockService->EditStockEntry($requestBody['id'], $requestBody['amount'], $bestBeforeDate, $locationId, $price, $requestBody['open']);
|
||||
$bookingId = $this->StockService->EditStockEntry($args['entryId'], $requestBody['amount'], $bestBeforeDate, $locationId, $price, $requestBody['open']);
|
||||
return $this->ApiResponse($this->Database->stock_log($bookingId));
|
||||
}
|
||||
catch (\Exception $ex)
|
||||
|
@ -1050,86 +1050,9 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"put": {
|
||||
"summary": "Edits the stock entry",
|
||||
"tags": [
|
||||
"Stock"
|
||||
],
|
||||
"requestBody": {
|
||||
"required": true,
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "number",
|
||||
"format": "number",
|
||||
"description": "The stock table id"
|
||||
},
|
||||
"amount": {
|
||||
"type": "number",
|
||||
"format": "number",
|
||||
"description": "The amount to add - please note that when tare weight handling for the product is enabled, this needs to be the amount including the container weight (gross), the amount to be posted will be automatically calculated based on what is in stock and the defined tare weight"
|
||||
},
|
||||
"best_before_date": {
|
||||
"type": "string",
|
||||
"format": "date",
|
||||
"description": "The best before date of the product to add, when omitted, the current date is used"
|
||||
},
|
||||
"location_id": {
|
||||
"type": "number",
|
||||
"format": "integer",
|
||||
"description": "If omitted, the default location of the product is used"
|
||||
},
|
||||
"price": {
|
||||
"type": "number",
|
||||
"format": "number",
|
||||
"description": "The price per purchase quantity unit in configured currency"
|
||||
},
|
||||
"open": {
|
||||
"type": "boolean",
|
||||
"description": "If the stock entry was already opened or not"
|
||||
}
|
||||
},
|
||||
"example": {
|
||||
"id": 2,
|
||||
"amount": 1,
|
||||
"best_before_date": "2019-01-19",
|
||||
"location_id": 2,
|
||||
"price": "1.99",
|
||||
"open": false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "The operation was successful",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/StockLogEntry"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"400": {
|
||||
"description": "The operation was not successful (possible errors are: Not existing product, invalid transaction type)",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/GenericErrorResponse"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/stock/{entryId}/entry": {
|
||||
"/stock/entry/{entryId}": {
|
||||
"get": {
|
||||
"summary": "Returns details of the given stock",
|
||||
"tags": [
|
||||
@ -1168,6 +1091,90 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"put": {
|
||||
"summary": "Edits the stock entry",
|
||||
"tags": [
|
||||
"Stock"
|
||||
],
|
||||
"parameters": [
|
||||
{
|
||||
"in": "path",
|
||||
"name": "entryId",
|
||||
"required": true,
|
||||
"description": "A valid stock row id",
|
||||
"schema": {
|
||||
"type": "integer"
|
||||
}
|
||||
}
|
||||
],
|
||||
"requestBody": {
|
||||
"required": true,
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"amount": {
|
||||
"type": "number",
|
||||
"format": "number",
|
||||
"description": "The amount to add - please note that when tare weight handling for the product is enabled, this needs to be the amount including the container weight (gross), the amount to be posted will be automatically calculated based on what is in stock and the defined tare weight"
|
||||
},
|
||||
"best_before_date": {
|
||||
"type": "string",
|
||||
"format": "date",
|
||||
"description": "The best before date of the product to add, when omitted, the current date is used"
|
||||
},
|
||||
"price": {
|
||||
"type": "number",
|
||||
"format": "number",
|
||||
"description": "The price per purchase quantity unit in configured currency"
|
||||
},
|
||||
"open": {
|
||||
"type": "boolean",
|
||||
"description": "If the stock entry was already opened or not"
|
||||
},
|
||||
"location_id": {
|
||||
"type": "number",
|
||||
"format": "integer",
|
||||
"description": "If omitted, the default location of the product is used"
|
||||
}
|
||||
},
|
||||
"example": {
|
||||
"id": "2",
|
||||
"amount": "1",
|
||||
"best_before_date": "2021-07-19",
|
||||
"purchased_date": "2020-01-01",
|
||||
"price": "22.03",
|
||||
"open": false,
|
||||
"location_id": "4"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "The operation was successful",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/StockEntry"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"400": {
|
||||
"description": "The operation was not successful (possible errors are: Not existing product, invalid transaction type)",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/GenericErrorResponse"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/stock/volatile": {
|
||||
|
@ -19,7 +19,6 @@ $.fn.dataTable.ext.search.push(function(settings, data, dataIndex)
|
||||
return false;
|
||||
});
|
||||
|
||||
Grocy.Components.ProductPicker.GetPicker().trigger('change');
|
||||
|
||||
Grocy.Components.ProductPicker.GetPicker().on('change', function(e)
|
||||
{
|
||||
@ -116,7 +115,7 @@ $(document).on("click", ".stock-name-cell", function(e)
|
||||
|
||||
function RefreshStockDetailRow(stockRowId)
|
||||
{
|
||||
Grocy.Api.Get("stock/" + stockRowId + "/entry",
|
||||
Grocy.Api.Get("stock/entry/" + stockRowId,
|
||||
function(result)
|
||||
{
|
||||
var stockRow = $('#stock-' + stockRowId + '-row');
|
||||
@ -161,6 +160,8 @@ function RefreshStockDetailRow(stockRowId)
|
||||
});
|
||||
$('#stock-' + stockRowId + '-best-before-date-timeago').attr('datetime', result.best_before_date + ' 23:59:59');
|
||||
|
||||
$(".stock-consume-button").attr('data-location-id',result.location_id);
|
||||
|
||||
var locationName = "";
|
||||
Grocy.Api.Get("objects/locations/" + result.location_id,
|
||||
function(locationResult)
|
||||
@ -175,6 +176,7 @@ function RefreshStockDetailRow(stockRowId)
|
||||
$('#stock-' + stockRowId + '-location').parent().effect('highlight', { }, 500);
|
||||
$('#stock-' + stockRowId + '-location').fadeOut(500, function()
|
||||
{
|
||||
$(this).attr('data-location-id',result.location_id);
|
||||
$(this).text(locationName).fadeIn(500);
|
||||
});
|
||||
|
||||
@ -231,6 +233,8 @@ $(window).on("message", function(e)
|
||||
}
|
||||
});
|
||||
|
||||
Grocy.Components.ProductPicker.GetPicker().trigger('change');
|
||||
|
||||
function UndoStockBookingEntry(bookingId, stockRowId)
|
||||
{
|
||||
Grocy.Api.Post('stock/bookings/' + bookingId.toString() + '/undo', { },
|
||||
|
@ -26,9 +26,8 @@
|
||||
jsonData.open = $("#open").is(":checked");
|
||||
|
||||
var stockRowId = GetUriParam('stockRowId');
|
||||
jsonData.id = stockRowId;
|
||||
|
||||
Grocy.Api.Put("stock", jsonData,
|
||||
Grocy.Api.Put("stock/entry/" + stockRowId, jsonData,
|
||||
function(result)
|
||||
{
|
||||
var successMessage = __t('Stock entry successfully updated') + '<br><a class="btn btn-secondary btn-sm mt-2" href="#" onclick="UndoStockBookingEntry(\'' + result.id + '\',\'' + stockRowId + '\')"><i class="fas fa-undo"></i> ' + __t("Undo") + '</a>';
|
||||
@ -84,7 +83,7 @@ if (Grocy.Components.DateTimePicker)
|
||||
}
|
||||
|
||||
var stockRowId = GetUriParam('stockRowId');
|
||||
Grocy.Api.Get("stock/" + stockRowId + "/entry",
|
||||
Grocy.Api.Get("stock/entry/" + stockRowId,
|
||||
function (stockEntry)
|
||||
{
|
||||
Grocy.Components.LocationPicker.SetId(stockEntry.location_id);
|
||||
|
@ -161,8 +161,8 @@ $app->group('/api', function()
|
||||
if (GROCY_FEATURE_FLAG_STOCK)
|
||||
{
|
||||
$this->get('/stock', '\Grocy\Controllers\StockApiController:CurrentStock');
|
||||
$this->get('/stock/{entryId}/entry', '\Grocy\Controllers\StockApiController:StockEntry');
|
||||
$this->put('/stock', '\Grocy\Controllers\StockApiController:EditStockEntry');
|
||||
$this->get('/stock/entry/{entryId}', '\Grocy\Controllers\StockApiController:StockEntry');
|
||||
$this->put('/stock/entry/{entryId}', '\Grocy\Controllers\StockApiController:EditStockEntry');
|
||||
$this->get('/stock/volatile', '\Grocy\Controllers\StockApiController:CurrentVolatileStock');
|
||||
$this->get('/stock/products/{productId}', '\Grocy\Controllers\StockApiController:ProductDetails');
|
||||
$this->get('/stock/products/{productId}/entries', '\Grocy\Controllers\StockApiController:ProductStockEntries');
|
||||
|
@ -591,11 +591,19 @@ class StockService extends BaseService
|
||||
));
|
||||
$logOldRowForStockUpdate->save();
|
||||
|
||||
$openDate = $stockRow->opened_date;
|
||||
if ($open && $openDate == null) {
|
||||
$openDate = date('Y-m-d');
|
||||
} else if (!$open) {
|
||||
$openDate = null;
|
||||
}
|
||||
|
||||
$stockRow->update(array(
|
||||
'amount' => $amount,
|
||||
'price' => $price,
|
||||
'best_before_date' => $bestBeforeDate,
|
||||
'location_id' => $locationId,
|
||||
'opened_date' => $openDate,
|
||||
'open' => $open
|
||||
));
|
||||
|
||||
@ -1071,12 +1079,20 @@ class StockService extends BaseService
|
||||
throw new \Exception('Booking does not exist or was already undone');
|
||||
}
|
||||
|
||||
$openDate = $logRow->opened_date;
|
||||
$open = true;
|
||||
if ($openDate == null) {
|
||||
$open = false;
|
||||
}
|
||||
|
||||
$stockRow->update(array(
|
||||
'amount' => $logRow->amount,
|
||||
'best_before_date' => $logRow->best_before_date,
|
||||
'purchased_date' => $logRow->purchased_date,
|
||||
'price' => $logRow->price,
|
||||
'location_id' => $logRow->location_id
|
||||
'location_id' => $logRow->location_id,
|
||||
'open' => $open,
|
||||
'opened_date' => $openDate
|
||||
));
|
||||
|
||||
// Update log entry
|
||||
|
@ -88,7 +88,6 @@
|
||||
'isRequired' => false,
|
||||
'label' => 'Produces product',
|
||||
'prefillById' => $recipe->product_id,
|
||||
'disallowAllProductWorkflows' => true,
|
||||
'hint' => $__t('When a product is selected, one unit (per serving in purchase quantity unit) will be added to stock on consuming this recipe')
|
||||
))
|
||||
|
||||
|
@ -64,10 +64,10 @@
|
||||
data-stockrow-id="{{ $currentStockEntry->id }}">
|
||||
<i class="fas fa-box-open"></i>
|
||||
</a>
|
||||
@endif
|
||||
<a class="btn btn-info btn-sm show-as-dialog-link" href="{{ $U('/stockedit?embedded&product=' . $currentStockEntry->product_id . '&stockRowId=' . $currentStockEntry->id) }}" data-toggle="tooltip" data-placement="left" title="{{ $__t('Edit stock entry') }}">
|
||||
<i class="fas fa-edit"></i>
|
||||
</a>
|
||||
@endif
|
||||
<div class="dropdown d-inline-block">
|
||||
<button class="btn btn-sm btn-light text-secondary" type="button" data-toggle="dropdown">
|
||||
<i class="fas fa-ellipsis-v"></i>
|
||||
|
Loading…
x
Reference in New Issue
Block a user