Skip to content

Commit

Permalink
Purchase order updates (#456)
Browse files Browse the repository at this point in the history
* Support supplierpart in related field

* Manual add line item to purchase order

* Update release notes
  • Loading branch information
SchrodingersGat authored Nov 15, 2023
1 parent 1148f01 commit 0a85441
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 6 deletions.
1 change: 1 addition & 0 deletions assets/release_notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
30 changes: 24 additions & 6 deletions lib/api_form.dart
Original file line number Diff line number Diff line change
Expand Up @@ -524,11 +524,10 @@ class APIFormField {
),
selectedItem: initial_data,
asyncItems: (String filter) async {
Map<String, String> _filters = {};

filters.forEach((key, value) {
_filters[key] = value;
});
Map<String, String> _filters = {
..._relatedFieldFilters(),
...filters,
};

_filters["search"] = filter;
_filters["offset"] = "0";
Expand Down Expand Up @@ -586,6 +585,17 @@ class APIFormField {
});
}

// Construct a set of custom filters for the dropdown search
Map<String, String> _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) {

Expand All @@ -611,7 +621,6 @@ class APIFormField {

switch (model) {
case "part":

var part = InvenTreePart.fromJson(data);

return ListTile(
Expand All @@ -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);
Expand Down
35 changes: 35 additions & 0 deletions lib/widget/order/purchase_order_detail.dart
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,17 @@ class _PurchaseOrderDetailState extends RefreshableState<PurchaseOrderDetailWidg

if (widget.order.canCreate) {
if (widget.order.isPending) {

actions.add(
SpeedDialChild(
child: FaIcon(FontAwesomeIcons.circlePlus, color: Colors.green),
label: L10().lineItemAdd,
onTap: () async {
_addLineItem(context);
}
)
);

actions.add(
SpeedDialChild(
child: FaIcon(FontAwesomeIcons.paperPlane, color: Colors.blue),
Expand Down Expand Up @@ -101,6 +112,30 @@ class _PurchaseOrderDetailState extends RefreshableState<PurchaseOrderDetailWidg
return actions;
}

/// Add a new line item to this order
Future<void> _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<void> _issueOrder(BuildContext context) async {

Expand Down

0 comments on commit 0a85441

Please sign in to comment.