mirror of
https://github.com/inventree/inventree-app.git
synced 2026-04-25 19:03:25 +00:00
Build Order (#673)
* WIP * Remove debug msg * Add required roles * More roles * Fix refresh for BuildDetail widget * Add attachments widget * Translated text * Further updates * More translations * Form field updates * Cleanup * Code formatting * Fix duplicate import * formatting * Remove duplicate switch case * Update to match modern app * Improved required parts list * Filtering for build outputs * Display list of allocated stock items * Display source and destination locations * Fix typo * Add build orders to drawer * Fix hard-coded string * Set default filter value * Tweak build fields (remove "notes") * Fixes * Add "start_date" to build edit form * Disable editing of build line * Tweak build item / build detail views * Remove unused func * Remove unused import --------- Co-authored-by: Asterix\Oliver <oliver@currawongeng.com> Co-authored-by: Oliver Walters <oliver.henry.walters@gmail.com>
This commit is contained in:
@@ -0,0 +1,610 @@
|
||||
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.dart";
|
||||
import "package:inventree/app_colors.dart";
|
||||
import "package:inventree/inventree/stock.dart";
|
||||
import "package:inventree/l10.dart";
|
||||
|
||||
import "package:inventree/inventree/build.dart";
|
||||
import "package:inventree/inventree/part.dart";
|
||||
import "package:inventree/widget/attachment_widget.dart";
|
||||
|
||||
import "package:inventree/widget/dialogs.dart";
|
||||
import "package:inventree/widget/link_icon.dart";
|
||||
import "package:inventree/widget/notes_widget.dart";
|
||||
import "package:inventree/widget/refreshable_state.dart";
|
||||
import "package:inventree/widget/build/build_line_list.dart";
|
||||
import "package:inventree/widget/build/build_item_list.dart";
|
||||
import "package:inventree/widget/build/build_output_list.dart";
|
||||
|
||||
/*
|
||||
* Widget for viewing a single BuildOrder instance
|
||||
*/
|
||||
class BuildOrderDetailWidget extends StatefulWidget {
|
||||
const BuildOrderDetailWidget(this.order, {Key? key}) : super(key: key);
|
||||
|
||||
final InvenTreeBuildOrder order;
|
||||
|
||||
@override
|
||||
_BuildOrderDetailState createState() => _BuildOrderDetailState();
|
||||
}
|
||||
|
||||
class _BuildOrderDetailState extends RefreshableState<BuildOrderDetailWidget> {
|
||||
_BuildOrderDetailState();
|
||||
|
||||
// Track state of the build order
|
||||
int allocatedLineCount = 0;
|
||||
int totalLineCount = 0;
|
||||
int outputCount = 0;
|
||||
int attachmentCount = 0;
|
||||
|
||||
bool showCameraShortcut = true;
|
||||
|
||||
InvenTreeStockLocation? sourceLocation;
|
||||
InvenTreeStockLocation? destinationLocation;
|
||||
|
||||
@override
|
||||
String getAppBarTitle() {
|
||||
String title = L10().buildOrder;
|
||||
|
||||
if (widget.order.reference.isNotEmpty) {
|
||||
title += " - ${widget.order.reference}";
|
||||
}
|
||||
|
||||
return title;
|
||||
}
|
||||
|
||||
@override
|
||||
List<Widget> appBarActions(BuildContext context) {
|
||||
List<Widget> actions = [];
|
||||
|
||||
if (widget.order.canEdit) {
|
||||
actions.add(
|
||||
IconButton(
|
||||
icon: const Icon(TablerIcons.edit),
|
||||
tooltip: L10().buildOrderEdit,
|
||||
onPressed: () {
|
||||
editOrder(context);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return actions;
|
||||
}
|
||||
|
||||
@override
|
||||
List<SpeedDialChild> actionButtons(BuildContext context) {
|
||||
List<SpeedDialChild> actions = [];
|
||||
|
||||
// Image upload shortcut
|
||||
if (showCameraShortcut && widget.order.canEdit) {
|
||||
actions.add(
|
||||
SpeedDialChild(
|
||||
child: const Icon(TablerIcons.camera, color: Colors.blue),
|
||||
label: L10().takePicture,
|
||||
onTap: () async {
|
||||
_uploadImage(context);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// Add actions based on current build order state
|
||||
if (widget.order.canEdit) {
|
||||
// Issue action (for pending build orders)
|
||||
if (widget.order.canIssue) {
|
||||
actions.add(
|
||||
SpeedDialChild(
|
||||
child: const Icon(TablerIcons.send, color: Colors.blue),
|
||||
label: L10().issueOrder,
|
||||
onTap: () async {
|
||||
_issueOrder(context);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// Complete action (for in-progress build orders with outputs)
|
||||
if (widget.order.canCompleteOrder) {
|
||||
actions.add(
|
||||
SpeedDialChild(
|
||||
child: const Icon(TablerIcons.check, color: Colors.green),
|
||||
label: L10().completeOrder,
|
||||
onTap: () async {
|
||||
_completeOrder(context);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// Hold action
|
||||
if (widget.order.canHold) {
|
||||
actions.add(
|
||||
SpeedDialChild(
|
||||
child: const Icon(TablerIcons.player_pause, color: Colors.orange),
|
||||
label: L10().holdOrder,
|
||||
onTap: () async {
|
||||
_holdOrder(context);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// Auto-allocate action (for in-progress build orders)
|
||||
if (widget.order.isInProgress) {
|
||||
actions.add(
|
||||
SpeedDialChild(
|
||||
child: const Icon(
|
||||
TablerIcons.arrow_autofit_down,
|
||||
color: Colors.purple,
|
||||
),
|
||||
label: L10().allocateAuto,
|
||||
onTap: () async {
|
||||
_autoAllocate(context);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// Unallocate action (if there are allocated items)
|
||||
if (widget.order.isInProgress &&
|
||||
widget.order.allocatedLineItemCount > 0) {
|
||||
actions.add(
|
||||
SpeedDialChild(
|
||||
child: const Icon(TablerIcons.arrow_autofit_up, color: Colors.red),
|
||||
label: L10().unallocateStock,
|
||||
onTap: () async {
|
||||
_unallocateAll(context);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// Cancel action
|
||||
if (widget.order.canCancel) {
|
||||
actions.add(
|
||||
SpeedDialChild(
|
||||
child: const Icon(TablerIcons.circle_x, color: Colors.red),
|
||||
label: L10().cancelOrder,
|
||||
onTap: () async {
|
||||
_cancelOrder(context);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return actions;
|
||||
}
|
||||
|
||||
/// Upload an image against the current BuildOrder
|
||||
Future<void> _uploadImage(BuildContext context) async {
|
||||
// Implement image upload when attachment classes are created
|
||||
// Placeholder for now
|
||||
}
|
||||
|
||||
/// Issue this build order
|
||||
Future<void> _issueOrder(BuildContext context) async {
|
||||
confirmationDialog(
|
||||
L10().issueOrder,
|
||||
L10().issueOrderConfirm,
|
||||
icon: TablerIcons.send,
|
||||
color: Colors.blue,
|
||||
acceptText: L10().issue,
|
||||
onAccept: () async {
|
||||
widget.order.issue().then((dynamic) {
|
||||
refresh(context);
|
||||
});
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
/// Complete this build order
|
||||
Future<void> _completeOrder(BuildContext context) async {
|
||||
confirmationDialog(
|
||||
L10().completeOrder,
|
||||
L10().completeOrderConfirm,
|
||||
icon: TablerIcons.check,
|
||||
color: Colors.green,
|
||||
acceptText: L10().complete,
|
||||
onAccept: () async {
|
||||
widget.order.completeOrder().then((dynamic) {
|
||||
refresh(context);
|
||||
});
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
/// Hold this build order
|
||||
Future<void> _holdOrder(BuildContext context) async {
|
||||
confirmationDialog(
|
||||
L10().holdOrder,
|
||||
L10().holdOrderConfirm,
|
||||
icon: TablerIcons.player_pause,
|
||||
color: Colors.orange,
|
||||
acceptText: L10().hold,
|
||||
onAccept: () async {
|
||||
widget.order.hold().then((dynamic) {
|
||||
refresh(context);
|
||||
});
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
/// Cancel this build order
|
||||
Future<void> _cancelOrder(BuildContext context) async {
|
||||
confirmationDialog(
|
||||
L10().cancelOrder,
|
||||
L10().cancelOrderConfirm,
|
||||
icon: TablerIcons.circle_x,
|
||||
color: Colors.red,
|
||||
acceptText: L10().cancel,
|
||||
onAccept: () async {
|
||||
widget.order.cancel().then((dynamic) {
|
||||
refresh(context);
|
||||
});
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
/// Auto allocate stock items for this build order
|
||||
Future<void> _autoAllocate(BuildContext context) async {
|
||||
confirmationDialog(
|
||||
L10().allocateAuto,
|
||||
L10().allocateAutoDetail,
|
||||
icon: TablerIcons.arrow_autofit_down,
|
||||
color: Colors.purple,
|
||||
acceptText: L10().allocate,
|
||||
onAccept: () async {
|
||||
widget.order.autoAllocate().then((dynamic) {
|
||||
refresh(context);
|
||||
});
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
/// Unallocate all stock from this build order
|
||||
Future<void> _unallocateAll(BuildContext context) async {
|
||||
confirmationDialog(
|
||||
L10().unallocateStock,
|
||||
L10().buildOrderUnallocateDetail,
|
||||
icon: TablerIcons.trash,
|
||||
color: Colors.orange,
|
||||
acceptText: L10().unallocate,
|
||||
onAccept: () async {
|
||||
widget.order.unallocateAll().then((dynamic) {
|
||||
refresh(context);
|
||||
});
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
List<SpeedDialChild> barcodeButtons(BuildContext context) {
|
||||
// Build orders don't have barcode functionality yet
|
||||
return [];
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> request(BuildContext context) async {
|
||||
super.request(context);
|
||||
|
||||
// Refresh the BuildOrder instance
|
||||
await widget.order.reload();
|
||||
|
||||
if (mounted) {
|
||||
setState(() {});
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
if (widget.order.sourceLocationId != null) {
|
||||
InvenTreeStockLocation().get(widget.order.sourceLocationId!).then((
|
||||
value,
|
||||
) {
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
sourceLocation = value as InvenTreeStockLocation?;
|
||||
});
|
||||
}
|
||||
});
|
||||
} else if (mounted) {
|
||||
setState(() {
|
||||
sourceLocation = null;
|
||||
});
|
||||
}
|
||||
|
||||
if (widget.order.destinationId != null) {
|
||||
InvenTreeStockLocation().get(widget.order.destinationId!).then((value) {
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
destinationLocation = value as InvenTreeStockLocation?;
|
||||
});
|
||||
}
|
||||
});
|
||||
} else if (mounted) {
|
||||
setState(() {
|
||||
destinationLocation = null;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/// Edit this build order
|
||||
Future<void> editOrder(BuildContext context) async {
|
||||
if (!widget.order.canEdit) {
|
||||
return;
|
||||
}
|
||||
|
||||
var fields = widget.order.formFields();
|
||||
|
||||
// Cannot edit part field from here
|
||||
fields.remove("part");
|
||||
|
||||
widget.order.editForm(
|
||||
context,
|
||||
L10().buildOrderEdit,
|
||||
fields: fields,
|
||||
onSuccess: (data) async {
|
||||
refresh(context);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
/// Header tile for the build order
|
||||
Widget headerTile(BuildContext context) {
|
||||
return Card(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(
|
||||
widget.order.reference,
|
||||
style: const TextStyle(fontSize: 20, fontWeight: FontWeight.bold),
|
||||
),
|
||||
Text(
|
||||
BuildOrderStatus.getStatusText(widget.order.status),
|
||||
style: TextStyle(
|
||||
color: BuildOrderStatus.getStatusColor(widget.order.status),
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// Build the list of order detail tiles
|
||||
List<Widget> orderTiles(BuildContext context) {
|
||||
List<Widget> tiles = [];
|
||||
|
||||
// Header tile
|
||||
tiles.add(headerTile(context));
|
||||
|
||||
// Part information
|
||||
if (widget.order.partDetail != null) {
|
||||
InvenTreePart part = widget.order.partDetail!;
|
||||
|
||||
tiles.add(
|
||||
ListTile(
|
||||
title: Text(part.name),
|
||||
subtitle: Text(part.description),
|
||||
leading: part.thumbnail.isNotEmpty
|
||||
? SizedBox(
|
||||
width: 32,
|
||||
height: 32,
|
||||
child: InvenTreeAPI().getThumbnail(part.thumbnail),
|
||||
)
|
||||
: const Icon(TablerIcons.box, color: Colors.blue),
|
||||
onTap: () {
|
||||
part.goToDetailPage(context);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// Build quantities
|
||||
tiles.add(
|
||||
ListTile(
|
||||
title: Text(L10().quantity),
|
||||
leading: const Icon(TablerIcons.box),
|
||||
trailing: Text(
|
||||
"${widget.order.completed.toInt()} / ${widget.order.quantity.toInt()}",
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
// Progress bar
|
||||
Color progressColor = Colors.blue;
|
||||
|
||||
if (widget.order.isComplete) {
|
||||
progressColor = Colors.green;
|
||||
} else if (widget.order.targetDate.isNotEmpty &&
|
||||
DateTime.tryParse(widget.order.targetDate) != null &&
|
||||
DateTime.tryParse(widget.order.targetDate)!.isBefore(DateTime.now())) {
|
||||
progressColor = Colors.red;
|
||||
}
|
||||
|
||||
tiles.add(
|
||||
ListTile(
|
||||
title: LinearProgressIndicator(
|
||||
value: widget.order.progressPercent / 100.0,
|
||||
color: progressColor,
|
||||
backgroundColor: const Color(0xFFEEEEEE),
|
||||
),
|
||||
leading: const Icon(TablerIcons.chart_bar),
|
||||
trailing: Text(
|
||||
"${widget.order.progressPercent.toStringAsFixed(1)}%",
|
||||
style: TextStyle(color: progressColor, fontWeight: FontWeight.bold),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
// Line items tile
|
||||
/*
|
||||
* TODO: Reimplement this item
|
||||
Color lineColor = Colors.red;
|
||||
if (widget.order.areAllLinesAllocated) {
|
||||
lineColor = Colors.green;
|
||||
} else if (widget.order.allocatedLineItemCount > 0) {
|
||||
lineColor = Colors.orange;
|
||||
}
|
||||
|
||||
tiles.add(
|
||||
ListTile(
|
||||
title: Text(L10().requiredParts),
|
||||
subtitle: LinearProgressIndicator(
|
||||
value: widget.order.lineItemCount > 0
|
||||
? widget.order.allocatedLineItemCount / widget.order.lineItemCount
|
||||
: 0,
|
||||
color: lineColor,
|
||||
),
|
||||
leading: const Icon(TablerIcons.clipboard_check),
|
||||
trailing: Text(
|
||||
"${widget.order.allocatedLineItemCount} / ${widget.order.lineItemCount}",
|
||||
style: TextStyle(color: lineColor),
|
||||
),
|
||||
),
|
||||
);
|
||||
*/
|
||||
|
||||
// Output items
|
||||
tiles.add(
|
||||
ListTile(
|
||||
title: Text(L10().allocatedStock),
|
||||
leading: Icon(TablerIcons.box_model_2, color: COLOR_ACTION),
|
||||
trailing: LinkIcon(text: widget.order.outputCount.toString()),
|
||||
onTap: () => {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => PaginatedBuildItemWidget(widget.order),
|
||||
),
|
||||
),
|
||||
},
|
||||
),
|
||||
);
|
||||
|
||||
// Source location
|
||||
if (sourceLocation != null) {
|
||||
tiles.add(
|
||||
ListTile(
|
||||
title: Text(L10().sourceLocation),
|
||||
subtitle: Text(sourceLocation!.pathstring),
|
||||
leading: Icon(TablerIcons.sitemap, color: COLOR_ACTION),
|
||||
trailing: LinkIcon(),
|
||||
onTap: () => sourceLocation!.goToDetailPage(context),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// Destination location
|
||||
if (destinationLocation != null) {
|
||||
tiles.add(
|
||||
ListTile(
|
||||
title: Text(L10().destination),
|
||||
subtitle: Text(destinationLocation!.pathstring),
|
||||
leading: Icon(TablerIcons.sitemap, color: COLOR_ACTION),
|
||||
trailing: LinkIcon(),
|
||||
onTap: () => destinationLocation!.goToDetailPage(context),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// Dates
|
||||
if (widget.order.creationDate.isNotEmpty) {
|
||||
tiles.add(
|
||||
ListTile(
|
||||
title: Text(L10().creationDate),
|
||||
trailing: Text(widget.order.creationDate),
|
||||
leading: const Icon(TablerIcons.calendar),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
if (widget.order.startDate.isNotEmpty) {
|
||||
tiles.add(
|
||||
ListTile(
|
||||
title: Text(L10().startDate),
|
||||
trailing: Text(widget.order.startDate),
|
||||
leading: const Icon(TablerIcons.calendar),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
if (widget.order.targetDate.isNotEmpty) {
|
||||
tiles.add(
|
||||
ListTile(
|
||||
title: Text(L10().targetDate),
|
||||
trailing: Text(widget.order.targetDate),
|
||||
leading: const Icon(TablerIcons.calendar),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
if (widget.order.completionDate.isNotEmpty) {
|
||||
tiles.add(
|
||||
ListTile(
|
||||
title: Text(L10().completionDate),
|
||||
trailing: Text(widget.order.completionDate),
|
||||
leading: const Icon(TablerIcons.calendar),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// Notes tile
|
||||
tiles.add(
|
||||
ListTile(
|
||||
title: Text(L10().notes),
|
||||
leading: Icon(TablerIcons.notes, color: COLOR_ACTION),
|
||||
trailing: LinkIcon(),
|
||||
onTap: () {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(builder: (context) => NotesWidget(widget.order)),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
|
||||
// Attachments tile
|
||||
ListTile? attachmentTile = ShowAttachmentsItem(
|
||||
context,
|
||||
InvenTreeBuildOrder.MODEL_TYPE,
|
||||
widget.order.pk,
|
||||
widget.order.reference,
|
||||
attachmentCount,
|
||||
widget.order.canEdit,
|
||||
);
|
||||
|
||||
if (attachmentTile != null) {
|
||||
tiles.add(attachmentTile);
|
||||
}
|
||||
|
||||
return tiles;
|
||||
}
|
||||
|
||||
@override
|
||||
List<Widget> getTabIcons(BuildContext context) {
|
||||
return [
|
||||
Tab(text: L10().details),
|
||||
Tab(text: L10().requiredParts),
|
||||
// Tab(text: L10().allocatedStock),
|
||||
Tab(text: L10().buildOutputs),
|
||||
];
|
||||
}
|
||||
|
||||
@override
|
||||
List<Widget> getTabs(BuildContext context) {
|
||||
return [
|
||||
ListView(children: orderTiles(context)),
|
||||
PaginatedBuildLineList({"build": widget.order.pk.toString()}),
|
||||
// PaginatedBuildItemList({"build": widget.order.pk.toString()}),
|
||||
PaginatedBuildOutputList({"build": widget.order.pk.toString()}),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,218 @@
|
||||
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.dart";
|
||||
import "package:inventree/app_colors.dart";
|
||||
import "package:inventree/l10.dart";
|
||||
|
||||
import "package:inventree/inventree/build.dart";
|
||||
import "package:inventree/inventree/stock.dart";
|
||||
|
||||
import "package:inventree/widget/progress.dart";
|
||||
import "package:inventree/widget/refreshable_state.dart";
|
||||
import "package:inventree/widget/snacks.dart";
|
||||
import "package:inventree/widget/dialogs.dart";
|
||||
|
||||
/*
|
||||
* Widget for displaying detail view of a single BuildItem (stock allocation)
|
||||
*/
|
||||
class BuildItemDetailWidget extends StatefulWidget {
|
||||
const BuildItemDetailWidget(this.item, {Key? key}) : super(key: key);
|
||||
|
||||
final InvenTreeBuildItem item;
|
||||
|
||||
@override
|
||||
_BuildItemDetailWidgetState createState() => _BuildItemDetailWidgetState();
|
||||
}
|
||||
|
||||
/*
|
||||
* State for the BuildItemDetailWidget
|
||||
*/
|
||||
class _BuildItemDetailWidgetState
|
||||
extends RefreshableState<BuildItemDetailWidget> {
|
||||
_BuildItemDetailWidgetState();
|
||||
|
||||
@override
|
||||
String getAppBarTitle() => L10().allocatedItem;
|
||||
|
||||
@override
|
||||
List<Widget> appBarActions(BuildContext context) {
|
||||
List<Widget> actions = [];
|
||||
|
||||
actions.add(
|
||||
IconButton(
|
||||
icon: const Icon(TablerIcons.edit),
|
||||
tooltip: L10().allocationEdit,
|
||||
onPressed: () {
|
||||
_editAllocation(context);
|
||||
},
|
||||
),
|
||||
);
|
||||
|
||||
return actions;
|
||||
}
|
||||
|
||||
@override
|
||||
List<SpeedDialChild> actionButtons(BuildContext context) {
|
||||
List<SpeedDialChild> buttons = [];
|
||||
|
||||
// Unallocate button
|
||||
buttons.add(
|
||||
SpeedDialChild(
|
||||
child: const Icon(TablerIcons.minus, color: Colors.red),
|
||||
label: L10().unallocate,
|
||||
onTap: () async {
|
||||
_unallocateStock(context);
|
||||
},
|
||||
),
|
||||
);
|
||||
|
||||
return buttons;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> request(BuildContext context) async {
|
||||
await widget.item.reload();
|
||||
}
|
||||
|
||||
// Edit this allocation
|
||||
Future<void> _editAllocation(BuildContext context) async {
|
||||
var fields = widget.item.formFields();
|
||||
|
||||
fields["stock_item"]?["hidden"] = true;
|
||||
|
||||
widget.item.editForm(
|
||||
context,
|
||||
L10().allocationEdit,
|
||||
fields: fields,
|
||||
onSuccess: (data) async {
|
||||
refresh(context);
|
||||
showSnackIcon(L10().itemUpdated, success: true);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
// Deallocate this stock item
|
||||
Future<void> _unallocateStock(BuildContext context) async {
|
||||
confirmationDialog(
|
||||
L10().unallocateStock,
|
||||
L10().unallocateStockConfirm,
|
||||
icon: TablerIcons.minus,
|
||||
color: Colors.red,
|
||||
acceptText: L10().unallocate,
|
||||
onAccept: () async {
|
||||
widget.item.delete().then((result) {
|
||||
if (result) {
|
||||
showSnackIcon(L10().stockItemUpdated, success: true);
|
||||
Navigator.pop(context);
|
||||
} else {
|
||||
showSnackIcon(L10().error);
|
||||
}
|
||||
});
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
// Go to stock item detail page
|
||||
Future<void> _viewStockItem(BuildContext context) async {
|
||||
if (widget.item.stockItem != null) {
|
||||
widget.item.stockItem!.goToDetailPage(context);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
List<Widget> getTiles(BuildContext context) {
|
||||
List<Widget> tiles = [];
|
||||
|
||||
// Stock item information
|
||||
if (widget.item.stockItem != null) {
|
||||
tiles.add(
|
||||
ListTile(
|
||||
title: Text(L10().stockItem),
|
||||
subtitle: Text(widget.item.partName),
|
||||
leading: widget.item.partThumbnail.isNotEmpty
|
||||
? SizedBox(
|
||||
width: 32,
|
||||
height: 32,
|
||||
child: InvenTreeAPI().getThumbnail(widget.item.partThumbnail),
|
||||
)
|
||||
: Icon(TablerIcons.box, color: COLOR_ACTION),
|
||||
trailing: Icon(TablerIcons.chevron_right, color: COLOR_ACTION),
|
||||
onTap: () {
|
||||
_viewStockItem(context);
|
||||
},
|
||||
),
|
||||
);
|
||||
|
||||
// Location information
|
||||
tiles.add(
|
||||
ListTile(
|
||||
title: Text(L10().stockLocation),
|
||||
subtitle: Text(
|
||||
widget.item.locationName.isNotEmpty
|
||||
? widget.item.locationPath
|
||||
: L10().locationNotSet,
|
||||
),
|
||||
leading: const Icon(TablerIcons.map_pin),
|
||||
),
|
||||
);
|
||||
|
||||
// Serial number if available
|
||||
if (widget.item.serialNumber.isNotEmpty) {
|
||||
tiles.add(
|
||||
ListTile(
|
||||
title: Text(L10().serialNumber),
|
||||
subtitle: Text(widget.item.serialNumber),
|
||||
leading: const Icon(TablerIcons.hash),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// Batch code if available
|
||||
if (widget.item.batchCode.isNotEmpty) {
|
||||
tiles.add(
|
||||
ListTile(
|
||||
title: Text(L10().batchCode),
|
||||
subtitle: Text(widget.item.batchCode),
|
||||
leading: const Icon(TablerIcons.barcode),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Quantity allocated
|
||||
tiles.add(
|
||||
ListTile(
|
||||
title: Text(L10().quantity),
|
||||
subtitle: Text(widget.item.quantity.toString()),
|
||||
leading: const Icon(TablerIcons.list),
|
||||
),
|
||||
);
|
||||
|
||||
// Install into (if specified)
|
||||
if (widget.item.installIntoId > 0) {
|
||||
tiles.add(
|
||||
ListTile(
|
||||
title: Text(L10().buildOutput),
|
||||
subtitle: Text(L10().viewDetails),
|
||||
leading: const Icon(TablerIcons.arrow_right),
|
||||
trailing: const Icon(TablerIcons.chevron_right),
|
||||
onTap: () async {
|
||||
showLoadingOverlay();
|
||||
var stockItem = await InvenTreeStockItem().get(
|
||||
widget.item.installIntoId,
|
||||
);
|
||||
hideLoadingOverlay();
|
||||
|
||||
if (stockItem is InvenTreeStockItem) {
|
||||
stockItem.goToDetailPage(context);
|
||||
}
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return tiles;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,136 @@
|
||||
import "package:flutter/material.dart";
|
||||
|
||||
import "package:inventree/api.dart";
|
||||
import "package:inventree/l10.dart";
|
||||
import "package:inventree/inventree/build.dart";
|
||||
import "package:inventree/inventree/model.dart";
|
||||
import "package:inventree/widget/paginator.dart";
|
||||
import "package:inventree/widget/build/build_item_detail.dart";
|
||||
import "package:inventree/widget/progress.dart";
|
||||
import "package:inventree/widget/refreshable_state.dart";
|
||||
|
||||
class PaginatedBuildItemWidget extends StatefulWidget {
|
||||
const PaginatedBuildItemWidget(this.build, {Key? key}) : super(key: key);
|
||||
|
||||
final InvenTreeBuildOrder build;
|
||||
|
||||
@override
|
||||
_PaginatedBuildItemWidgetState createState() =>
|
||||
_PaginatedBuildItemWidgetState();
|
||||
}
|
||||
|
||||
class _PaginatedBuildItemWidgetState
|
||||
extends RefreshableState<PaginatedBuildItemWidget> {
|
||||
_PaginatedBuildItemWidgetState();
|
||||
|
||||
@override
|
||||
String getAppBarTitle() {
|
||||
return L10().allocatedStock;
|
||||
}
|
||||
|
||||
@override
|
||||
Widget getBody(BuildContext context) {
|
||||
Map<String, String> filters = {"build": widget.build.pk.toString()};
|
||||
|
||||
return Column(
|
||||
children: [
|
||||
ListTile(
|
||||
leading: InvenTreeAPI().getThumbnail(
|
||||
widget.build.partDetail!.thumbnail,
|
||||
),
|
||||
title: Text(widget.build.reference),
|
||||
subtitle: Text(L10().allocatedStock),
|
||||
),
|
||||
Divider(thickness: 1.25),
|
||||
Expanded(child: PaginatedBuildItemList(filters)),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Paginated widget class for displaying a list of build order item allocations
|
||||
*/
|
||||
class PaginatedBuildItemList extends PaginatedSearchWidget {
|
||||
const PaginatedBuildItemList(Map<String, String> filters)
|
||||
: super(filters: filters);
|
||||
|
||||
@override
|
||||
String get searchTitle => L10().allocatedStock;
|
||||
|
||||
@override
|
||||
_PaginatedBuildItemListState createState() => _PaginatedBuildItemListState();
|
||||
}
|
||||
|
||||
/*
|
||||
* State class for PaginatedBuildItemList
|
||||
*/
|
||||
class _PaginatedBuildItemListState
|
||||
extends PaginatedSearchState<PaginatedBuildItemList> {
|
||||
_PaginatedBuildItemListState() : super();
|
||||
|
||||
@override
|
||||
String get prefix => "build_item_";
|
||||
|
||||
@override
|
||||
Map<String, String> get orderingOptions => {
|
||||
"stock_item": L10().stockItem,
|
||||
"quantity": L10().quantity,
|
||||
};
|
||||
|
||||
@override
|
||||
Future<InvenTreePageResponse?> requestPage(
|
||||
int limit,
|
||||
int offset,
|
||||
Map<String, String> params,
|
||||
) async {
|
||||
params["part_detail"] = "true";
|
||||
|
||||
final page = await InvenTreeBuildItem().listPaginated(
|
||||
limit,
|
||||
offset,
|
||||
filters: params,
|
||||
);
|
||||
return page;
|
||||
}
|
||||
|
||||
@override
|
||||
Widget buildItem(BuildContext context, InvenTreeModel model) {
|
||||
InvenTreeBuildItem item = model as InvenTreeBuildItem;
|
||||
|
||||
// Format the serialized data
|
||||
String info = "";
|
||||
|
||||
// Show serial number if available
|
||||
if (item.serialNumber.isNotEmpty) {
|
||||
info = "${L10().serialNumber}: ${item.serialNumber}";
|
||||
}
|
||||
// Show batch code if available
|
||||
else if (item.batchCode.isNotEmpty) {
|
||||
info = "${L10().batchCode}: ${item.batchCode}";
|
||||
}
|
||||
// Otherwise show location
|
||||
else if (item.locationName.isNotEmpty) {
|
||||
info = item.locationPath;
|
||||
}
|
||||
|
||||
return ListTile(
|
||||
title: Text(item.partName),
|
||||
subtitle: Text(info),
|
||||
trailing: Text(
|
||||
item.quantity.toString(),
|
||||
style: const TextStyle(fontWeight: FontWeight.bold),
|
||||
),
|
||||
leading: InvenTreeAPI().getThumbnail(item.partThumbnail),
|
||||
onTap: () async {
|
||||
showLoadingOverlay();
|
||||
await item.reload();
|
||||
hideLoadingOverlay();
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(builder: (context) => BuildItemDetailWidget(item)),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,136 @@
|
||||
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.dart";
|
||||
import "package:inventree/app_colors.dart";
|
||||
import "package:inventree/l10.dart";
|
||||
|
||||
import "package:inventree/inventree/part.dart";
|
||||
import "package:inventree/inventree/build.dart";
|
||||
|
||||
import "package:inventree/widget/progress.dart";
|
||||
import "package:inventree/widget/refreshable_state.dart";
|
||||
|
||||
/*
|
||||
* Widget for displaying detail view of a single BuildOrderLineItem
|
||||
*/
|
||||
class BuildLineDetailWidget extends StatefulWidget {
|
||||
const BuildLineDetailWidget(this.item, {Key? key}) : super(key: key);
|
||||
|
||||
final InvenTreeBuildLine item;
|
||||
|
||||
@override
|
||||
_BuildLineDetailWidgetState createState() => _BuildLineDetailWidgetState();
|
||||
}
|
||||
|
||||
/*
|
||||
* State for the BuildLineDetailWidget
|
||||
*/
|
||||
class _BuildLineDetailWidgetState
|
||||
extends RefreshableState<BuildLineDetailWidget> {
|
||||
_BuildLineDetailWidgetState();
|
||||
|
||||
@override
|
||||
String getAppBarTitle() => L10().lineItem;
|
||||
|
||||
@override
|
||||
List<Widget> appBarActions(BuildContext context) {
|
||||
List<Widget> actions = [];
|
||||
|
||||
return actions;
|
||||
}
|
||||
|
||||
@override
|
||||
List<SpeedDialChild> actionButtons(BuildContext context) {
|
||||
// Currently, no action buttons are needed as allocation/deallocation
|
||||
// is done at the build order level instead of individual line level
|
||||
return [];
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> request(BuildContext context) async {
|
||||
await widget.item.reload();
|
||||
}
|
||||
|
||||
@override
|
||||
List<Widget> getTiles(BuildContext context) {
|
||||
List<Widget> tiles = [];
|
||||
|
||||
// Reference to the part
|
||||
tiles.add(
|
||||
ListTile(
|
||||
title: Text(L10().part),
|
||||
subtitle: Text(widget.item.partName),
|
||||
leading:
|
||||
widget.item.part != null && widget.item.part!.thumbnail.isNotEmpty
|
||||
? SizedBox(
|
||||
width: 32,
|
||||
height: 32,
|
||||
child: InvenTreeAPI().getThumbnail(widget.item.part!.thumbnail),
|
||||
)
|
||||
: Icon(TablerIcons.box, color: COLOR_ACTION),
|
||||
trailing: const Icon(TablerIcons.chevron_right),
|
||||
onTap: () async {
|
||||
showLoadingOverlay();
|
||||
var part = await InvenTreePart().get(widget.item.partId);
|
||||
hideLoadingOverlay();
|
||||
|
||||
if (part is InvenTreePart) {
|
||||
part.goToDetailPage(context);
|
||||
}
|
||||
},
|
||||
),
|
||||
);
|
||||
|
||||
// Required quantity
|
||||
tiles.add(
|
||||
ListTile(
|
||||
title: Text(L10().quantity),
|
||||
subtitle: Text(widget.item.requiredQuantity.toString()),
|
||||
leading: const Icon(TablerIcons.list),
|
||||
),
|
||||
);
|
||||
|
||||
// Allocated quantity
|
||||
tiles.add(
|
||||
ListTile(
|
||||
title: Text(L10().allocated),
|
||||
subtitle: ProgressBar(
|
||||
widget.item.allocatedQuantity / widget.item.requiredQuantity,
|
||||
),
|
||||
trailing: Text(
|
||||
"${widget.item.allocatedQuantity.toInt()} / ${widget.item.requiredQuantity.toInt()}",
|
||||
style: TextStyle(
|
||||
color: widget.item.isFullyAllocated ? COLOR_SUCCESS : COLOR_WARNING,
|
||||
),
|
||||
),
|
||||
leading: const Icon(TablerIcons.progress),
|
||||
),
|
||||
);
|
||||
|
||||
// Reference
|
||||
if (widget.item.reference.isNotEmpty) {
|
||||
tiles.add(
|
||||
ListTile(
|
||||
title: Text(L10().reference),
|
||||
subtitle: Text(widget.item.reference),
|
||||
leading: const Icon(TablerIcons.hash),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// Notes
|
||||
if (widget.item.notes.isNotEmpty) {
|
||||
tiles.add(
|
||||
ListTile(
|
||||
title: Text(L10().notes),
|
||||
subtitle: Text(widget.item.notes),
|
||||
leading: const Icon(TablerIcons.note),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return tiles;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,115 @@
|
||||
import "package:flutter/material.dart";
|
||||
import "package:flutter_tabler_icons/flutter_tabler_icons.dart";
|
||||
import "package:inventree/api.dart";
|
||||
|
||||
import "package:inventree/app_colors.dart";
|
||||
import "package:inventree/l10.dart";
|
||||
|
||||
import "package:inventree/inventree/model.dart";
|
||||
import "package:inventree/inventree/build.dart";
|
||||
|
||||
import "package:inventree/widget/paginator.dart";
|
||||
import "package:inventree/widget/build/build_line_detail.dart";
|
||||
import "package:inventree/widget/progress.dart";
|
||||
|
||||
/*
|
||||
* Paginated widget class for displaying a list of build order line items
|
||||
*/
|
||||
class PaginatedBuildLineList extends PaginatedSearchWidget {
|
||||
const PaginatedBuildLineList(Map<String, String> filters)
|
||||
: super(filters: filters);
|
||||
|
||||
@override
|
||||
String get searchTitle => L10().requiredParts;
|
||||
|
||||
@override
|
||||
_PaginatedBuildLineListState createState() => _PaginatedBuildLineListState();
|
||||
}
|
||||
|
||||
/*
|
||||
* State class for PaginatedBuildLineList
|
||||
*/
|
||||
class _PaginatedBuildLineListState
|
||||
extends PaginatedSearchState<PaginatedBuildLineList> {
|
||||
_PaginatedBuildLineListState() : super();
|
||||
|
||||
@override
|
||||
String get prefix => "build_line_";
|
||||
|
||||
@override
|
||||
Map<String, String> get orderingOptions => {
|
||||
"part": L10().part,
|
||||
"reference": L10().reference,
|
||||
"quantity": L10().quantity,
|
||||
};
|
||||
|
||||
@override
|
||||
Map<String, Map<String, dynamic>> get filterOptions => {
|
||||
"allocated": {
|
||||
"label": L10().allocated,
|
||||
"help_text": L10().allocatedFilterDetail,
|
||||
"tristate": true,
|
||||
},
|
||||
"completed": {
|
||||
"label": L10().complete,
|
||||
"help_text": L10().completedFilterDetail,
|
||||
"tristate": true,
|
||||
},
|
||||
};
|
||||
|
||||
@override
|
||||
Future<InvenTreePageResponse?> requestPage(
|
||||
int limit,
|
||||
int offset,
|
||||
Map<String, String> params,
|
||||
) async {
|
||||
final page = await InvenTreeBuildLine().listPaginated(
|
||||
limit,
|
||||
offset,
|
||||
filters: params,
|
||||
);
|
||||
return page;
|
||||
}
|
||||
|
||||
@override
|
||||
Widget buildItem(BuildContext context, InvenTreeModel model) {
|
||||
InvenTreeBuildLine item = model as InvenTreeBuildLine;
|
||||
|
||||
// Calculate allocation progress
|
||||
double progress = 0;
|
||||
if (item.requiredQuantity > 0) {
|
||||
progress = item.allocatedQuantity / item.requiredQuantity;
|
||||
}
|
||||
|
||||
// Clamp to valid range
|
||||
progress = progress.clamp(0, 1);
|
||||
|
||||
return ListTile(
|
||||
title: Text(item.partName),
|
||||
subtitle: Text(item.partDescription),
|
||||
trailing: Text(
|
||||
"${item.allocatedQuantity.toInt()} / ${item.requiredQuantity.toInt()}",
|
||||
style: TextStyle(
|
||||
color: progress >= 1 ? COLOR_SUCCESS : COLOR_WARNING,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
leading: item.part != null && item.part!.thumbnail.isNotEmpty
|
||||
? SizedBox(
|
||||
width: 32,
|
||||
height: 32,
|
||||
child: InvenTreeAPI().getThumbnail(item.part!.thumbnail),
|
||||
)
|
||||
: const Icon(TablerIcons.box),
|
||||
onTap: () async {
|
||||
showLoadingOverlay();
|
||||
await item.reload();
|
||||
hideLoadingOverlay();
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(builder: (context) => BuildLineDetailWidget(item)),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,190 @@
|
||||
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/inventree/model.dart";
|
||||
import "package:inventree/widget/paginator.dart";
|
||||
import "package:inventree/widget/refreshable_state.dart";
|
||||
import "package:inventree/l10.dart";
|
||||
import "package:inventree/api.dart";
|
||||
import "package:inventree/inventree/part.dart";
|
||||
import "package:inventree/inventree/build.dart";
|
||||
|
||||
/*
|
||||
* Widget class for displaying a list of Build Orders
|
||||
*/
|
||||
class BuildOrderListWidget extends StatefulWidget {
|
||||
const BuildOrderListWidget({this.filters = const {}, Key? key})
|
||||
: super(key: key);
|
||||
|
||||
final Map<String, String> filters;
|
||||
|
||||
@override
|
||||
_BuildOrderListWidgetState createState() => _BuildOrderListWidgetState();
|
||||
}
|
||||
|
||||
class _BuildOrderListWidgetState
|
||||
extends RefreshableState<BuildOrderListWidget> {
|
||||
_BuildOrderListWidgetState();
|
||||
|
||||
@override
|
||||
String getAppBarTitle() => L10().buildOrders;
|
||||
|
||||
@override
|
||||
List<SpeedDialChild> actionButtons(BuildContext context) {
|
||||
List<SpeedDialChild> actions = [];
|
||||
|
||||
// Add create button if user has permission
|
||||
// Using canCreate instead of specific permission check
|
||||
if (InvenTreeBuildOrder().canCreate) {
|
||||
actions.add(
|
||||
SpeedDialChild(
|
||||
child: const Icon(TablerIcons.circle_plus),
|
||||
label: L10().buildOrderCreate,
|
||||
onTap: () {
|
||||
_createBuildOrder(context);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return actions;
|
||||
}
|
||||
|
||||
// Launch form to create a new BuildOrder
|
||||
Future<void> _createBuildOrder(BuildContext context) async {
|
||||
var fields = InvenTreeBuildOrder().formFields();
|
||||
|
||||
InvenTreeBuildOrder().createForm(
|
||||
context,
|
||||
L10().buildOrderCreate,
|
||||
fields: fields,
|
||||
onSuccess: (result) async {
|
||||
Map<String, dynamic> data = result as Map<String, dynamic>;
|
||||
|
||||
if (data.containsKey("pk")) {
|
||||
var order = InvenTreeBuildOrder.fromJson(data);
|
||||
order.goToDetailPage(context);
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
List<SpeedDialChild> barcodeButtons(BuildContext context) {
|
||||
// Build orders don't have barcode functionality yet
|
||||
return [];
|
||||
}
|
||||
|
||||
@override
|
||||
Widget getBody(BuildContext context) {
|
||||
return PaginatedBuildOrderList(widget.filters);
|
||||
}
|
||||
}
|
||||
|
||||
class PaginatedBuildOrderList extends PaginatedSearchWidget {
|
||||
const PaginatedBuildOrderList(Map<String, String> filters)
|
||||
: super(filters: filters);
|
||||
|
||||
@override
|
||||
String get searchTitle => L10().buildOrders;
|
||||
|
||||
@override
|
||||
_PaginatedBuildOrderListState createState() =>
|
||||
_PaginatedBuildOrderListState();
|
||||
}
|
||||
|
||||
class _PaginatedBuildOrderListState
|
||||
extends PaginatedSearchState<PaginatedBuildOrderList> {
|
||||
_PaginatedBuildOrderListState() : super();
|
||||
|
||||
@override
|
||||
String get prefix => "build_";
|
||||
|
||||
@override
|
||||
Map<String, String> get orderingOptions => {
|
||||
"reference": L10().reference,
|
||||
"part__name": L10().part,
|
||||
"status": L10().status,
|
||||
"creation_date": L10().creationDate,
|
||||
"target_date": L10().targetDate,
|
||||
"completion_date": L10().completionDate,
|
||||
};
|
||||
|
||||
@override
|
||||
Map<String, Map<String, dynamic>> get filterOptions => {
|
||||
"outstanding": {
|
||||
"label": L10().outstanding,
|
||||
"help_text": L10().outstandingOrderDetail,
|
||||
"tristate": true,
|
||||
"default": "true",
|
||||
},
|
||||
"overdue": {
|
||||
"label": L10().overdue,
|
||||
"help_text": L10().overdueDetail,
|
||||
"tristate": true,
|
||||
},
|
||||
"assigned_to_me": {
|
||||
"label": L10().assignedToMe,
|
||||
"help_text": L10().assignedToMeDetail,
|
||||
"tristate": true,
|
||||
},
|
||||
};
|
||||
|
||||
@override
|
||||
Future<InvenTreePageResponse?> requestPage(
|
||||
int limit,
|
||||
int offset,
|
||||
Map<String, String> params,
|
||||
) async {
|
||||
// Make sure the status codes are loaded
|
||||
await InvenTreeAPI().fetchStatusCodeData();
|
||||
|
||||
final page = await InvenTreeBuildOrder().listPaginated(
|
||||
limit,
|
||||
offset,
|
||||
filters: params,
|
||||
);
|
||||
|
||||
return page;
|
||||
}
|
||||
|
||||
@override
|
||||
Widget buildItem(BuildContext context, InvenTreeModel model) {
|
||||
InvenTreeBuildOrder order = model as InvenTreeBuildOrder;
|
||||
InvenTreePart? part = order.partDetail;
|
||||
|
||||
return ListTile(
|
||||
title: Text(order.reference),
|
||||
subtitle: Text(order.description),
|
||||
leading: part != null
|
||||
? InvenTreeAPI().getThumbnail(part.thumbnail)
|
||||
: null,
|
||||
trailing: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
children: [
|
||||
Text(
|
||||
BuildOrderStatus.getStatusText(order.status),
|
||||
style: TextStyle(
|
||||
color: BuildOrderStatus.getStatusColor(order.status),
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
Text(
|
||||
"${order.completed.toInt()} / ${order.quantity.toInt()}",
|
||||
style: const TextStyle(fontSize: 12),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
onTap: () async {
|
||||
order.goToDetailPage(context);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,166 @@
|
||||
import "package:flutter/material.dart";
|
||||
import "package:flutter_tabler_icons/flutter_tabler_icons.dart";
|
||||
import "package:inventree/widget/progress.dart";
|
||||
|
||||
import "package:inventree/api.dart";
|
||||
import "package:inventree/l10.dart";
|
||||
import "package:inventree/inventree/build.dart";
|
||||
|
||||
/*
|
||||
* A widget for displaying a single build order in a list
|
||||
*/
|
||||
class BuildOrderListItem extends StatelessWidget {
|
||||
const BuildOrderListItem(this.order, {Key? key}) : super(key: key);
|
||||
|
||||
final InvenTreeBuildOrder order;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
// Calculate completion percentage
|
||||
double progress = 0;
|
||||
if (order.quantity > 0) {
|
||||
progress = order.completed / order.quantity;
|
||||
}
|
||||
|
||||
// Clamp to valid range
|
||||
progress = progress.clamp(0, 1);
|
||||
|
||||
// Part name may be empty
|
||||
String partName = order.partDetail?.name ?? "-";
|
||||
|
||||
// Format dates
|
||||
String creationDate = order.creationDate;
|
||||
String targetDate = order.targetDate.isNotEmpty ? order.targetDate : "-";
|
||||
|
||||
return Card(
|
||||
margin: const EdgeInsets.all(4.0),
|
||||
child: InkWell(
|
||||
onTap: () {
|
||||
order.goToDetailPage(context);
|
||||
},
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
// Header row with reference and status
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(
|
||||
order.reference,
|
||||
style: const TextStyle(
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 16,
|
||||
),
|
||||
),
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 8.0,
|
||||
vertical: 4.0,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: BuildOrderStatus.getStatusColor(
|
||||
order.status,
|
||||
).withValues(alpha: 0.2),
|
||||
borderRadius: BorderRadius.circular(12.0),
|
||||
),
|
||||
child: Text(
|
||||
BuildOrderStatus.getStatusText(order.status),
|
||||
style: TextStyle(
|
||||
color: BuildOrderStatus.getStatusColor(order.status),
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 12,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
const SizedBox(height: 8),
|
||||
|
||||
// Part information
|
||||
Row(
|
||||
children: [
|
||||
SizedBox(
|
||||
width: 32,
|
||||
height: 32,
|
||||
child:
|
||||
order.partDetail != null &&
|
||||
order.partDetail!.thumbnail.isNotEmpty
|
||||
? InvenTreeAPI().getThumbnail(
|
||||
order.partDetail!.thumbnail,
|
||||
)
|
||||
: const Icon(TablerIcons.tool),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
partName,
|
||||
style: const TextStyle(fontWeight: FontWeight.bold),
|
||||
),
|
||||
if (order.description.isNotEmpty)
|
||||
Text(
|
||||
order.description,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
const SizedBox(height: 8),
|
||||
|
||||
// Progress indicator
|
||||
ProgressBar(order.completed, maximum: order.quantity),
|
||||
|
||||
const SizedBox(height: 8),
|
||||
|
||||
// Date information
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
const Icon(TablerIcons.calendar, size: 14),
|
||||
const SizedBox(width: 4),
|
||||
Text(
|
||||
"${L10().creationDate}: ${creationDate}",
|
||||
style: const TextStyle(fontSize: 12),
|
||||
),
|
||||
],
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
const Icon(TablerIcons.calendar_due, size: 14),
|
||||
const SizedBox(width: 4),
|
||||
Text(
|
||||
"${L10().targetDate}: $targetDate",
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
color:
|
||||
(order.targetDate.isNotEmpty &&
|
||||
DateTime.tryParse(order.targetDate) != null &&
|
||||
DateTime.tryParse(
|
||||
order.targetDate,
|
||||
)!.isBefore(DateTime.now()))
|
||||
? Colors.red
|
||||
: null,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,129 @@
|
||||
import "package:flutter/material.dart";
|
||||
import "package:flutter_tabler_icons/flutter_tabler_icons.dart";
|
||||
|
||||
import "package:inventree/api.dart";
|
||||
import "package:inventree/l10.dart";
|
||||
import "package:inventree/inventree/model.dart";
|
||||
import "package:inventree/inventree/stock.dart";
|
||||
|
||||
import "package:inventree/widget/paginator.dart";
|
||||
import "package:inventree/widget/progress.dart";
|
||||
import "package:inventree/widget/stock/stock_detail.dart";
|
||||
|
||||
/*
|
||||
* Paginated widget class for displaying a list of build order outputs (manufactured items)
|
||||
*/
|
||||
class PaginatedBuildOutputList extends PaginatedSearchWidget {
|
||||
const PaginatedBuildOutputList(Map<String, String> filters)
|
||||
: super(filters: filters);
|
||||
|
||||
@override
|
||||
String get searchTitle => L10().buildOutputs;
|
||||
|
||||
@override
|
||||
_PaginatedBuildOutputListState createState() =>
|
||||
_PaginatedBuildOutputListState();
|
||||
}
|
||||
|
||||
/*
|
||||
* State class for PaginatedBuildOutputList
|
||||
*/
|
||||
class _PaginatedBuildOutputListState
|
||||
extends PaginatedSearchState<PaginatedBuildOutputList> {
|
||||
_PaginatedBuildOutputListState() : super();
|
||||
|
||||
@override
|
||||
String get prefix => "build_output_";
|
||||
|
||||
@override
|
||||
Map<String, String> get orderingOptions => {
|
||||
"part": L10().part,
|
||||
"serial": L10().serialNumber,
|
||||
"quantity": L10().quantity,
|
||||
};
|
||||
|
||||
@override
|
||||
Map<String, Map<String, dynamic>> get filterOptions => {
|
||||
"is_building": {
|
||||
"label": L10().filterInProduction,
|
||||
"help_text": L10().filterInProductionDetail,
|
||||
"default": null,
|
||||
"tristate": true,
|
||||
},
|
||||
"status": {
|
||||
"label": L10().status,
|
||||
"help_text": L10().statusCode,
|
||||
"choices": InvenTreeAPI().StockStatus.choices,
|
||||
},
|
||||
};
|
||||
|
||||
@override
|
||||
Future<InvenTreePageResponse?> requestPage(
|
||||
int limit,
|
||||
int offset,
|
||||
Map<String, String> params,
|
||||
) async {
|
||||
final page = await InvenTreeStockItem().listPaginated(
|
||||
limit,
|
||||
offset,
|
||||
filters: params,
|
||||
);
|
||||
return page;
|
||||
}
|
||||
|
||||
@override
|
||||
Widget buildItem(BuildContext context, InvenTreeModel model) {
|
||||
InvenTreeStockItem stockItem = model as InvenTreeStockItem;
|
||||
|
||||
// Format the information to display
|
||||
String info = "";
|
||||
|
||||
// Show serial number if available
|
||||
if (stockItem.serialNumber.isNotEmpty) {
|
||||
info = "${L10().serialNumber}: ${stockItem.serialNumber}";
|
||||
}
|
||||
// Show batch code if available
|
||||
else if (stockItem.batch.isNotEmpty) {
|
||||
info = "${L10().batchCode}: ${stockItem.batch}";
|
||||
}
|
||||
// Otherwise show location
|
||||
else if (stockItem.locationId > 0) {
|
||||
// Use locationName if available
|
||||
info = stockItem.getString("name", subKey: "location_detail");
|
||||
|
||||
// Try to get the path if available
|
||||
String path = stockItem.getString(
|
||||
"pathstring",
|
||||
subKey: "location_detail",
|
||||
);
|
||||
if (path.isNotEmpty) {
|
||||
info = path;
|
||||
}
|
||||
}
|
||||
|
||||
return ListTile(
|
||||
title: Text(stockItem.partName),
|
||||
subtitle: Text(info),
|
||||
trailing: Text(
|
||||
stockItem.quantity.toString(),
|
||||
style: const TextStyle(fontWeight: FontWeight.bold),
|
||||
),
|
||||
leading: stockItem.partThumbnail.isNotEmpty
|
||||
? SizedBox(
|
||||
width: 32,
|
||||
height: 32,
|
||||
child: InvenTreeAPI().getThumbnail(stockItem.partThumbnail),
|
||||
)
|
||||
: const Icon(TablerIcons.box),
|
||||
onTap: () async {
|
||||
showLoadingOverlay();
|
||||
await stockItem.reload();
|
||||
hideLoadingOverlay();
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(builder: (context) => StockDetailWidget(stockItem)),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user