mirror of
https://github.com/inventree/inventree-app.git
synced 2025-06-14 19:25:27 +00:00
Sales order support (#438)
* Add new models for SalesOrder - Create generic Order and OrderLine models with common functionality * Refactor - Move some widgets around - Cleanup directory structure * Add link to home screen and nav drawer * Add SalesOrder list widget * Linting fixes * Fix string * Refactor PurchaseOrderDetailWidget * Tweaks to existing code * linting * Fixes for drawer widget * Add "detail" page for SalesOrder * Add more tiles to SalesOrder detail * Allow editing of salesorder * add list filters for sales orders * Display list of line items * Customer updates - Display customer icon on home screen - Fetch sales orders for customer detail page * Cleanup company detail view * Create new sales order from list * Stricter typing for formFields method * Create new PurchaseOrder and SalesOrder from company deatil * Status code updates - Add function for name comparison - Remove hard-coded values * Update view permission checks for home widget * Add ability to manually add SalesOrderLineItem * Add nice progress bar widgets * Display detail view for sales order line item * edit SalesOrderLineItem * Fix unused import * Hide "shipped items" tab - Will be added in a future update
This commit is contained in:
424
lib/widget/stock/location_display.dart
Normal file
424
lib/widget/stock/location_display.dart
Normal file
@ -0,0 +1,424 @@
|
||||
import "package:flutter/material.dart";
|
||||
import "package:flutter_speed_dial/flutter_speed_dial.dart";
|
||||
|
||||
import "package:font_awesome_flutter/font_awesome_flutter.dart";
|
||||
|
||||
import "package:inventree/app_colors.dart";
|
||||
import "package:inventree/barcode/barcode.dart";
|
||||
import "package:inventree/l10.dart";
|
||||
|
||||
import "package:inventree/inventree/stock.dart";
|
||||
import "package:inventree/preferences.dart";
|
||||
|
||||
import "package:inventree/widget/stock/location_list.dart";
|
||||
import "package:inventree/widget/progress.dart";
|
||||
import "package:inventree/widget/refreshable_state.dart";
|
||||
import "package:inventree/widget/snacks.dart";
|
||||
import "package:inventree/widget/stock/stock_detail.dart";
|
||||
import "package:inventree/widget/stock/stock_list.dart";
|
||||
import "package:inventree/labels.dart";
|
||||
|
||||
|
||||
/*
|
||||
* Widget for displaying detail view for a single StockLocation instance
|
||||
*/
|
||||
class LocationDisplayWidget extends StatefulWidget {
|
||||
|
||||
LocationDisplayWidget(this.location, {Key? key}) : super(key: key);
|
||||
|
||||
final InvenTreeStockLocation? location;
|
||||
|
||||
final String title = L10().stockLocation;
|
||||
|
||||
@override
|
||||
_LocationDisplayState createState() => _LocationDisplayState(location);
|
||||
}
|
||||
|
||||
class _LocationDisplayState extends RefreshableState<LocationDisplayWidget> {
|
||||
|
||||
_LocationDisplayState(this.location);
|
||||
|
||||
final InvenTreeStockLocation? location;
|
||||
|
||||
List<Map<String, dynamic>> labels = [];
|
||||
|
||||
@override
|
||||
String getAppBarTitle() {
|
||||
return L10().stockLocation;
|
||||
}
|
||||
|
||||
@override
|
||||
List<Widget> appBarActions(BuildContext context) {
|
||||
List<Widget> actions = [];
|
||||
|
||||
// Add "locate" button
|
||||
if (location != null && api.supportsMixin("locate")) {
|
||||
actions.add(
|
||||
IconButton(
|
||||
icon: Icon(Icons.travel_explore),
|
||||
tooltip: L10().locateLocation,
|
||||
onPressed: () async {
|
||||
api.locateItemOrLocation(context, location: location!.pk);
|
||||
}
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
// Add "edit" button
|
||||
if (location != null && InvenTreeStockLocation().canEdit) {
|
||||
actions.add(
|
||||
IconButton(
|
||||
icon: Icon(Icons.edit_square),
|
||||
tooltip: L10().editLocation,
|
||||
onPressed: () {
|
||||
_editLocationDialog(context);
|
||||
}
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
return actions;
|
||||
}
|
||||
|
||||
@override
|
||||
List<SpeedDialChild> barcodeButtons(BuildContext context) {
|
||||
List<SpeedDialChild> actions = [];
|
||||
|
||||
if (location != null) {
|
||||
// Scan items into this location
|
||||
if (InvenTreeStockItem().canEdit) {
|
||||
actions.add(
|
||||
SpeedDialChild(
|
||||
child: FaIcon(FontAwesomeIcons.qrcode),
|
||||
label: L10().barcodeScanItem,
|
||||
onTap: () {
|
||||
scanBarcode(
|
||||
context,
|
||||
handler: StockLocationScanInItemsHandler(location!),
|
||||
).then((value) {
|
||||
refresh(context);
|
||||
});
|
||||
}
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if (api.supportsBarcodePOReceiveEndpoint) {
|
||||
actions.add(
|
||||
SpeedDialChild(
|
||||
child: Icon(Icons.barcode_reader),
|
||||
label: L10().scanReceivedParts,
|
||||
onTap:() async {
|
||||
scanBarcode(
|
||||
context,
|
||||
handler: POReceiveBarcodeHandler(location: location),
|
||||
);
|
||||
},
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
// Scan this location into another one
|
||||
if (InvenTreeStockLocation().canEdit) {
|
||||
actions.add(
|
||||
SpeedDialChild(
|
||||
child: FaIcon(FontAwesomeIcons.qrcode),
|
||||
label: L10().transferStockLocation,
|
||||
onTap: () {
|
||||
scanBarcode(
|
||||
context,
|
||||
handler: ScanParentLocationHandler(location!),
|
||||
).then((value) {
|
||||
refresh(context);
|
||||
});
|
||||
}
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
// Assign or un-assign barcodes
|
||||
if (api.supportModernBarcodes) {
|
||||
actions.add(
|
||||
customBarcodeAction(
|
||||
context, this,
|
||||
location!.customBarcode, "stocklocation",
|
||||
location!.pk
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return actions;
|
||||
}
|
||||
|
||||
@override
|
||||
List<SpeedDialChild> actionButtons(BuildContext context) {
|
||||
List<SpeedDialChild> actions = [];
|
||||
|
||||
// Create new location
|
||||
if (InvenTreeStockLocation().canCreate) {
|
||||
actions.add(
|
||||
SpeedDialChild(
|
||||
child: FaIcon(FontAwesomeIcons.sitemap),
|
||||
label: L10().locationCreate,
|
||||
onTap: () async {
|
||||
_newLocation(context);
|
||||
}
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
// Create new item
|
||||
if (InvenTreeStockItem().canCreate) {
|
||||
actions.add(
|
||||
SpeedDialChild(
|
||||
child: FaIcon(FontAwesomeIcons.boxesStacked),
|
||||
label: L10().stockItemCreate,
|
||||
onTap: () async {
|
||||
_newStockItem(context);
|
||||
}
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if (widget.location != null && labels.isNotEmpty) {
|
||||
actions.add(
|
||||
SpeedDialChild(
|
||||
child: FaIcon(FontAwesomeIcons.print),
|
||||
label: L10().printLabel,
|
||||
onTap: () async {
|
||||
selectAndPrintLabel(
|
||||
context,
|
||||
labels,
|
||||
"location",
|
||||
"location=${widget.location!.pk}"
|
||||
);
|
||||
}
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
return actions;
|
||||
}
|
||||
|
||||
/*
|
||||
* Launch a dialog form to edit this stock location
|
||||
*/
|
||||
void _editLocationDialog(BuildContext context) {
|
||||
final _loc = location;
|
||||
|
||||
if (_loc == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
_loc.editForm(
|
||||
context,
|
||||
L10().editLocation,
|
||||
onSuccess: (data) async {
|
||||
refresh(context);
|
||||
showSnackIcon(L10().locationUpdated, success: true);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> onBuild(BuildContext context) async {
|
||||
refresh(context);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> request(BuildContext context) async {
|
||||
// Reload location information
|
||||
if (location != null) {
|
||||
final bool result = await location!.reload();
|
||||
|
||||
if (!result) {
|
||||
Navigator.of(context).pop();
|
||||
}
|
||||
}
|
||||
|
||||
List<Map<String, dynamic>> _labels = [];
|
||||
bool allowLabelPrinting = await InvenTreeSettingsManager().getBool(INV_ENABLE_LABEL_PRINTING, true);
|
||||
allowLabelPrinting &= api.supportsMixin("labels");
|
||||
|
||||
if (allowLabelPrinting) {
|
||||
|
||||
if (widget.location != null) {
|
||||
_labels = await getLabelTemplates("location", {
|
||||
"location": widget.location!.pk.toString()
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
labels = _labels;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _newLocation(BuildContext context) async {
|
||||
int pk = location?.pk ?? -1;
|
||||
|
||||
InvenTreeStockLocation().createForm(
|
||||
context,
|
||||
L10().locationCreate,
|
||||
data: {
|
||||
"parent": (pk > 0) ? pk : null,
|
||||
},
|
||||
onSuccess: (result) async {
|
||||
Map<String, dynamic> data = result as Map<String, dynamic>;
|
||||
|
||||
if (data.containsKey("pk")) {
|
||||
var loc = InvenTreeStockLocation.fromJson(data);
|
||||
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => LocationDisplayWidget(loc)
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/*
|
||||
* Launch a dialog form to create a new stock item
|
||||
*/
|
||||
Future<void> _newStockItem(BuildContext context) async {
|
||||
|
||||
var fields = InvenTreeStockItem().formFields();
|
||||
|
||||
// Serial number field is not required here
|
||||
fields.remove("serial");
|
||||
|
||||
InvenTreeStockItem().createForm(
|
||||
context,
|
||||
L10().stockItemCreate,
|
||||
data: {
|
||||
"location": location != null ? location!.pk : null,
|
||||
},
|
||||
fields: fields,
|
||||
onSuccess: (result) async {
|
||||
Map<String, dynamic> data = result as Map<String, dynamic>;
|
||||
|
||||
if (data.containsKey("pk")) {
|
||||
var item = InvenTreeStockItem.fromJson(data);
|
||||
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => StockDetailWidget(item)
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
Widget locationDescriptionCard({bool includeActions = true}) {
|
||||
if (location == null) {
|
||||
return Card(
|
||||
child: ListTile(
|
||||
title: Text(
|
||||
L10().stockTopLevel,
|
||||
style: TextStyle(fontStyle: FontStyle.italic)
|
||||
),
|
||||
leading: FaIcon(FontAwesomeIcons.boxesStacked),
|
||||
)
|
||||
);
|
||||
} else {
|
||||
List<Widget> children = [
|
||||
ListTile(
|
||||
title: Text("${location!.name}"),
|
||||
subtitle: Text("${location!.description}"),
|
||||
leading: location!.customIcon ??
|
||||
FaIcon(FontAwesomeIcons.boxesStacked),
|
||||
),
|
||||
];
|
||||
|
||||
if (includeActions) {
|
||||
children.add(
|
||||
ListTile(
|
||||
title: Text(L10().parentLocation),
|
||||
subtitle: Text("${location!.parentPathString}"),
|
||||
leading: FaIcon(FontAwesomeIcons.turnUp, color: COLOR_ACTION),
|
||||
onTap: () async {
|
||||
int parentId = location?.parentId ?? -1;
|
||||
|
||||
if (parentId < 0) {
|
||||
Navigator.push(context, MaterialPageRoute(
|
||||
builder: (context) => LocationDisplayWidget(null)));
|
||||
} else {
|
||||
showLoadingOverlay(context);
|
||||
var loc = await InvenTreeStockLocation().get(parentId);
|
||||
hideLoadingOverlay();
|
||||
|
||||
if (loc is InvenTreeStockLocation) {
|
||||
Navigator.push(context, MaterialPageRoute(
|
||||
builder: (context) => LocationDisplayWidget(loc)));
|
||||
}
|
||||
}
|
||||
},
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
return Card(
|
||||
child: Column(
|
||||
children: children,
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
List<Widget> getTabIcons(BuildContext context) {
|
||||
return [
|
||||
Tab(text: L10().details),
|
||||
Tab(text: L10().stockItems),
|
||||
];
|
||||
}
|
||||
|
||||
@override
|
||||
List<Widget> getTabs(BuildContext context) {
|
||||
return [
|
||||
Column(children: detailTiles()),
|
||||
Column(children: stockTiles()),
|
||||
];
|
||||
}
|
||||
|
||||
// Construct the "details" panel
|
||||
List<Widget> detailTiles() {
|
||||
List<Widget> tiles = [
|
||||
locationDescriptionCard(),
|
||||
Expanded(
|
||||
child: PaginatedStockLocationList(
|
||||
{
|
||||
"parent": location?.pk.toString() ?? "null",
|
||||
},
|
||||
title: L10().sublocations,
|
||||
),
|
||||
flex: 10,
|
||||
)
|
||||
];
|
||||
|
||||
return tiles;
|
||||
}
|
||||
|
||||
// Construct the "stock" panel
|
||||
List<Widget> stockTiles() {
|
||||
Map<String, String> filters = {
|
||||
"location": location?.pk.toString() ?? "null",
|
||||
};
|
||||
|
||||
return [
|
||||
Expanded(
|
||||
child: PaginatedStockItemList(filters),
|
||||
flex: 10,
|
||||
)
|
||||
];
|
||||
}
|
||||
}
|
99
lib/widget/stock/location_list.dart
Normal file
99
lib/widget/stock/location_list.dart
Normal file
@ -0,0 +1,99 @@
|
||||
import "package:flutter/material.dart";
|
||||
|
||||
import "package:inventree/inventree/model.dart";
|
||||
import "package:inventree/inventree/stock.dart";
|
||||
import "package:inventree/widget/stock/location_display.dart";
|
||||
import "package:inventree/widget/paginator.dart";
|
||||
|
||||
import "package:inventree/widget/refreshable_state.dart";
|
||||
import "package:inventree/l10.dart";
|
||||
|
||||
|
||||
class StockLocationList extends StatefulWidget {
|
||||
|
||||
const StockLocationList(this.filters);
|
||||
|
||||
final Map<String, String> filters;
|
||||
|
||||
@override
|
||||
_StockLocationListState createState() => _StockLocationListState(filters);
|
||||
}
|
||||
|
||||
|
||||
class _StockLocationListState extends RefreshableState<StockLocationList> {
|
||||
|
||||
_StockLocationListState(this.filters);
|
||||
|
||||
final Map<String, String> filters;
|
||||
|
||||
@override
|
||||
String getAppBarTitle() => L10().stockLocations;
|
||||
|
||||
@override
|
||||
Widget getBody(BuildContext context) {
|
||||
return PaginatedStockLocationList(filters);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class PaginatedStockLocationList extends PaginatedSearchWidget {
|
||||
|
||||
const PaginatedStockLocationList(Map<String, String> filters, {String title = ""}) : super(filters: filters, title: title);
|
||||
|
||||
@override
|
||||
String get searchTitle => title.isNotEmpty ? title : L10().stockLocations;
|
||||
|
||||
@override
|
||||
_PaginatedStockLocationListState createState() => _PaginatedStockLocationListState();
|
||||
}
|
||||
|
||||
|
||||
class _PaginatedStockLocationListState extends PaginatedSearchState<PaginatedStockLocationList> {
|
||||
|
||||
_PaginatedStockLocationListState() : super();
|
||||
|
||||
@override
|
||||
Map<String, String> get orderingOptions => {
|
||||
"name": L10().name,
|
||||
"items": L10().stockItems,
|
||||
"level": L10().level,
|
||||
};
|
||||
|
||||
@override
|
||||
Map<String, Map<String, dynamic>> get filterOptions => {
|
||||
"cascade": {
|
||||
"label": L10().includeSublocations,
|
||||
"help_text": L10().includeSublocationsDetail,
|
||||
"tristate": false,
|
||||
}
|
||||
};
|
||||
|
||||
@override
|
||||
Future<InvenTreePageResponse?> requestPage(int limit, int offset, Map<String, String> params) async {
|
||||
|
||||
final page = await InvenTreeStockLocation().listPaginated(limit, offset, filters: params);
|
||||
|
||||
return page;
|
||||
}
|
||||
|
||||
@override
|
||||
Widget buildItem(BuildContext context, InvenTreeModel model) {
|
||||
|
||||
InvenTreeStockLocation location = model as InvenTreeStockLocation;
|
||||
|
||||
return ListTile(
|
||||
title: Text(location.name),
|
||||
subtitle: Text(location.pathstring),
|
||||
trailing: Text("${location.itemcount}"),
|
||||
leading: location.customIcon,
|
||||
onTap: () {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => LocationDisplayWidget(location)
|
||||
)
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
787
lib/widget/stock/stock_detail.dart
Normal file
787
lib/widget/stock/stock_detail.dart
Normal file
@ -0,0 +1,787 @@
|
||||
import "package:flutter/material.dart";
|
||||
import "package:flutter_speed_dial/flutter_speed_dial.dart";
|
||||
|
||||
import "package:font_awesome_flutter/font_awesome_flutter.dart";
|
||||
|
||||
import "package:inventree/app_colors.dart";
|
||||
import "package:inventree/barcode/barcode.dart";
|
||||
import "package:inventree/helpers.dart";
|
||||
import "package:inventree/l10.dart";
|
||||
import "package:inventree/api.dart";
|
||||
import "package:inventree/api_form.dart";
|
||||
import "package:inventree/labels.dart";
|
||||
import "package:inventree/preferences.dart";
|
||||
|
||||
import "package:inventree/inventree/company.dart";
|
||||
import "package:inventree/inventree/stock.dart";
|
||||
import "package:inventree/inventree/part.dart";
|
||||
|
||||
import "package:inventree/widget/company/supplier_part_detail.dart";
|
||||
import "package:inventree/widget/dialogs.dart";
|
||||
import "package:inventree/widget/attachment_widget.dart";
|
||||
import "package:inventree/widget/stock/location_display.dart";
|
||||
import "package:inventree/widget/part/part_detail.dart";
|
||||
import "package:inventree/widget/progress.dart";
|
||||
import "package:inventree/widget/refreshable_state.dart";
|
||||
import "package:inventree/widget/snacks.dart";
|
||||
import "package:inventree/widget/stock/stock_item_history.dart";
|
||||
import "package:inventree/widget/stock/stock_item_test_results.dart";
|
||||
import "package:inventree/widget/notes_widget.dart";
|
||||
|
||||
|
||||
class StockDetailWidget extends StatefulWidget {
|
||||
|
||||
const StockDetailWidget(this.item, {Key? key}) : super(key: key);
|
||||
|
||||
final InvenTreeStockItem item;
|
||||
|
||||
@override
|
||||
_StockItemDisplayState createState() => _StockItemDisplayState();
|
||||
}
|
||||
|
||||
|
||||
class _StockItemDisplayState extends RefreshableState<StockDetailWidget> {
|
||||
|
||||
_StockItemDisplayState();
|
||||
|
||||
@override
|
||||
String getAppBarTitle() => L10().stockItem;
|
||||
|
||||
bool stockShowHistory = false;
|
||||
bool stockShowTests = true;
|
||||
|
||||
@override
|
||||
List<Widget> appBarActions(BuildContext context) {
|
||||
List<Widget> actions = [];
|
||||
|
||||
if (api.supportsMixin("locate")) {
|
||||
actions.add(
|
||||
IconButton(
|
||||
icon: Icon(Icons.travel_explore),
|
||||
tooltip: L10().locateItem,
|
||||
onPressed: () async {
|
||||
api.locateItemOrLocation(context, item: widget.item.pk);
|
||||
}
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if (widget.item.canEdit) {
|
||||
actions.add(
|
||||
IconButton(
|
||||
icon: Icon(Icons.edit_square),
|
||||
tooltip: L10().editItem,
|
||||
onPressed: () {
|
||||
_editStockItem(context);
|
||||
}
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
return actions;
|
||||
}
|
||||
|
||||
@override
|
||||
List<SpeedDialChild> actionButtons(BuildContext context) {
|
||||
|
||||
List<SpeedDialChild> actions = [];
|
||||
|
||||
if (widget.item.canEdit) {
|
||||
|
||||
// Stock adjustment actions available if item is *not* serialized
|
||||
if (!widget.item.isSerialized()) {
|
||||
|
||||
actions.add(
|
||||
SpeedDialChild(
|
||||
child: FaIcon(FontAwesomeIcons.circleCheck, color: Colors.blue),
|
||||
label: L10().countStock,
|
||||
onTap: _countStockDialog,
|
||||
)
|
||||
);
|
||||
|
||||
actions.add(
|
||||
SpeedDialChild(
|
||||
child: FaIcon(FontAwesomeIcons.circleMinus, color: Colors.red),
|
||||
label: L10().removeStock,
|
||||
onTap: _removeStockDialog,
|
||||
)
|
||||
);
|
||||
|
||||
actions.add(
|
||||
SpeedDialChild(
|
||||
child: FaIcon(FontAwesomeIcons.circlePlus, color: Colors.green),
|
||||
label: L10().addStock,
|
||||
onTap: _addStockDialog,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
// Transfer item
|
||||
actions.add(
|
||||
SpeedDialChild(
|
||||
child: Icon(Icons.trolley),
|
||||
label: L10().transferStock,
|
||||
onTap: () {
|
||||
_transferStockDialog(context);
|
||||
}
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if (labels.isNotEmpty) {
|
||||
actions.add(
|
||||
SpeedDialChild(
|
||||
child: FaIcon(FontAwesomeIcons.print),
|
||||
label: L10().printLabel,
|
||||
onTap: () async {
|
||||
selectAndPrintLabel(
|
||||
context,
|
||||
labels,
|
||||
"stock",
|
||||
"item=${widget.item.pk}"
|
||||
);
|
||||
}
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if (widget.item.canDelete) {
|
||||
actions.add(
|
||||
SpeedDialChild(
|
||||
child: FaIcon(FontAwesomeIcons.trashCan, color: Colors.red),
|
||||
label: L10().stockItemDelete,
|
||||
onTap: () {
|
||||
_deleteItem(context);
|
||||
}
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
return actions;
|
||||
}
|
||||
|
||||
@override
|
||||
List<SpeedDialChild> barcodeButtons(BuildContext context) {
|
||||
List<SpeedDialChild> actions = [];
|
||||
|
||||
if (widget.item.canEdit) {
|
||||
// Scan item into location
|
||||
actions.add(
|
||||
SpeedDialChild(
|
||||
child: Icon(Icons.qr_code_scanner),
|
||||
label: L10().scanIntoLocation,
|
||||
onTap: () {
|
||||
scanBarcode(
|
||||
context,
|
||||
handler: StockItemScanIntoLocationHandler(widget.item)
|
||||
).then((ctx) {
|
||||
refresh(context);
|
||||
});
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
if (api.supportModernBarcodes) {
|
||||
actions.add(
|
||||
customBarcodeAction(
|
||||
context, this,
|
||||
widget.item.customBarcode,
|
||||
"stockitem", widget.item.pk
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return actions;
|
||||
}
|
||||
|
||||
// Is label printing enabled for this StockItem?
|
||||
// This will be determined when the widget is loaded
|
||||
List<Map<String, dynamic>> labels = [];
|
||||
|
||||
// Part object
|
||||
InvenTreePart? part;
|
||||
|
||||
int attachmentCount = 0;
|
||||
|
||||
@override
|
||||
Future<void> onBuild(BuildContext context) async {
|
||||
// Load part data if not already loaded
|
||||
if (part == null) {
|
||||
refresh(context);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> request(BuildContext context) async {
|
||||
await api.StockStatus.load();
|
||||
stockShowHistory = await InvenTreeSettingsManager().getValue(INV_STOCK_SHOW_HISTORY, false) as bool;
|
||||
stockShowTests = await InvenTreeSettingsManager().getValue(INV_STOCK_SHOW_TESTS, true) as bool;
|
||||
|
||||
final bool result = widget.item.pk > 0 && await widget.item.reload();
|
||||
|
||||
// Could not load this stock item for some reason
|
||||
// Perhaps it has been depleted?
|
||||
if (!result) {
|
||||
Navigator.of(context).pop();
|
||||
}
|
||||
|
||||
// Request part information
|
||||
part = await InvenTreePart().get(widget.item.partId) as InvenTreePart?;
|
||||
|
||||
stockShowTests &= part?.isTrackable ?? false;
|
||||
|
||||
// Request test results (async)
|
||||
if (stockShowTests) {
|
||||
widget.item.getTestResults().then((value) {
|
||||
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
// Update
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Request the number of attachments
|
||||
InvenTreeStockItemAttachment().count(
|
||||
filters: {
|
||||
"stock_item": widget.item.pk.toString()
|
||||
}
|
||||
).then((int value) {
|
||||
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
attachmentCount = value;
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
List<Map<String, dynamic>> _labels = [];
|
||||
bool allowLabelPrinting = await InvenTreeSettingsManager().getBool(INV_ENABLE_LABEL_PRINTING, true);
|
||||
allowLabelPrinting &= api.supportsMixin("labels");
|
||||
|
||||
// Request information on labels available for this stock item
|
||||
if (allowLabelPrinting) {
|
||||
// Clear the existing labels list
|
||||
_labels = await getLabelTemplates("stock", {
|
||||
"item": widget.item.pk.toString()
|
||||
});
|
||||
}
|
||||
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
labels = _labels;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/// Delete the stock item from the database
|
||||
Future<void> _deleteItem(BuildContext context) async {
|
||||
|
||||
confirmationDialog(
|
||||
L10().stockItemDelete,
|
||||
L10().stockItemDeleteConfirm,
|
||||
icon: FontAwesomeIcons.trashCan,
|
||||
color: Colors.red,
|
||||
acceptText: L10().delete,
|
||||
onAccept: () async {
|
||||
final bool result = await widget.item.delete();
|
||||
|
||||
if (result) {
|
||||
Navigator.of(context).pop();
|
||||
showSnackIcon(L10().stockItemDeleteSuccess, success: true);
|
||||
} else {
|
||||
showSnackIcon(L10().stockItemDeleteFailure, success: false);
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
Future <void> _editStockItem(BuildContext context) async {
|
||||
|
||||
var fields = InvenTreeStockItem().formFields();
|
||||
|
||||
// Some fields we don't want to edit!
|
||||
fields.remove("part");
|
||||
fields.remove("quantity");
|
||||
fields.remove("location");
|
||||
fields.remove("serial_numbers");
|
||||
|
||||
if (part == null || !part!.isTrackable) {
|
||||
fields.remove("serial");
|
||||
}
|
||||
|
||||
widget.item.editForm(
|
||||
context,
|
||||
L10().editItem,
|
||||
fields: fields,
|
||||
onSuccess: (data) async {
|
||||
refresh(context);
|
||||
showSnackIcon(L10().stockItemUpdated, success: true);
|
||||
}
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* Launch a dialog to 'add' quantity to this StockItem
|
||||
*/
|
||||
Future <void> _addStockDialog() async {
|
||||
|
||||
Map<String, dynamic> fields = {
|
||||
"pk": {
|
||||
"parent": "items",
|
||||
"nested": true,
|
||||
"hidden": true,
|
||||
"value": widget.item.pk,
|
||||
},
|
||||
"quantity": {
|
||||
"parent": "items",
|
||||
"nested": true,
|
||||
"value": 0,
|
||||
},
|
||||
"notes": {},
|
||||
};
|
||||
|
||||
launchApiForm(
|
||||
context,
|
||||
L10().addStock,
|
||||
InvenTreeStockItem.addStockUrl(),
|
||||
fields,
|
||||
method: "POST",
|
||||
icon: FontAwesomeIcons.circlePlus,
|
||||
onSuccess: (data) async {
|
||||
_stockUpdateMessage(true);
|
||||
refresh(context);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
void _stockUpdateMessage(bool result) {
|
||||
|
||||
if (result) {
|
||||
showSnackIcon(L10().stockItemUpdated, success: true);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Launch a dialog to 'remove' quantity from this StockItem
|
||||
*/
|
||||
void _removeStockDialog() {
|
||||
|
||||
Map<String, dynamic> fields = {
|
||||
"pk": {
|
||||
"parent": "items",
|
||||
"nested": true,
|
||||
"hidden": true,
|
||||
"value": widget.item.pk,
|
||||
},
|
||||
"quantity": {
|
||||
"parent": "items",
|
||||
"nested": true,
|
||||
"value": 0,
|
||||
},
|
||||
"notes": {},
|
||||
};
|
||||
|
||||
launchApiForm(
|
||||
context,
|
||||
L10().removeStock,
|
||||
InvenTreeStockItem.removeStockUrl(),
|
||||
fields,
|
||||
method: "POST",
|
||||
icon: FontAwesomeIcons.circleMinus,
|
||||
onSuccess: (data) async {
|
||||
_stockUpdateMessage(true);
|
||||
refresh(context);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
Future <void> _countStockDialog() async {
|
||||
|
||||
Map<String, dynamic> fields = {
|
||||
"pk": {
|
||||
"parent": "items",
|
||||
"nested": true,
|
||||
"hidden": true,
|
||||
"value": widget.item.pk,
|
||||
},
|
||||
"quantity": {
|
||||
"parent": "items",
|
||||
"nested": true,
|
||||
"value": widget.item.quantity,
|
||||
},
|
||||
"notes": {},
|
||||
};
|
||||
|
||||
launchApiForm(
|
||||
context,
|
||||
L10().countStock,
|
||||
InvenTreeStockItem.countStockUrl(),
|
||||
fields,
|
||||
method: "POST",
|
||||
icon: FontAwesomeIcons.clipboardCheck,
|
||||
onSuccess: (data) async {
|
||||
_stockUpdateMessage(true);
|
||||
refresh(context);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/*
|
||||
* Launches an API Form to transfer this stock item to a new location
|
||||
*/
|
||||
Future <void> _transferStockDialog(BuildContext context) async {
|
||||
|
||||
Map<String, dynamic> fields = {
|
||||
"pk": {
|
||||
"parent": "items",
|
||||
"nested": true,
|
||||
"hidden": true,
|
||||
"value": widget.item.pk,
|
||||
},
|
||||
"quantity": {
|
||||
"parent": "items",
|
||||
"nested": true,
|
||||
"value": widget.item.quantity,
|
||||
},
|
||||
"location": {
|
||||
"value": widget.item.locationId,
|
||||
},
|
||||
"status": {
|
||||
"parent": "items",
|
||||
"nested": true,
|
||||
"value": widget.item.status,
|
||||
},
|
||||
"packaging": {
|
||||
"parent": "items",
|
||||
"nested": true,
|
||||
"value": widget.item.packaging,
|
||||
},
|
||||
"notes": {},
|
||||
};
|
||||
|
||||
if (widget.item.isSerialized()) {
|
||||
// Prevent editing of 'quantity' field if the item is serialized
|
||||
fields["quantity"]["hidden"] = true;
|
||||
}
|
||||
|
||||
// Old API does not support these fields
|
||||
if (!api.supportsStockAdjustExtraFields) {
|
||||
fields.remove("packaging");
|
||||
fields.remove("status");
|
||||
}
|
||||
|
||||
launchApiForm(
|
||||
context,
|
||||
L10().transferStock,
|
||||
InvenTreeStockItem.transferStockUrl(),
|
||||
fields,
|
||||
method: "POST",
|
||||
icon: FontAwesomeIcons.dolly,
|
||||
onSuccess: (data) async {
|
||||
_stockUpdateMessage(true);
|
||||
refresh(context);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
Widget headerTile() {
|
||||
return Card(
|
||||
child: ListTile(
|
||||
title: Text("${widget.item.partName}"),
|
||||
subtitle: Text("${widget.item.partDescription}"),
|
||||
leading: InvenTreeAPI().getThumbnail(widget.item.partImage),
|
||||
trailing: Text(
|
||||
widget.item.quantityString(),
|
||||
style: TextStyle(
|
||||
fontSize: 20,
|
||||
color: api.StockStatus.color(widget.item.status),
|
||||
)
|
||||
),
|
||||
onTap: () async {
|
||||
if (widget.item.partId > 0) {
|
||||
|
||||
showLoadingOverlay(context);
|
||||
var part = await InvenTreePart().get(widget.item.partId);
|
||||
hideLoadingOverlay();
|
||||
|
||||
if (part is InvenTreePart) {
|
||||
Navigator.push(context, MaterialPageRoute(builder: (context) => PartDetailWidget(part)));
|
||||
}
|
||||
}
|
||||
},
|
||||
//trailing: Text(item.serialOrQuantityDisplay()),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/*
|
||||
* Construct a list of detail elements about this StockItem.
|
||||
* The number of elements may vary depending on the StockItem details
|
||||
*/
|
||||
@override
|
||||
List<Widget> getTiles(BuildContext context) {
|
||||
List<Widget> tiles = [];
|
||||
|
||||
// Image / name / description
|
||||
tiles.add(headerTile());
|
||||
|
||||
if (loading) {
|
||||
tiles.add(progressIndicator());
|
||||
return tiles;
|
||||
}
|
||||
|
||||
// Location information
|
||||
if ((widget.item.locationId > 0) && (widget.item.locationName.isNotEmpty)) {
|
||||
tiles.add(
|
||||
ListTile(
|
||||
title: Text(L10().stockLocation),
|
||||
subtitle: Text("${widget.item.locationPathString}"),
|
||||
leading: FaIcon(
|
||||
FontAwesomeIcons.locationDot,
|
||||
color: COLOR_ACTION,
|
||||
),
|
||||
onTap: () async {
|
||||
if (widget.item.locationId > 0) {
|
||||
|
||||
showLoadingOverlay(context);
|
||||
var loc = await InvenTreeStockLocation().get(widget.item.locationId);
|
||||
hideLoadingOverlay();
|
||||
|
||||
if (loc is InvenTreeStockLocation) {
|
||||
Navigator.push(context, MaterialPageRoute(
|
||||
builder: (context) => LocationDisplayWidget(loc)));
|
||||
}
|
||||
}
|
||||
},
|
||||
),
|
||||
);
|
||||
} else {
|
||||
tiles.add(
|
||||
ListTile(
|
||||
title: Text(L10().stockLocation),
|
||||
leading: FaIcon(FontAwesomeIcons.locationDot),
|
||||
subtitle: Text(L10().locationNotSet),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
// Quantity information
|
||||
if (widget.item.isSerialized()) {
|
||||
tiles.add(
|
||||
ListTile(
|
||||
title: Text(L10().serialNumber),
|
||||
leading: FaIcon(FontAwesomeIcons.hashtag),
|
||||
trailing: Text("${widget.item.serialNumber}"),
|
||||
)
|
||||
);
|
||||
} else {
|
||||
tiles.add(
|
||||
ListTile(
|
||||
title: widget.item.allocated > 0 ? Text(L10().quantityAvailable) : Text(L10().quantity),
|
||||
leading: FaIcon(FontAwesomeIcons.cubes),
|
||||
trailing: Text("${widget.item.quantityString()}"),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
// Stock item status information
|
||||
tiles.add(
|
||||
ListTile(
|
||||
title: Text(L10().status),
|
||||
leading: FaIcon(FontAwesomeIcons.circleInfo),
|
||||
trailing: Text(
|
||||
api.StockStatus.label(widget.item.status),
|
||||
style: TextStyle(
|
||||
color: api.StockStatus.color(widget.item.status),
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
// Supplier part information (if available)
|
||||
if (widget.item.supplierPartId > 0) {
|
||||
tiles.add(
|
||||
ListTile(
|
||||
title: Text(L10().supplierPart),
|
||||
subtitle: Text(widget.item.supplierSKU),
|
||||
leading: FaIcon(FontAwesomeIcons.building, color: COLOR_ACTION),
|
||||
trailing: InvenTreeAPI().getThumbnail(widget.item.supplierImage, hideIfNull: true),
|
||||
onTap: () async {
|
||||
showLoadingOverlay(context);
|
||||
var sp = await InvenTreeSupplierPart().get(
|
||||
widget.item.supplierPartId);
|
||||
hideLoadingOverlay();
|
||||
if (sp is InvenTreeSupplierPart) {
|
||||
Navigator.push(
|
||||
context, MaterialPageRoute(
|
||||
builder: (context) => SupplierPartDetailWidget(sp))
|
||||
);
|
||||
}
|
||||
}
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if (widget.item.isBuilding) {
|
||||
tiles.add(
|
||||
ListTile(
|
||||
title: Text(L10().inProduction),
|
||||
leading: FaIcon(FontAwesomeIcons.screwdriverWrench),
|
||||
subtitle: Text(L10().inProductionDetail),
|
||||
onTap: () {
|
||||
// TODO: Click through to the "build order"
|
||||
},
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if (widget.item.batch.isNotEmpty) {
|
||||
tiles.add(
|
||||
ListTile(
|
||||
title: Text(L10().batchCode),
|
||||
subtitle: Text(widget.item.batch),
|
||||
leading: FaIcon(FontAwesomeIcons.layerGroup),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if (widget.item.packaging.isNotEmpty) {
|
||||
tiles.add(
|
||||
ListTile(
|
||||
title: Text(L10().packaging),
|
||||
subtitle: Text(widget.item.packaging),
|
||||
leading: FaIcon(FontAwesomeIcons.boxesPacking),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
// Last update?
|
||||
if (widget.item.updatedDateString.isNotEmpty) {
|
||||
|
||||
tiles.add(
|
||||
ListTile(
|
||||
title: Text(L10().lastUpdated),
|
||||
subtitle: Text(widget.item.updatedDateString),
|
||||
leading: FaIcon(FontAwesomeIcons.calendarDays)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
// Stocktake?
|
||||
if (widget.item.stocktakeDateString.isNotEmpty) {
|
||||
tiles.add(
|
||||
ListTile(
|
||||
title: Text(L10().lastStocktake),
|
||||
subtitle: Text(widget.item.stocktakeDateString),
|
||||
leading: FaIcon(FontAwesomeIcons.calendarDays)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if (widget.item.link.isNotEmpty) {
|
||||
tiles.add(
|
||||
ListTile(
|
||||
title: Text("${widget.item.link}"),
|
||||
leading: FaIcon(FontAwesomeIcons.link, color: COLOR_ACTION),
|
||||
onTap: () {
|
||||
widget.item.openLink();
|
||||
},
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if (stockShowTests || (widget.item.testResultCount > 0)) {
|
||||
tiles.add(
|
||||
ListTile(
|
||||
title: Text(L10().testResults),
|
||||
leading: FaIcon(FontAwesomeIcons.listCheck, color: COLOR_ACTION),
|
||||
trailing: Text("${widget.item.testResultCount}"),
|
||||
onTap: () {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => StockItemTestResultsWidget(widget.item))
|
||||
).then((ctx) {
|
||||
refresh(context);
|
||||
});
|
||||
}
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if (widget.item.hasPurchasePrice) {
|
||||
tiles.add(
|
||||
ListTile(
|
||||
title: Text(L10().purchasePrice),
|
||||
leading: FaIcon(FontAwesomeIcons.dollarSign),
|
||||
trailing: Text(
|
||||
renderCurrency(widget.item.purchasePrice, widget.item.purchasePriceCurrency)
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
// TODO - Is this stock item linked to a PurchaseOrder?
|
||||
|
||||
if (stockShowHistory && widget.item.trackingItemCount > 0) {
|
||||
tiles.add(
|
||||
ListTile(
|
||||
title: Text(L10().history),
|
||||
leading: FaIcon(FontAwesomeIcons.clockRotateLeft, color: COLOR_ACTION),
|
||||
trailing: Text("${widget.item.trackingItemCount}"),
|
||||
onTap: () {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => StockItemHistoryWidget(widget.item))
|
||||
).then((ctx) {
|
||||
refresh(context);
|
||||
});
|
||||
},
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
// Notes field
|
||||
tiles.add(
|
||||
ListTile(
|
||||
title: Text(L10().notes),
|
||||
leading: FaIcon(FontAwesomeIcons.noteSticky, color: COLOR_ACTION),
|
||||
onTap: () {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(builder: (context) => NotesWidget(widget.item))
|
||||
);
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
tiles.add(
|
||||
ListTile(
|
||||
title: Text(L10().attachments),
|
||||
leading: FaIcon(FontAwesomeIcons.fileLines, color: COLOR_ACTION),
|
||||
trailing: attachmentCount > 0 ? Text(attachmentCount.toString()) : null,
|
||||
onTap: () {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => AttachmentWidget(
|
||||
InvenTreeStockItemAttachment(),
|
||||
widget.item.pk,
|
||||
widget.item.canEdit,
|
||||
)
|
||||
)
|
||||
);
|
||||
},
|
||||
)
|
||||
);
|
||||
|
||||
return tiles;
|
||||
}
|
||||
|
||||
}
|
94
lib/widget/stock/stock_item_history.dart
Normal file
94
lib/widget/stock/stock_item_history.dart
Normal file
@ -0,0 +1,94 @@
|
||||
import "package:flutter/material.dart";
|
||||
|
||||
import "package:inventree/api.dart";
|
||||
import "package:inventree/l10.dart";
|
||||
import "package:inventree/inventree/stock.dart";
|
||||
import "package:inventree/inventree/model.dart";
|
||||
|
||||
import "package:inventree/widget/paginator.dart";
|
||||
import "package:inventree/widget/refreshable_state.dart";
|
||||
|
||||
class StockItemHistoryWidget extends StatefulWidget {
|
||||
const StockItemHistoryWidget(this.item, {Key? key}) : super(key: key);
|
||||
|
||||
final InvenTreeStockItem item;
|
||||
|
||||
@override
|
||||
_StockItemHistoryDisplayState createState() => _StockItemHistoryDisplayState(item);
|
||||
}
|
||||
|
||||
class _StockItemHistoryDisplayState extends RefreshableState<StockItemHistoryWidget> {
|
||||
_StockItemHistoryDisplayState(this.item);
|
||||
|
||||
final InvenTreeStockItem item;
|
||||
|
||||
@override
|
||||
String getAppBarTitle() => L10().stockItemHistory;
|
||||
|
||||
@override
|
||||
List<Widget> appBarActions(BuildContext context) => [];
|
||||
|
||||
@override
|
||||
Widget getBody(BuildContext context) {
|
||||
Map<String, String> filters = {
|
||||
"item": widget.item.pk.toString(),
|
||||
};
|
||||
|
||||
return PaginatedStockHistoryList(filters);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* Widget which displays a paginated stock history list
|
||||
*/
|
||||
class PaginatedStockHistoryList extends PaginatedSearchWidget {
|
||||
const PaginatedStockHistoryList(Map<String, String> filters) : super(filters: filters);
|
||||
|
||||
@override
|
||||
String get searchTitle => L10().stockItemHistory;
|
||||
|
||||
@override
|
||||
_PaginatedStockHistoryState createState() => _PaginatedStockHistoryState();
|
||||
}
|
||||
|
||||
/*
|
||||
* State class for the paginated stock history list
|
||||
*/
|
||||
class _PaginatedStockHistoryState
|
||||
extends PaginatedSearchState<PaginatedStockHistoryList> {
|
||||
_PaginatedStockHistoryState() : super();
|
||||
|
||||
@override
|
||||
String get prefix => "stock_history";
|
||||
|
||||
@override
|
||||
Map<String, String> get orderingOptions => {};
|
||||
|
||||
@override
|
||||
Map<String, Map<String, dynamic>> get filterOptions => {
|
||||
// TODO: Add filter options
|
||||
};
|
||||
|
||||
@override
|
||||
Future<InvenTreePageResponse?> requestPage(
|
||||
int limit, int offset, Map<String, String> params) async {
|
||||
await InvenTreeAPI().StockHistoryStatus.load();
|
||||
|
||||
final page = await InvenTreeStockItemHistory().listPaginated(limit, offset, filters: params);
|
||||
|
||||
return page;
|
||||
}
|
||||
|
||||
@override
|
||||
Widget buildItem(BuildContext context, InvenTreeModel model) {
|
||||
InvenTreeStockItemHistory entry = model as InvenTreeStockItemHistory;
|
||||
|
||||
return ListTile(
|
||||
leading: Text(entry.dateString),
|
||||
trailing: entry.userString.isNotEmpty ? Text(entry.userString) : null,
|
||||
title: Text(entry.label),
|
||||
subtitle: entry.notes.isNotEmpty ? Text(entry.notes) : null,
|
||||
);
|
||||
}
|
||||
}
|
233
lib/widget/stock/stock_item_test_results.dart
Normal file
233
lib/widget/stock/stock_item_test_results.dart
Normal file
@ -0,0 +1,233 @@
|
||||
import "package:flutter/material.dart";
|
||||
import "package:flutter_speed_dial/flutter_speed_dial.dart";
|
||||
import "package:font_awesome_flutter/font_awesome_flutter.dart";
|
||||
|
||||
import "package:inventree/api.dart";
|
||||
import "package:inventree/app_colors.dart";
|
||||
import "package:inventree/l10.dart";
|
||||
|
||||
import "package:inventree/inventree/part.dart";
|
||||
import "package:inventree/inventree/stock.dart";
|
||||
import "package:inventree/inventree/model.dart";
|
||||
|
||||
import "package:inventree/widget/progress.dart";
|
||||
import "package:inventree/widget/refreshable_state.dart";
|
||||
|
||||
|
||||
class StockItemTestResultsWidget extends StatefulWidget {
|
||||
|
||||
const StockItemTestResultsWidget(this.item, {Key? key}) : super(key: key);
|
||||
|
||||
final InvenTreeStockItem item;
|
||||
|
||||
@override
|
||||
_StockItemTestResultDisplayState createState() => _StockItemTestResultDisplayState(item);
|
||||
}
|
||||
|
||||
|
||||
class _StockItemTestResultDisplayState extends RefreshableState<StockItemTestResultsWidget> {
|
||||
|
||||
_StockItemTestResultDisplayState(this.item);
|
||||
|
||||
@override
|
||||
String getAppBarTitle() => L10().testResults;
|
||||
|
||||
@override
|
||||
List<Widget> appBarActions(BuildContext context) => [];
|
||||
|
||||
@override
|
||||
List<SpeedDialChild> actionButtons(BuildContext context) {
|
||||
List<SpeedDialChild> actions = [];
|
||||
|
||||
if (InvenTreeStockItemTestResult().canCreate) {
|
||||
actions.add(
|
||||
SpeedDialChild(
|
||||
child: FaIcon(FontAwesomeIcons.circlePlus),
|
||||
label: L10().testResultAdd,
|
||||
onTap: () {
|
||||
addTestResult(context);
|
||||
}
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
return actions;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> request(BuildContext context) async {
|
||||
await item.getTestTemplates();
|
||||
await item.getTestResults();
|
||||
}
|
||||
|
||||
final InvenTreeStockItem item;
|
||||
|
||||
Future <void> addTestResult(BuildContext context, {String name = "", bool nameIsEditable = true, bool result = false, String value = "", bool valueRequired = false, bool attachmentRequired = false}) async {
|
||||
|
||||
InvenTreeStockItemTestResult().createForm(
|
||||
context,
|
||||
L10().testResultAdd,
|
||||
data: {
|
||||
"stock_item": "${item.pk}",
|
||||
"test": "${name}",
|
||||
},
|
||||
onSuccess: (data) {
|
||||
refresh(context);
|
||||
},
|
||||
fileField: "attachment",
|
||||
);
|
||||
}
|
||||
|
||||
// Squish together templates and results
|
||||
List<InvenTreeModel> getTestResults() {
|
||||
var templates = item.testTemplates;
|
||||
var results = item.testResults;
|
||||
|
||||
List<InvenTreeModel> outputs = [];
|
||||
|
||||
// Add each template to the list
|
||||
for (var t in templates) {
|
||||
outputs.add(t);
|
||||
}
|
||||
|
||||
// Add each result (compare to existing items / templates
|
||||
for (var result in results) {
|
||||
bool match = false;
|
||||
|
||||
for (var ii = 0; ii < outputs.length; ii++) {
|
||||
|
||||
// Check against templates
|
||||
if (outputs[ii] is InvenTreePartTestTemplate) {
|
||||
var t = outputs[ii] as InvenTreePartTestTemplate;
|
||||
|
||||
if (result.key == t.key) {
|
||||
t.results.add(result);
|
||||
match = true;
|
||||
break;
|
||||
}
|
||||
} else if (outputs[ii] is InvenTreeStockItemTestResult) {
|
||||
var r = outputs[ii] as InvenTreeStockItemTestResult;
|
||||
|
||||
if (r.key == result.key) {
|
||||
// Overwrite with a newer result
|
||||
outputs[ii] = result;
|
||||
match = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!match) {
|
||||
outputs.add(result);
|
||||
}
|
||||
}
|
||||
|
||||
return outputs;
|
||||
}
|
||||
|
||||
@override
|
||||
List<Widget> getTiles(BuildContext context) {
|
||||
List<Widget> tiles = [];
|
||||
|
||||
tiles.add(
|
||||
Card(
|
||||
child: ListTile(
|
||||
title: Text(item.partName),
|
||||
subtitle: Text(item.partDescription),
|
||||
leading: InvenTreeAPI().getThumbnail(item.partImage),
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
tiles.add(
|
||||
ListTile(
|
||||
title: Text(L10().testResults,
|
||||
style: TextStyle(fontWeight: FontWeight.bold)
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
if (loading) {
|
||||
tiles.add(progressIndicator());
|
||||
return tiles;
|
||||
}
|
||||
|
||||
var results = getTestResults();
|
||||
|
||||
if (results.isEmpty) {
|
||||
tiles.add(ListTile(
|
||||
title: Text(L10().testResultNone),
|
||||
subtitle: Text(L10().testResultNoneDetail),
|
||||
));
|
||||
|
||||
return tiles;
|
||||
}
|
||||
|
||||
for (var item in results) {
|
||||
|
||||
bool _hasResult = false;
|
||||
bool _required = false;
|
||||
String _test = "";
|
||||
bool _result = false;
|
||||
String _value = "";
|
||||
String _notes = "";
|
||||
|
||||
FaIcon _icon = FaIcon(FontAwesomeIcons.circleQuestion, color: Colors.lightBlue);
|
||||
bool _valueRequired = false;
|
||||
bool _attachmentRequired = false;
|
||||
|
||||
if (item is InvenTreePartTestTemplate) {
|
||||
_result = item.passFailStatus();
|
||||
_test = item.testName;
|
||||
_required = item.required;
|
||||
_value = item.latestResult()?.value ?? L10().noResults;
|
||||
_valueRequired = item.requiresValue;
|
||||
_attachmentRequired = item.requiresAttachment;
|
||||
_notes = item.latestResult()?.notes ?? item.description;
|
||||
_hasResult = item.latestResult() != null;
|
||||
} else if (item is InvenTreeStockItemTestResult) {
|
||||
_result = item.result;
|
||||
_test = item.testName;
|
||||
_required = false;
|
||||
_value = item.value;
|
||||
_notes = item.notes;
|
||||
_hasResult = true;
|
||||
}
|
||||
|
||||
if (!_hasResult) {
|
||||
_icon = FaIcon(FontAwesomeIcons.circleQuestion, color: Colors.blue);
|
||||
} else if (_result == true) {
|
||||
_icon = FaIcon(FontAwesomeIcons.circleCheck, color: COLOR_SUCCESS);
|
||||
} else if (_result == false) {
|
||||
_icon = FaIcon(FontAwesomeIcons.circleXmark, color: COLOR_DANGER);
|
||||
}
|
||||
|
||||
tiles.add(ListTile(
|
||||
title: Text(_test, style: TextStyle(
|
||||
fontWeight: _required ? FontWeight.bold : FontWeight.normal,
|
||||
fontStyle: _hasResult ? FontStyle.normal : FontStyle.italic
|
||||
)),
|
||||
subtitle: Text(_notes),
|
||||
trailing: Text(_value),
|
||||
leading: _icon,
|
||||
onTap: () {
|
||||
addTestResult(
|
||||
context,
|
||||
name: _test,
|
||||
nameIsEditable: !_required,
|
||||
valueRequired: _valueRequired,
|
||||
attachmentRequired: _attachmentRequired
|
||||
);
|
||||
}
|
||||
));
|
||||
}
|
||||
|
||||
if (tiles.isEmpty) {
|
||||
tiles.add(ListTile(
|
||||
title: Text(L10().testResultNone),
|
||||
));
|
||||
}
|
||||
|
||||
return tiles;
|
||||
}
|
||||
}
|
150
lib/widget/stock/stock_list.dart
Normal file
150
lib/widget/stock/stock_list.dart
Normal file
@ -0,0 +1,150 @@
|
||||
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/widget/stock/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() => L10().stockItems;
|
||||
|
||||
@override
|
||||
Widget getBody(BuildContext context) {
|
||||
return PaginatedStockItemList(filters);
|
||||
}
|
||||
}
|
||||
|
||||
class PaginatedStockItemList extends PaginatedSearchWidget {
|
||||
|
||||
const PaginatedStockItemList(Map<String, String> filters) : super(filters: filters);
|
||||
|
||||
@override
|
||||
String get searchTitle => L10().stockItems;
|
||||
|
||||
@override
|
||||
_PaginatedStockItemListState createState() => _PaginatedStockItemListState();
|
||||
|
||||
}
|
||||
|
||||
|
||||
class _PaginatedStockItemListState extends PaginatedSearchState<PaginatedStockItemList> {
|
||||
|
||||
_PaginatedStockItemListState() : super();
|
||||
|
||||
@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
|
||||
Map<String, Map<String, dynamic>> get filterOptions {
|
||||
Map<String, Map<String, dynamic>> filters = {
|
||||
"available": {
|
||||
"default": null,
|
||||
"label": L10().available,
|
||||
"help_text": L10().availableStock,
|
||||
"tristate": true,
|
||||
},
|
||||
"in_stock": {
|
||||
"default": true,
|
||||
"label": L10().filterInStock,
|
||||
"help_text": L10().filterInStockDetail,
|
||||
"tristate": true,
|
||||
},
|
||||
"cascade": {
|
||||
"default": false,
|
||||
"label": L10().includeSublocations,
|
||||
"help_text": L10().includeSublocationsDetail,
|
||||
"tristate": false,
|
||||
},
|
||||
"external": {
|
||||
"default": null,
|
||||
"label": L10().filterExternal,
|
||||
"help_text": L10().filterExternalDetail,
|
||||
"tristate": true,
|
||||
},
|
||||
"serialized": {
|
||||
"label": L10().filterSerialized,
|
||||
"help_text": L10().filterSerializedDetail,
|
||||
},
|
||||
"status": {
|
||||
"label": L10().status,
|
||||
"help_text": L10().statusCode,
|
||||
"choices": InvenTreeAPI().StockStatus.choices,
|
||||
}
|
||||
};
|
||||
|
||||
if (!InvenTreeAPI().supportsStatusLabelEndpoints) {
|
||||
filters.remove("status");
|
||||
}
|
||||
|
||||
return filters;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<InvenTreePageResponse?> requestPage(int limit, int offset, Map<String, String> params) async {
|
||||
|
||||
// Ensure StockStatus codes are loaded
|
||||
await InvenTreeAPI().StockStatus.load();
|
||||
|
||||
final page = await InvenTreeStockItem().listPaginated(
|
||||
limit,
|
||||
offset,
|
||||
filters: params
|
||||
);
|
||||
|
||||
return page;
|
||||
}
|
||||
|
||||
@override
|
||||
Widget buildItem(BuildContext context, InvenTreeModel model) {
|
||||
|
||||
InvenTreeStockItem item = model as InvenTreeStockItem;
|
||||
|
||||
return ListTile(
|
||||
title: Text("${item.partName}"),
|
||||
subtitle: Text("${item.locationPathString}"),
|
||||
leading: InvenTreeAPI().getThumbnail(item.partThumbnail),
|
||||
trailing: Text("${item.displayQuantity}",
|
||||
style: TextStyle(
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 16,
|
||||
color: InvenTreeAPI().StockStatus.color(item.status),
|
||||
),
|
||||
),
|
||||
onTap: () {
|
||||
Navigator.push(context, MaterialPageRoute(builder: (context) => StockDetailWidget(item)));
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user