Skip to content

Commit

Permalink
Merge pull request #572 from inventree/order-updates
Browse files Browse the repository at this point in the history
Order updates
  • Loading branch information
SchrodingersGat authored Dec 11, 2024
2 parents 0ef72dc + cc0085e commit 9745bcf
Show file tree
Hide file tree
Showing 8 changed files with 143 additions and 11 deletions.
1 change: 1 addition & 0 deletions assets/release_notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
---

- Fixes barcode scanning bug which prevents scanning of DataMatrix codes
- Display "destination" information in PurchaseOrder detail view
- Adds "assigned to me" filter for Purchase Order list
- Adds "assigned to me" filter for Sales Order list

Expand Down
4 changes: 4 additions & 0 deletions lib/api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,10 @@ class InvenTreeAPI {
// Ref: https://github.com/inventree/InvenTree/pull/7420
bool get supportsModernAttachments => isConnected() && apiVersion >= 207;

// Does the server support the "destination" field on the PurchaseOrder model?
// Ref: https://github.com/inventree/InvenTree/pull/8403
bool get supportsPurchaseOrderDestination => isConnected() && apiVersion >= 276;

// Cached list of plugins (refreshed when we connect to the server)
List<InvenTreePlugin> _plugins = [];

Expand Down
9 changes: 8 additions & 1 deletion lib/inventree/purchase_order.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class InvenTreePurchaseOrder extends InvenTreeOrder {
"supplier_reference": {},
"description": {},
"project_code": {},
"destination": {},
"target_date": {},
"link": {},
"responsible": {},
Expand All @@ -54,6 +55,10 @@ class InvenTreePurchaseOrder extends InvenTreeOrder {
fields.remove("project_code");
}

if (!InvenTreeAPI().supportsPurchaseOrderDestination) {
fields.remove("destination");
}

return fields;

}
Expand Down Expand Up @@ -87,6 +92,8 @@ class InvenTreePurchaseOrder extends InvenTreeOrder {

String get supplierReference => getString("supplier_reference");

int get destinationId => getInt("destination");

bool get isOpen => api.PurchaseOrderStatus.isNameIn(status, ["PENDING", "PLACED", "ON_HOLD"]);

bool get isPending => api.PurchaseOrderStatus.isNameIn(status, ["PENDING", "ON_HOLD"]);
Expand Down Expand Up @@ -219,7 +226,7 @@ class InvenTreePOLineItem extends InvenTreeOrderLine {

String get purchasePriceCurrency => getString("purchase_price_currency");

int get destination => getInt("destination");
int get destinationId => getInt("destination");

Map<String, dynamic> get destinationDetail => getMap("destination_detail");
}
Expand Down
3 changes: 3 additions & 0 deletions lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,9 @@
"description": "Description",
"@description": {},

"destination": "Destination",
"@destination": {},

"destroyed": "Destroyed",
"@destroyed": {},

Expand Down
10 changes: 9 additions & 1 deletion lib/widget/company/company_detail.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,15 @@ class _CompanyDetailState extends RefreshableState<CompanyDetailWidget> {
int attachmentCount = 0;

@override
String getAppBarTitle() => L10().company;
String getAppBarTitle() {
String title = L10().company;

if (widget.company.name.isNotEmpty) {
title += " - ${widget.company.name}";
}

return title;
}

@override
List<Widget> appBarActions(BuildContext context) {
Expand Down
53 changes: 50 additions & 3 deletions lib/widget/order/po_line_detail.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,18 @@ 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";
import "package:inventree/l10.dart";
import "package:inventree/widget/progress.dart";
import "package:inventree/widget/part/part_detail.dart";

import "package:inventree/widget/refreshable_state.dart";
import "package:inventree/inventree/company.dart";
import "package:inventree/inventree/part.dart";
import "package:inventree/inventree/purchase_order.dart";
import "package:inventree/inventree/stock.dart";

import "package:inventree/widget/progress.dart";
import "package:inventree/widget/part/part_detail.dart";
import "package:inventree/widget/stock/location_display.dart";
import "package:inventree/widget/refreshable_state.dart";
import "package:inventree/widget/snacks.dart";
import "package:inventree/widget/company/supplier_part_detail.dart";

Expand All @@ -38,6 +42,8 @@ class _POLineDetailWidgetState extends RefreshableState<POLineDetailWidget> {

_POLineDetailWidgetState();

InvenTreeStockLocation? destination;

@override
String getAppBarTitle() => L10().lineItem;

Expand Down Expand Up @@ -84,6 +90,29 @@ class _POLineDetailWidgetState extends RefreshableState<POLineDetailWidget> {
@override
Future<void> request(BuildContext context) async {
await widget.item.reload();

if (widget.item.destinationId > 0) {
InvenTreeStockLocation().get(widget.item.destinationId).then((InvenTreeModel? loc) {
if (mounted) {
if (loc != null && loc is InvenTreeStockLocation) {
setState(() {
destination = loc;
});
} else {
setState(() {
destination = null;
});
}
}
});
} else {
if (mounted) {
setState(() {
destination = null;
});
}
}

}

// Callback to edit this line item
Expand Down Expand Up @@ -199,6 +228,24 @@ class _POLineDetailWidgetState extends RefreshableState<POLineDetailWidget> {
)
);

// Destination
if (destination != null) {
tiles.add(ListTile(
title: Text(L10().destination),
subtitle: Text(destination!.name),
leading: Icon(TablerIcons.map_pin, color: COLOR_ACTION),
onTap: () =>
{
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => LocationDisplayWidget(destination)
)
)
}
));
}

// Received quantity
tiles.add(
ListTile(
Expand Down
64 changes: 59 additions & 5 deletions lib/widget/order/purchase_order_detail.dart
Original file line number Diff line number Diff line change
@@ -1,17 +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:inventree/widget/dialogs.dart";
import "package:inventree/widget/order/po_line_list.dart";

import "package:inventree/app_colors.dart";
import "package:inventree/barcode/barcode.dart";
import "package:inventree/barcode/purchase_order.dart";
import "package:inventree/helpers.dart";
import "package:inventree/l10.dart";

import "package:inventree/inventree/model.dart";
import "package:inventree/inventree/company.dart";
import "package:inventree/inventree/stock.dart";
import "package:inventree/inventree/purchase_order.dart";

import "package:inventree/widget/dialogs.dart";
import "package:inventree/widget/stock/location_display.dart";
import "package:inventree/widget/order/po_line_list.dart";


import "package:inventree/widget/attachment_widget.dart";
import "package:inventree/widget/company/company_detail.dart";
import "package:inventree/widget/notes_widget.dart";
Expand Down Expand Up @@ -42,6 +48,8 @@ class _PurchaseOrderDetailState extends RefreshableState<PurchaseOrderDetailWidg

List<InvenTreePOLineItem> lines = [];

InvenTreeStockLocation? destination;

int completedLines = 0;

int attachmentCount = 0;
Expand All @@ -50,7 +58,15 @@ class _PurchaseOrderDetailState extends RefreshableState<PurchaseOrderDetailWidg
bool supportProjectCodes = false;

@override
String getAppBarTitle() => L10().purchaseOrder;
String getAppBarTitle() {
String title = L10().purchaseOrder;

if (widget.order.reference.isNotEmpty) {
title += " - ${widget.order.reference}";
}

return title;
}

@override
List<Widget> appBarActions(BuildContext context) {
Expand Down Expand Up @@ -258,6 +274,28 @@ class _PurchaseOrderDetailState extends RefreshableState<PurchaseOrderDetailWidg
});
}
});

if (api.supportsPurchaseOrderDestination && widget.order.destinationId > 0) {
InvenTreeStockLocation().get(widget.order.destinationId).then((InvenTreeModel? loc) {
if (mounted) {
if (loc != null && loc is InvenTreeStockLocation) {
setState(() {
destination = loc;
});
} else {
setState(() {
destination = null;
});
}
}
});
} else {
if (mounted) {
setState(() {
destination = null;
});
}
}
}

// Edit the currently displayed PurchaseOrder
Expand Down Expand Up @@ -348,6 +386,23 @@ class _PurchaseOrderDetailState extends RefreshableState<PurchaseOrderDetailWidg
));
}

// Order destination
if (destination != null) {
tiles.add(ListTile(
title: Text(L10().destination),
subtitle: Text(destination!.name),
leading: Icon(TablerIcons.map_pin, color: COLOR_ACTION),
onTap: () => {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => LocationDisplayWidget(destination)
)
)
}
));
}

Color lineColor = completedLines < widget.order.lineItemCount ? COLOR_WARNING : COLOR_SUCCESS;

tiles.add(ListTile(
Expand Down Expand Up @@ -444,5 +499,4 @@ class _PurchaseOrderDetailState extends RefreshableState<PurchaseOrderDetailWidg
PaginatedStockItemList({"purchase_order": widget.order.pk.toString()}),
];
}

}
}
10 changes: 9 additions & 1 deletion lib/widget/order/sales_order_detail.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,15 @@ class _SalesOrderDetailState extends RefreshableState<SalesOrderDetailWidget> {
int attachmentCount = 0;

@override
String getAppBarTitle() => L10().salesOrder;
String getAppBarTitle() {
String title = L10().salesOrder;

if (widget.order.reference.isNotEmpty) {
title += " - ${widget.order.reference}";
}

return title;
}

@override
List<Widget> appBarActions(BuildContext context) {
Expand Down

0 comments on commit 9745bcf

Please sign in to comment.