Skip to content

Commit

Permalink
fix(admin-ui): Allow Fulfillments to be created based on state machine
Browse files Browse the repository at this point in the history
Closes #471
  • Loading branch information
michaelbromley committed Oct 2, 2020
1 parent 141d650 commit 5b99f59
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<button
class="btn btn-primary"
(click)="fulfillOrder()"
[disabled]="order.state !== 'PaymentSettled' && order.state !== 'PartiallyDelivered'"
[disabled]="!canAddFulfillment(order)"
>
{{ 'order.fulfill-order' | translate }}
</button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
NotificationService,
Order,
OrderDetail,
OrderLineFragment,
ServerConfigService,
SortOrder,
} from '@vendure/admin-ui/core';
Expand Down Expand Up @@ -196,6 +197,16 @@ export class OrderDetailComponent extends BaseDetailComponent<OrderDetail.Fragme
});
}

canAddFulfillment(order: OrderDetail.Fragment): boolean {
const allItemsFulfilled = order.lines
.reduce((items, line) => [...items, ...line.items], [] as OrderLineFragment['items'])
.every(item => !!item.fulfillment);
return (
!allItemsFulfilled &&
(order.nextStates.includes('Shipped') || order.nextStates.includes('PartiallyShipped'))
);
}

fulfillOrder() {
this.entity$
.pipe(
Expand Down

0 comments on commit 5b99f59

Please sign in to comment.