diff --git a/assets/release_notes.md b/assets/release_notes.md index 544c49dd..5063db6a 100644 --- a/assets/release_notes.md +++ b/assets/release_notes.md @@ -5,6 +5,7 @@ - Adds option to pause and resume barcode scanning with camera - Adds option for "single shot" barcode scanning with camera - Fixes bug when removing entire quantity of a stock item +- Add line items to purchase orders directly from the app ### 0.13.0 - October 2023 diff --git a/lib/api_form.dart b/lib/api_form.dart index 237b1d57..043eedbb 100644 --- a/lib/api_form.dart +++ b/lib/api_form.dart @@ -524,11 +524,10 @@ class APIFormField { ), selectedItem: initial_data, asyncItems: (String filter) async { - Map _filters = {}; - - filters.forEach((key, value) { - _filters[key] = value; - }); + Map _filters = { + ..._relatedFieldFilters(), + ...filters, + }; _filters["search"] = filter; _filters["offset"] = "0"; @@ -586,6 +585,17 @@ class APIFormField { }); } + // Construct a set of custom filters for the dropdown search + Map _relatedFieldFilters() { + + switch (model) { + case "supplierpart": + return InvenTreeSupplierPart().defaultListFilters(); + } + + return {}; + } + // Render a "related field" based on the "model" type Widget _renderRelatedField(String fieldName, dynamic item, bool selected, bool extended) { @@ -611,7 +621,6 @@ class APIFormField { switch (model) { case "part": - var part = InvenTreePart.fromJson(data); return ListTile( @@ -626,6 +635,15 @@ class APIFormField { leading: extended ? InvenTreeAPI().getThumbnail(part.thumbnail) : null, ); + case "supplierpart": + var part = InvenTreeSupplierPart.fromJson(data); + + return ListTile( + title: Text(part.SKU), + subtitle: Text(part.partName), + leading: extended ? InvenTreeAPI().getThumbnail(part.partImage) : null, + trailing: extended && part.supplierImage.isNotEmpty ? InvenTreeAPI().getThumbnail(part.supplierImage) : null, + ); case "partcategory": var cat = InvenTreePartCategory.fromJson(data); diff --git a/lib/widget/order/purchase_order_detail.dart b/lib/widget/order/purchase_order_detail.dart index 73fa4eb2..13cb7a4f 100644 --- a/lib/widget/order/purchase_order_detail.dart +++ b/lib/widget/order/purchase_order_detail.dart @@ -74,6 +74,17 @@ class _PurchaseOrderDetailState extends RefreshableState _addLineItem(BuildContext context) async { + + var fields = InvenTreePOLineItem().formFields(); + + // Update part field definition + fields["part"]?["hidden"] = false; + fields["part"]?["filters"] = { + "supplier": widget.order.supplierId + }; + + fields["order"]?["value"] = widget.order.pk; + + InvenTreePOLineItem().createForm( + context, + L10().lineItemAdd, + fields: fields, + onSuccess: (data) async { + refresh(context); + showSnackIcon(L10().lineItemUpdated, success: true); + } + ); + } + /// Issue this order Future _issueOrder(BuildContext context) async {