mirror of
https://github.com/HendrikRauh/inventree-app.git
synced 2026-01-13 03:26:24 +00:00
Modern Label printing (#724)
* Basic widget * Redirect label printing action * Refactor label printing code * Construct form elements * Refactor to allow re-use of forms * Basic rendering of label printing form * Remove dead code * Pass custom handler through to form context * Refactoring API forms: - Allow custom pk field name - Add callback when values change * linting * Dynamically rebuild form * Handle nested fields * Handle label printing status * Run dart format * Update release notes * Remove unused var * Enable close icon * Handle initial plugin default value * Store default values: - Selected template (per label type) - Selected printing plugin * Dart format * Fix dart linting * use setter * Just use a public field
This commit is contained in:
parent
e41842a31d
commit
13d95dd1b1
10 changed files with 425 additions and 368 deletions
|
|
@ -63,8 +63,6 @@ class _PartDisplayState extends RefreshableState<PartDetailWidget> {
|
|||
|
||||
InvenTreePartPricing? partPricing;
|
||||
|
||||
List<Map<String, dynamic>> labels = [];
|
||||
|
||||
@override
|
||||
String getAppBarTitle() => L10().partDetails;
|
||||
|
||||
|
|
@ -121,19 +119,13 @@ class _PartDisplayState extends RefreshableState<PartDetailWidget> {
|
|||
);
|
||||
}
|
||||
|
||||
if (labels.isNotEmpty) {
|
||||
if (allowLabelPrinting && api.supportsModernLabelPrinting) {
|
||||
actions.add(
|
||||
SpeedDialChild(
|
||||
child: Icon(TablerIcons.printer),
|
||||
label: L10().printLabel,
|
||||
onTap: () async {
|
||||
selectAndPrintLabel(
|
||||
context,
|
||||
labels,
|
||||
widget.part.pk,
|
||||
"part",
|
||||
"part=${widget.part.pk}",
|
||||
);
|
||||
selectAndPrintLabel(context, "part", widget.part.pk);
|
||||
},
|
||||
),
|
||||
);
|
||||
|
|
@ -271,26 +263,6 @@ class _PartDisplayState extends RefreshableState<PartDetailWidget> {
|
|||
});
|
||||
}
|
||||
});
|
||||
|
||||
List<Map<String, dynamic>> _labels = [];
|
||||
allowLabelPrinting &= api.supportsMixin("labels");
|
||||
|
||||
if (allowLabelPrinting) {
|
||||
String model_type = api.supportsModernLabelPrinting
|
||||
? InvenTreePart.MODEL_TYPE
|
||||
: "part";
|
||||
String item_key = api.supportsModernLabelPrinting ? "items" : "part";
|
||||
|
||||
_labels = await getLabelTemplates(model_type, {
|
||||
item_key: widget.part.pk.toString(),
|
||||
});
|
||||
}
|
||||
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
labels = _labels;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void _editPartDialog(BuildContext context) {
|
||||
|
|
|
|||
|
|
@ -64,6 +64,7 @@ void showSnackIcon(
|
|||
},
|
||||
),
|
||||
backgroundColor: backgroundColor,
|
||||
showCloseIcon: true,
|
||||
action: onAction == null
|
||||
? null
|
||||
: SnackBarAction(
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ class _LocationDisplayState extends RefreshableState<LocationDisplayWidget> {
|
|||
|
||||
final InvenTreeStockLocation? location;
|
||||
|
||||
List<Map<String, dynamic>> labels = [];
|
||||
bool allowLabelPrinting = false;
|
||||
|
||||
@override
|
||||
String getAppBarTitle() {
|
||||
|
|
@ -179,19 +179,15 @@ class _LocationDisplayState extends RefreshableState<LocationDisplayWidget> {
|
|||
);
|
||||
}
|
||||
|
||||
if (widget.location != null && labels.isNotEmpty) {
|
||||
if (widget.location != null &&
|
||||
allowLabelPrinting &&
|
||||
api.supportsModernLabelPrinting) {
|
||||
actions.add(
|
||||
SpeedDialChild(
|
||||
child: Icon(TablerIcons.printer),
|
||||
label: L10().printLabel,
|
||||
onTap: () async {
|
||||
selectAndPrintLabel(
|
||||
context,
|
||||
labels,
|
||||
widget.location!.pk,
|
||||
"location",
|
||||
"location=${widget.location!.pk}",
|
||||
);
|
||||
selectAndPrintLabel(context, "stocklocation", widget.location!.pk);
|
||||
},
|
||||
),
|
||||
);
|
||||
|
|
@ -236,33 +232,10 @@ class _LocationDisplayState extends RefreshableState<LocationDisplayWidget> {
|
|||
}
|
||||
}
|
||||
|
||||
List<Map<String, dynamic>> _labels = [];
|
||||
bool allowLabelPrinting = await InvenTreeSettingsManager().getBool(
|
||||
allowLabelPrinting = await InvenTreeSettingsManager().getBool(
|
||||
INV_ENABLE_LABEL_PRINTING,
|
||||
true,
|
||||
);
|
||||
allowLabelPrinting &= api.supportsMixin("labels");
|
||||
|
||||
if (allowLabelPrinting) {
|
||||
if (widget.location != null) {
|
||||
String model_type = api.supportsModernLabelPrinting
|
||||
? InvenTreeStockLocation.MODEL_TYPE
|
||||
: "location";
|
||||
String item_key = api.supportsModernLabelPrinting
|
||||
? "items"
|
||||
: "location";
|
||||
|
||||
_labels = await getLabelTemplates(model_type, {
|
||||
item_key: widget.location!.pk.toString(),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
labels = _labels;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _newLocation(BuildContext context) async {
|
||||
|
|
|
|||
|
|
@ -128,19 +128,13 @@ class _StockItemDisplayState extends RefreshableState<StockDetailWidget> {
|
|||
);
|
||||
}
|
||||
|
||||
if (labels.isNotEmpty) {
|
||||
if (allowLabelPrinting && api.supportsModernLabelPrinting) {
|
||||
actions.add(
|
||||
SpeedDialChild(
|
||||
child: Icon(TablerIcons.printer),
|
||||
label: L10().printLabel,
|
||||
onTap: () async {
|
||||
selectAndPrintLabel(
|
||||
context,
|
||||
labels,
|
||||
widget.item.pk,
|
||||
"stock",
|
||||
"item=${widget.item.pk}",
|
||||
);
|
||||
selectAndPrintLabel(context, "stockitem", widget.item.pk);
|
||||
},
|
||||
),
|
||||
);
|
||||
|
|
@ -196,10 +190,7 @@ class _StockItemDisplayState extends RefreshableState<StockDetailWidget> {
|
|||
return actions;
|
||||
}
|
||||
|
||||
// Is label printing enabled for this StockItem?
|
||||
// This will be determined when the widget is loaded
|
||||
List<Map<String, dynamic>> labels = [];
|
||||
|
||||
bool allowLabelPrinting = false;
|
||||
int attachmentCount = 0;
|
||||
|
||||
@override
|
||||
|
|
@ -318,31 +309,10 @@ class _StockItemDisplayState extends RefreshableState<StockDetailWidget> {
|
|||
}
|
||||
}
|
||||
|
||||
List<Map<String, dynamic>> _labels = [];
|
||||
bool allowLabelPrinting = await InvenTreeSettingsManager().getBool(
|
||||
allowLabelPrinting = await InvenTreeSettingsManager().getBool(
|
||||
INV_ENABLE_LABEL_PRINTING,
|
||||
true,
|
||||
);
|
||||
allowLabelPrinting &= api.supportsMixin("labels");
|
||||
|
||||
// Request information on labels available for this stock item
|
||||
if (allowLabelPrinting) {
|
||||
String model_type = api.supportsModernLabelPrinting
|
||||
? InvenTreeStockItem.MODEL_TYPE
|
||||
: "stock";
|
||||
String item_key = api.supportsModernLabelPrinting ? "items" : "item";
|
||||
|
||||
// Clear the existing labels list
|
||||
_labels = await getLabelTemplates(model_type, {
|
||||
item_key: widget.item.pk.toString(),
|
||||
});
|
||||
}
|
||||
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
labels = _labels;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/// Delete the stock item from the database
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue