mirror of
https://github.com/inventree/inventree-app.git
synced 2025-06-12 18:25:26 +00:00
Add actions to issue or cancel purchase orders (#313)
This commit is contained in:
@ -93,6 +93,8 @@ class InvenTreePurchaseOrder extends InvenTreeModel {
|
||||
|
||||
bool get isOpen => status == PO_STATUS_PENDING || status == PO_STATUS_PLACED;
|
||||
|
||||
bool get isPending => status == PO_STATUS_PENDING;
|
||||
|
||||
bool get isPlaced => status == PO_STATUS_PLACED;
|
||||
|
||||
bool get isFailed => status == PO_STATUS_CANCELLED || status == PO_STATUS_LOST || status == PO_STATUS_RETURNED;
|
||||
@ -132,6 +134,25 @@ class InvenTreePurchaseOrder extends InvenTreeModel {
|
||||
InvenTreeModel createFromJson(Map<String, dynamic> json) {
|
||||
return InvenTreePurchaseOrder.fromJson(json);
|
||||
}
|
||||
|
||||
/// Mark this order as "placed" / "issued"
|
||||
Future<void> issueOrder() async {
|
||||
// Order can only be placed when the order is 'pending'
|
||||
if (!isPending) {
|
||||
return;
|
||||
}
|
||||
|
||||
await api.post("${url}issue/", expectedStatusCode: 201);
|
||||
}
|
||||
|
||||
/// Mark this order as "cancelled"
|
||||
Future<void> cancelOrder() async {
|
||||
if (!isOpen) {
|
||||
return;
|
||||
}
|
||||
|
||||
await api.post("${url}cancel/", expectedStatusCode: 201);
|
||||
}
|
||||
}
|
||||
|
||||
class InvenTreePOLineItem extends InvenTreeModel {
|
||||
|
@ -156,6 +156,9 @@
|
||||
"description": "Cancel"
|
||||
},
|
||||
|
||||
"cancelOrder": "Cancel Order",
|
||||
"@cancelOrder": {},
|
||||
|
||||
"category": "Category",
|
||||
"@category": {},
|
||||
|
||||
@ -479,9 +482,15 @@
|
||||
"invalidUsernamePassword": "Invalid username / password combination",
|
||||
"@invalidUsernamePassword": {},
|
||||
|
||||
"issue": "Issue",
|
||||
"@issue": {},
|
||||
|
||||
"issueDate": "Issue Date",
|
||||
"@issueDate": {},
|
||||
|
||||
"issueOrder": "Issue Order",
|
||||
"@issueOrder": {},
|
||||
|
||||
"itemInLocation": "Item already in location",
|
||||
"@itemInLocation": {},
|
||||
|
||||
|
@ -26,7 +26,7 @@ Future<void> confirmationDialog(String title, String text, {Color? color, IconDa
|
||||
title: Text(title, style: TextStyle(color: color)),
|
||||
leading: FaIcon(icon, color: color),
|
||||
),
|
||||
content: Text(text),
|
||||
content: text.isEmpty ? Text(text) : null,
|
||||
actions: [
|
||||
TextButton(
|
||||
child: Text(_reject),
|
||||
|
@ -1,5 +1,7 @@
|
||||
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/widget/dialogs.dart";
|
||||
import "package:one_context/one_context.dart";
|
||||
|
||||
import "package:inventree/api.dart";
|
||||
@ -62,6 +64,72 @@ class _PurchaseOrderDetailState extends RefreshableState<PurchaseOrderDetailWidg
|
||||
return actions;
|
||||
}
|
||||
|
||||
@override
|
||||
List<SpeedDialChild> actionButtons(BuildContext context) {
|
||||
List<SpeedDialChild> actions = [];
|
||||
|
||||
if (api.checkPermission("purchase_order", "add")) {
|
||||
if (order.isPending) {
|
||||
actions.add(
|
||||
SpeedDialChild(
|
||||
child: FaIcon(FontAwesomeIcons.paperPlane, color: Colors.blue),
|
||||
label: L10().issueOrder,
|
||||
onTap: () async {
|
||||
_issueOrder(context);
|
||||
}
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if (order.isOpen) {
|
||||
actions.add(
|
||||
SpeedDialChild(
|
||||
child: FaIcon(FontAwesomeIcons.circleXmark, color: Colors.red),
|
||||
label: L10().cancelOrder,
|
||||
onTap: () async {
|
||||
_cancelOrder(context);
|
||||
}
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return actions;
|
||||
}
|
||||
|
||||
/// Issue this order
|
||||
Future<void> _issueOrder(BuildContext context) async {
|
||||
|
||||
confirmationDialog(
|
||||
L10().issueOrder, "",
|
||||
icon: FontAwesomeIcons.paperPlane,
|
||||
color: Colors.blue,
|
||||
acceptText: L10().issue,
|
||||
onAccept: () async {
|
||||
await order.issueOrder().then((dynamic) {
|
||||
refresh(context);
|
||||
});
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/// Cancel this order
|
||||
Future<void> _cancelOrder(BuildContext context) async {
|
||||
|
||||
confirmationDialog(
|
||||
L10().cancelOrder, "",
|
||||
icon: FontAwesomeIcons.circleXmark,
|
||||
color: Colors.red,
|
||||
acceptText: L10().cancel,
|
||||
onAccept: () async {
|
||||
await order.cancelOrder().then((dynamic) {
|
||||
print("callback");
|
||||
refresh(context);
|
||||
});
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> request(BuildContext context) async {
|
||||
await order.reload();
|
||||
|
Reference in New Issue
Block a user