mirror of
https://github.com/inventree/inventree-app.git
synced 2025-06-15 03:35:28 +00:00
[refactor] Scan improvements (#577)
* Handle error on unexpected barcode response * Add ManufacturerPart detail view * Support barcode scanning for manufacturer part * Refactoring for null checks * Ignore selected errors in sentry * Fix API implementation for ManufacturerPart * Update release notes * More error handling * Decode quantity betterer * Refactoring * Add option to confirm checkin details * Improve response handlign * Cleanup * Remove unused imports * Fix async function * Fix for assigning custom barcode * Handle barcode scan result for company * Fix * Adjust scan priority * Refactoring MODEL_TYPE - Use instead of duplicated const strings * @override fix
This commit is contained in:
183
lib/widget/company/manufacturer_part_detail.dart
Normal file
183
lib/widget/company/manufacturer_part_detail.dart
Normal file
@ -0,0 +1,183 @@
|
||||
|
||||
import "package:flutter/material.dart";
|
||||
import "package:flutter_speed_dial/flutter_speed_dial.dart";
|
||||
import "package:flutter_tabler_icons/flutter_tabler_icons.dart";
|
||||
|
||||
import "package:inventree/l10.dart";
|
||||
import "package:inventree/api.dart";
|
||||
import "package:inventree/app_colors.dart";
|
||||
|
||||
import "package:inventree/inventree/company.dart";
|
||||
import "package:inventree/inventree/part.dart";
|
||||
|
||||
import "package:inventree/widget/refreshable_state.dart";
|
||||
import "package:inventree/widget/snacks.dart";
|
||||
import "package:inventree/widget/progress.dart";
|
||||
|
||||
import "package:inventree/widget/part/part_detail.dart";
|
||||
import "package:inventree/widget/company/company_detail.dart";
|
||||
import "package:url_launcher/url_launcher.dart";
|
||||
|
||||
/*
|
||||
* Detail widget for viewing a single ManufacturerPart instance
|
||||
*/
|
||||
class ManufacturerPartDetailWidget extends StatefulWidget {
|
||||
|
||||
const ManufacturerPartDetailWidget(this.manufacturerPart, {Key? key})
|
||||
: super(key: key);
|
||||
|
||||
final InvenTreeManufacturerPart manufacturerPart;
|
||||
|
||||
@override
|
||||
_ManufacturerPartDisplayState createState() => _ManufacturerPartDisplayState();
|
||||
}
|
||||
|
||||
|
||||
class _ManufacturerPartDisplayState extends RefreshableState<ManufacturerPartDetailWidget> {
|
||||
|
||||
_ManufacturerPartDisplayState();
|
||||
|
||||
@override
|
||||
String getAppBarTitle() => L10().manufacturerPart;
|
||||
|
||||
@override
|
||||
Future<void> request(BuildContext context) async {
|
||||
final bool result = widget.manufacturerPart.pk > 0 &&
|
||||
await widget.manufacturerPart.reload();
|
||||
|
||||
if (!result) {
|
||||
Navigator.of(context).pop();
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> editManufacturerPart(BuildContext context) async {
|
||||
widget.manufacturerPart.editForm(
|
||||
context,
|
||||
L10().manufacturerPartEdit,
|
||||
onSuccess: (data) async {
|
||||
refresh(context);
|
||||
showSnackIcon(L10().itemUpdated, success: true);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
List<SpeedDialChild> barcodeButtons(BuildContext context) {
|
||||
List<SpeedDialChild> actions = [];
|
||||
|
||||
// TODO: Barcode actions?
|
||||
|
||||
return actions;
|
||||
}
|
||||
|
||||
@override
|
||||
List<Widget> appBarActions(BuildContext context) {
|
||||
List<Widget> actions = [];
|
||||
|
||||
if (widget.manufacturerPart.canEdit) {
|
||||
actions.add(
|
||||
IconButton(
|
||||
icon: Icon(TablerIcons.edit),
|
||||
tooltip: L10().edit,
|
||||
onPressed: () {
|
||||
editManufacturerPart(context);
|
||||
}
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
return actions;
|
||||
}
|
||||
|
||||
/*
|
||||
* Build a set of tiles to display for this ManufacturerPart instance
|
||||
*/
|
||||
@override
|
||||
List<Widget> getTiles(BuildContext context) {
|
||||
List<Widget> tiles = [];
|
||||
|
||||
if (loading) {
|
||||
tiles.add(progressIndicator());
|
||||
return tiles;
|
||||
}
|
||||
|
||||
// Internal Part
|
||||
tiles.add(
|
||||
ListTile(
|
||||
title: Text(L10().internalPart),
|
||||
subtitle: Text(widget.manufacturerPart.partName),
|
||||
leading: Icon(TablerIcons.box, color: COLOR_ACTION),
|
||||
trailing: InvenTreeAPI().getThumbnail(widget.manufacturerPart.partImage),
|
||||
onTap: () async {
|
||||
showLoadingOverlay();
|
||||
final part = await InvenTreePart().get(widget.manufacturerPart.partId);
|
||||
hideLoadingOverlay();
|
||||
|
||||
if (part is InvenTreePart) {
|
||||
Navigator.push(context, MaterialPageRoute(
|
||||
builder: (context) => PartDetailWidget(part)));
|
||||
}
|
||||
},
|
||||
)
|
||||
);
|
||||
|
||||
// Manufacturer details
|
||||
tiles.add(
|
||||
ListTile(
|
||||
title: Text(L10().manufacturer),
|
||||
subtitle: Text(widget.manufacturerPart.manufacturerName),
|
||||
leading: Icon(TablerIcons.building_factory_2, color: COLOR_ACTION),
|
||||
trailing: InvenTreeAPI().getThumbnail(widget.manufacturerPart.manufacturerImage),
|
||||
onTap: () async {
|
||||
showLoadingOverlay();
|
||||
var supplier = await InvenTreeCompany().get(widget.manufacturerPart.manufacturerId);
|
||||
hideLoadingOverlay();
|
||||
|
||||
if (supplier is InvenTreeCompany) {
|
||||
Navigator.push(context, MaterialPageRoute(
|
||||
builder: (context) => CompanyDetailWidget(supplier)
|
||||
));
|
||||
}
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
// MPN (part number)
|
||||
tiles.add(
|
||||
ListTile(
|
||||
title: Text(L10().manufacturerPartNumber),
|
||||
subtitle: Text(widget.manufacturerPart.MPN),
|
||||
leading: Icon(TablerIcons.hash),
|
||||
)
|
||||
);
|
||||
|
||||
// Description
|
||||
if (widget.manufacturerPart.description.isNotEmpty) {
|
||||
tiles.add(
|
||||
ListTile(
|
||||
title: Text(L10().description),
|
||||
subtitle: Text(widget.manufacturerPart.description),
|
||||
leading: Icon(TablerIcons.info_circle),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if (widget.manufacturerPart.link.isNotEmpty) {
|
||||
tiles.add(
|
||||
ListTile(
|
||||
title: Text(widget.manufacturerPart.link),
|
||||
leading: Icon(TablerIcons.link, color: COLOR_ACTION),
|
||||
onTap: () async {
|
||||
var uri = Uri.tryParse(widget.manufacturerPart.link);
|
||||
if (uri != null && await canLaunchUrl(uri)) {
|
||||
await launchUrl(uri);
|
||||
}
|
||||
},
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
return tiles;
|
||||
}
|
||||
|
||||
}
|
@ -1,21 +1,23 @@
|
||||
import "package:flutter/material.dart";
|
||||
import "package:flutter_speed_dial/flutter_speed_dial.dart";
|
||||
import "package:flutter_tabler_icons/flutter_tabler_icons.dart";
|
||||
import "package:url_launcher/url_launcher.dart";
|
||||
|
||||
import "package:inventree/api.dart";
|
||||
import "package:inventree/app_colors.dart";
|
||||
import "package:inventree/barcode/barcode.dart";
|
||||
import "package:inventree/l10.dart";
|
||||
|
||||
import "package:inventree/barcode/barcode.dart";
|
||||
|
||||
import "package:inventree/inventree/part.dart";
|
||||
import "package:inventree/inventree/company.dart";
|
||||
|
||||
import "package:inventree/widget/company/company_detail.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:url_launcher/url_launcher.dart";
|
||||
import "package:inventree/widget/company/company_detail.dart";
|
||||
import "package:inventree/widget/company/manufacturer_part_detail.dart";
|
||||
import "package:inventree/widget/part/part_detail.dart";
|
||||
|
||||
|
||||
/*
|
||||
@ -180,7 +182,7 @@ class _SupplierPartDisplayState extends RefreshableState<SupplierPartDetailWidge
|
||||
ListTile(
|
||||
title: Text(L10().supplierPartNumber),
|
||||
subtitle: Text(widget.supplierPart.SKU),
|
||||
leading: Icon(TablerIcons.barcode),
|
||||
leading: Icon(TablerIcons.hash),
|
||||
)
|
||||
);
|
||||
|
||||
@ -210,7 +212,18 @@ class _SupplierPartDisplayState extends RefreshableState<SupplierPartDetailWidge
|
||||
ListTile(
|
||||
title: Text(L10().manufacturerPartNumber),
|
||||
subtitle: Text(widget.supplierPart.MPN),
|
||||
leading: Icon(TablerIcons.barcode),
|
||||
leading: Icon(TablerIcons.hash, color: COLOR_ACTION),
|
||||
onTap: () async {
|
||||
showLoadingOverlay();
|
||||
var manufacturerPart = await InvenTreeManufacturerPart().get(widget.supplierPart.manufacturerPartId);
|
||||
hideLoadingOverlay();
|
||||
|
||||
if (manufacturerPart is InvenTreeManufacturerPart) {
|
||||
Navigator.push(context, MaterialPageRoute(
|
||||
builder: (context) => ManufacturerPartDetailWidget(manufacturerPart)
|
||||
));
|
||||
}
|
||||
},
|
||||
)
|
||||
);
|
||||
}
|
||||
|
@ -2,7 +2,6 @@ import "package:flutter/material.dart";
|
||||
import "package:flutter_speed_dial/flutter_speed_dial.dart";
|
||||
import "package:flutter_tabler_icons/flutter_tabler_icons.dart";
|
||||
|
||||
import "package:inventree/api_form.dart";
|
||||
import "package:inventree/app_colors.dart";
|
||||
import "package:inventree/helpers.dart";
|
||||
import "package:inventree/inventree/model.dart";
|
||||
@ -132,72 +131,15 @@ class _POLineDetailWidgetState extends RefreshableState<POLineDetailWidget> {
|
||||
|
||||
// Launch a form to 'receive' this line item
|
||||
Future<void> receiveLineItem(BuildContext context) async {
|
||||
|
||||
// Pre-fill the "destination" to receive into
|
||||
int destination = widget.item.destinationId;
|
||||
|
||||
if (destination < 0) {
|
||||
destination = (widget.item.orderDetail["destination"] ?? -1) as int;
|
||||
}
|
||||
|
||||
// Construct fields to receive
|
||||
Map<String, dynamic> fields = {
|
||||
"line_item": {
|
||||
"parent": "items",
|
||||
"nested": true,
|
||||
"hidden": true,
|
||||
"value": widget.item.pk,
|
||||
},
|
||||
"quantity": {
|
||||
"parent": "items",
|
||||
"nested": true,
|
||||
"value": widget.item.outstanding,
|
||||
},
|
||||
"status": {
|
||||
"parent": "items",
|
||||
"nested": true,
|
||||
},
|
||||
"location": {},
|
||||
"batch_code": {
|
||||
"parent": "items",
|
||||
"nested": true,
|
||||
},
|
||||
"barcode": {
|
||||
"parent": "items",
|
||||
"nested": true,
|
||||
"type": "barcode",
|
||||
"label": L10().barcodeAssign,
|
||||
"required": false,
|
||||
}
|
||||
};
|
||||
|
||||
if (destination > 0) {
|
||||
fields["location"]?["value"] = destination;
|
||||
}
|
||||
|
||||
showLoadingOverlay();
|
||||
var order = await InvenTreePurchaseOrder().get(widget.item.orderId);
|
||||
hideLoadingOverlay();
|
||||
|
||||
if (order is InvenTreePurchaseOrder) {
|
||||
launchApiForm(
|
||||
widget.item.receive(
|
||||
context,
|
||||
L10().receiveItem,
|
||||
order.receive_url,
|
||||
fields,
|
||||
method: "POST",
|
||||
icon: TablerIcons.transition_right,
|
||||
onSuccess: (data) async {
|
||||
showSnackIcon(L10().receivedItem, success: true);
|
||||
refresh(context);
|
||||
onSuccess: () => {
|
||||
showSnackIcon(L10().receivedItem, success: true),
|
||||
refresh(context)
|
||||
}
|
||||
);
|
||||
} else {
|
||||
showSnackIcon(L10().error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@override
|
||||
List<Widget> getTiles(BuildContext context) {
|
||||
List<Widget> tiles = [];
|
||||
|
@ -239,7 +239,7 @@ class _PartDisplayState extends RefreshableState<PartDetailWidget> {
|
||||
|
||||
if (allowLabelPrinting) {
|
||||
|
||||
String model_type = api.supportsModernLabelPrinting ? InvenTreePart().MODEL_TYPE : "part";
|
||||
String model_type = api.supportsModernLabelPrinting ? InvenTreePart.MODEL_TYPE : "part";
|
||||
String item_key = api.supportsModernLabelPrinting ? "items" : "part";
|
||||
|
||||
_labels = await getLabelTemplates(
|
||||
|
@ -246,7 +246,7 @@ class _LocationDisplayState extends RefreshableState<LocationDisplayWidget> {
|
||||
|
||||
if (widget.location != null) {
|
||||
|
||||
String model_type = api.supportsModernLabelPrinting ? InvenTreeStockLocation().MODEL_TYPE : "location";
|
||||
String model_type = api.supportsModernLabelPrinting ? InvenTreeStockLocation.MODEL_TYPE : "location";
|
||||
String item_key = api.supportsModernLabelPrinting ? "items" : "location";
|
||||
|
||||
_labels = await getLabelTemplates(
|
||||
|
@ -298,7 +298,7 @@ class _StockItemDisplayState extends RefreshableState<StockDetailWidget> {
|
||||
// Request information on labels available for this stock item
|
||||
if (allowLabelPrinting) {
|
||||
|
||||
String model_type = api.supportsModernLabelPrinting ? InvenTreeStockItem().MODEL_TYPE : "stock";
|
||||
String model_type = api.supportsModernLabelPrinting ? InvenTreeStockItem.MODEL_TYPE : "stock";
|
||||
String item_key = api.supportsModernLabelPrinting ? "items" : "item";
|
||||
|
||||
// Clear the existing labels list
|
||||
|
Reference in New Issue
Block a user