mirror of
https://github.com/grocy/grocy.git
synced 2025-08-13 17:27:23 +00:00
Make it possible to provide a different location for added product during inventory (closes #183)
This commit is contained in:
@@ -171,7 +171,13 @@ class StockApiController extends BaseApiController
|
|||||||
$bestBeforeDate = $requestBody['best_before_date'];
|
$bestBeforeDate = $requestBody['best_before_date'];
|
||||||
}
|
}
|
||||||
|
|
||||||
$bookingId = $this->StockService->InventoryProduct($args['productId'], $requestBody['new_amount'], $bestBeforeDate);
|
$locationId = null;
|
||||||
|
if (array_key_exists('location_id', $requestBody) && is_numeric($requestBody['location_id']))
|
||||||
|
{
|
||||||
|
$locationId = $requestBody['location_id'];
|
||||||
|
}
|
||||||
|
|
||||||
|
$bookingId = $this->StockService->InventoryProduct($args['productId'], $requestBody['new_amount'], $bestBeforeDate, $locationId);
|
||||||
return $this->ApiResponse($this->Database->stock_log($bookingId));
|
return $this->ApiResponse($this->Database->stock_log($bookingId));
|
||||||
}
|
}
|
||||||
catch (\Exception $ex)
|
catch (\Exception $ex)
|
||||||
|
@@ -48,7 +48,8 @@ class StockController extends BaseController
|
|||||||
public function Inventory(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args)
|
public function Inventory(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args)
|
||||||
{
|
{
|
||||||
return $this->AppContainer->view->render($response, 'inventory', [
|
return $this->AppContainer->view->render($response, 'inventory', [
|
||||||
'products' => $this->Database->products()->orderBy('name')
|
'products' => $this->Database->products()->orderBy('name'),
|
||||||
|
'locations' => $this->Database->locations()->orderBy('name')
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1229,6 +1229,11 @@
|
|||||||
"type": "string",
|
"type": "string",
|
||||||
"format": "date",
|
"format": "date",
|
||||||
"description": "The best before date which applies to added products"
|
"description": "The best before date which applies to added products"
|
||||||
|
},
|
||||||
|
"location_id": {
|
||||||
|
"type": "number",
|
||||||
|
"format": "integer",
|
||||||
|
"description": "If omitted, the default location of the product is used (only applies to added products)"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -11,6 +11,7 @@
|
|||||||
var jsonData = { };
|
var jsonData = { };
|
||||||
jsonData.new_amount = jsonForm.new_amount;
|
jsonData.new_amount = jsonForm.new_amount;
|
||||||
jsonData.best_before_date = Grocy.Components.DateTimePicker.GetValue();
|
jsonData.best_before_date = Grocy.Components.DateTimePicker.GetValue();
|
||||||
|
jsonData.location_id = Grocy.Components.LocationPicker.GetValue();
|
||||||
|
|
||||||
Grocy.Api.Post('stock/products/' + jsonForm.product_id + '/inventory', jsonData,
|
Grocy.Api.Post('stock/products/' + jsonForm.product_id + '/inventory', jsonData,
|
||||||
function(result)
|
function(result)
|
||||||
@@ -112,6 +113,7 @@ Grocy.Components.ProductPicker.GetPicker().on('change', function(e)
|
|||||||
$("#tare-weight-handling-info").addClass("d-none");
|
$("#tare-weight-handling-info").addClass("d-none");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Grocy.Components.LocationPicker.SetId(productDetails.location.id);
|
||||||
$('#new_amount').focus();
|
$('#new_amount').focus();
|
||||||
},
|
},
|
||||||
function(xhr)
|
function(xhr)
|
||||||
@@ -212,11 +214,13 @@ $('#new_amount').on('keyup', function(e)
|
|||||||
{
|
{
|
||||||
$('#inventory-change-info').text(L('This means #1 will be added to stock', estimatedBookingAmount.toLocaleString() + ' ' + Pluralize(estimatedBookingAmount, productDetails.quantity_unit_stock.name, productDetails.quantity_unit_stock.name_plural)));
|
$('#inventory-change-info').text(L('This means #1 will be added to stock', estimatedBookingAmount.toLocaleString() + ' ' + Pluralize(estimatedBookingAmount, productDetails.quantity_unit_stock.name, productDetails.quantity_unit_stock.name_plural)));
|
||||||
Grocy.Components.DateTimePicker.GetInputElement().attr('required', '');
|
Grocy.Components.DateTimePicker.GetInputElement().attr('required', '');
|
||||||
|
Grocy.Components.LocationPicker.GetInputElement().attr('required', '');
|
||||||
}
|
}
|
||||||
else if (newAmount < productStockAmount + containerWeight)
|
else if (newAmount < productStockAmount + containerWeight)
|
||||||
{
|
{
|
||||||
$('#inventory-change-info').text(L('This means #1 will be removed from stock', estimatedBookingAmount.toLocaleString() + ' ' + Pluralize(estimatedBookingAmount, productDetails.quantity_unit_stock.name, productDetails.quantity_unit_stock.name_plural)));
|
$('#inventory-change-info').text(L('This means #1 will be removed from stock', estimatedBookingAmount.toLocaleString() + ' ' + Pluralize(estimatedBookingAmount, productDetails.quantity_unit_stock.name, productDetails.quantity_unit_stock.name_plural)));
|
||||||
Grocy.Components.DateTimePicker.GetInputElement().removeAttr('required');
|
Grocy.Components.DateTimePicker.GetInputElement().removeAttr('required');
|
||||||
|
Grocy.Components.LocationPicker.GetInputElement().removeAttr('required');
|
||||||
}
|
}
|
||||||
|
|
||||||
Grocy.FrontendHelpers.ValidateForm('inventory-form');
|
Grocy.FrontendHelpers.ValidateForm('inventory-form');
|
||||||
|
@@ -292,7 +292,7 @@ class StockService extends BaseService
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function InventoryProduct(int $productId, int $newAmount, string $bestBeforeDate)
|
public function InventoryProduct(int $productId, int $newAmount, string $bestBeforeDate, $locationId = null)
|
||||||
{
|
{
|
||||||
if (!$this->ProductExists($productId))
|
if (!$this->ProductExists($productId))
|
||||||
{
|
{
|
||||||
@@ -318,7 +318,7 @@ class StockService extends BaseService
|
|||||||
$bookingAmount = $newAmount;
|
$bookingAmount = $newAmount;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->AddProduct($productId, $bookingAmount, $bestBeforeDate, self::TRANSACTION_TYPE_INVENTORY_CORRECTION, date('Y-m-d'), $productDetails->last_price);
|
$this->AddProduct($productId, $bookingAmount, $bestBeforeDate, self::TRANSACTION_TYPE_INVENTORY_CORRECTION, date('Y-m-d'), $productDetails->last_price, $locationId);
|
||||||
}
|
}
|
||||||
else if ($newAmount < $productDetails->stock_amount + $containerWeight)
|
else if ($newAmount < $productDetails->stock_amount + $containerWeight)
|
||||||
{
|
{
|
||||||
|
@@ -45,6 +45,11 @@
|
|||||||
'earlierThanInfoText' => $L('The given date is earlier than today, are you sure?')
|
'earlierThanInfoText' => $L('The given date is earlier than today, are you sure?')
|
||||||
))
|
))
|
||||||
|
|
||||||
|
@include('components.locationpicker', array(
|
||||||
|
'locations' => $locations,
|
||||||
|
'hint' => 'This will apply to added products'
|
||||||
|
))
|
||||||
|
|
||||||
<button id="save-inventory-button" class="btn btn-success">{{ $L('OK') }}</button>
|
<button id="save-inventory-button" class="btn btn-success">{{ $L('OK') }}</button>
|
||||||
|
|
||||||
</form>
|
</form>
|
||||||
|
Reference in New Issue
Block a user