Skip to content

Commit

Permalink
fix(admin-ui): Fulfillment dialog enforces max quantity
Browse files Browse the repository at this point in the history
Relates to #2329
  • Loading branch information
michaelbromley committed Aug 7, 2023
1 parent 579459a commit 571b157
Showing 1 changed file with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ export class FulfillOrderDialogComponent implements Dialog<FulfillOrderInput>, O
getUnfulfilledCount(line: OrderDetailFragment['lines'][number]): number {
const fulfilled =
this.order.fulfillments
?.map(f => f.lines)
?.filter(f => f.state !== 'Cancelled')
.map(f => f.lines)
.flat()
.filter(row => row.orderLineId === line.id)
.reduce((sum, row) => sum + row.quantity, 0) ?? 0;
Expand All @@ -81,12 +82,15 @@ export class FulfillOrderDialogComponent implements Dialog<FulfillOrderInput>, O
(total, { fulfillCount }) => total + fulfillCount,
0,
);
const fulfillmentQuantityIsValid = Object.values(this.fulfillmentQuantities).every(
({ fulfillCount, max }) => fulfillCount <= max,
);
const formIsValid =
configurableOperationValueIsValid(
this.fulfillmentHandlerDef,
this.fulfillmentHandlerControl.value,
) && this.fulfillmentHandlerControl.valid;
return formIsValid && 0 < totalCount;
return formIsValid && 0 < totalCount && fulfillmentQuantityIsValid;
}

select() {
Expand Down

0 comments on commit 571b157

Please sign in to comment.