2
0
mirror of https://github.com/inventree/inventree-app.git synced 2025-04-28 13:36:50 +00:00
inventree-app/lib/widget/stock_list.dart
Oliver aa274b2e45
Stock location scan (#169)
* Add action for scanning a stock location into another location

* Adds barcode scan handler for new functionality

* Handle scanning of stock location

* Cleanup

* Refactor existing barcode scanning functions

- Will require extensive testing and validation

* Add entry to release notes

* Delete dead code

* Improved ordering based on stock quantity

* Bug fix for 'adjustStock' function

* Improve error responses for barcode scanning

* Improve error responses for barcode scanning

* Remove old debug statements

* Add some extra explanatory texts

* Icon change

* Fixes for unit tests

* Adds extra functionality for user profile manager

* Refactor barcode code - do not rely on BuildContext

* Adds initial unit testing for barcode scanning

- Work on mocking barcode data
- Add hooks for testing snackBar and audio files

* Linting fixes

* More barcode unit tests

* Cleanup unit tests for barcode

* Remove unused import

* Handle HTTPException in API

* Improvements for API unit testing

* Unit testing for scanning item into location

* Add unit test for scanning in items from a location context

* Unit test for scanning location into parent location

* Improve feedback for barcode scanning events
2022-07-18 22:10:00 +10:00

118 lines
2.9 KiB
Dart

import "package:flutter/material.dart";
import "package:inventree/inventree/model.dart";
import "package:inventree/inventree/stock.dart";
import "package:inventree/widget/paginator.dart";
import "package:inventree/widget/refreshable_state.dart";
import "package:inventree/l10.dart";
import "package:inventree/preferences.dart";
import "package:inventree/widget/stock_detail.dart";
import "package:inventree/api.dart";
class StockItemList extends StatefulWidget {
const StockItemList(this.filters);
final Map<String, String> filters;
@override
_StockListState createState() => _StockListState(filters);
}
class _StockListState extends RefreshableState<StockItemList> {
_StockListState(this.filters);
final Map<String, String> filters;
@override
String getAppBarTitle(BuildContext context) => L10().stockItems;
@override
Widget getBody(BuildContext context) {
return PaginatedStockItemList(filters);
}
}
class PaginatedStockItemList extends StatefulWidget {
const PaginatedStockItemList(this.filters);
final Map<String, String> filters;
@override
_PaginatedStockItemListState createState() => _PaginatedStockItemListState(filters);
}
class _PaginatedStockItemListState extends PaginatedSearchState<PaginatedStockItemList> {
_PaginatedStockItemListState(Map<String, String> filters) : super(filters);
@override
String get prefix => "stock_";
@override
Map<String, String> get orderingOptions => {
"part__name": L10().name,
"part__IPN": L10().internalPartNumber,
"stock": L10().quantity,
"status": L10().status,
"batch": L10().batchCode,
"updated": L10().lastUpdated,
"stocktake_date": L10().lastStocktake,
};
@override
Future<InvenTreePageResponse?> requestPage(int limit, int offset, Map<String, String> params) async {
// Do we include stock items from sub-locations?
final bool cascade = await InvenTreeSettingsManager().getBool(INV_STOCK_SUBLOCATION, true);
params["cascade"] = "${cascade}";
final page = await InvenTreeStockItem().listPaginated(
limit,
offset,
filters: params
);
return page;
}
void _openItem(BuildContext context, int pk) {
InvenTreeStockItem().get(pk).then((var item) {
if (item is InvenTreeStockItem) {
Navigator.push(context, MaterialPageRoute(builder: (context) => StockDetailWidget(item)));
}
});
}
@override
Widget buildItem(BuildContext context, InvenTreeModel model) {
InvenTreeStockItem item = model as InvenTreeStockItem;
return ListTile(
title: Text("${item.partName}"),
subtitle: Text("${item.locationPathString}"),
leading: InvenTreeAPI().getImage(
item.partThumbnail,
width: 40,
height: 40,
),
trailing: Text("${item.displayQuantity}",
style: TextStyle(
fontWeight: FontWeight.bold,
color: item.statusColor,
),
),
onTap: () {
_openItem(context, item.pk);
},
);
}
}