fix(inventory): delete reservation item inventory level required quantity (#13633)
Fixes #13625 --- > [!NOTE] > Ensure `reserved_quantity` is adjusted when deleting reservation items via `deleteReservationItems`, with new integration tests covering deletion and inventory updates. > > - **Inventory Module Service (`packages/modules/inventory/src/services/inventory-module.ts`)**: > - Add `deleteReservationItems` API (and transactional `_` variant) that hard-deletes reservations, then updates related inventory levels via `adjustInventoryLevelsForReservationsDeletion`. > - Wire through event emission/manager decorators consistent with existing patterns. > - **Integration Tests (`packages/modules/inventory/integration-tests/__tests__/inventory-module-service.spec.ts`)**: > - Add tests for `deleteReservationItems` to verify deletion by id and `reserved_quantity` adjustments on inventory levels. > - Minor import update to include `ReservationItemDTO`. > - **Changeset**: > - Patch release note for `@medusajs/inventory` documenting the fix. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit ac6641a9ec9543115504407f708f81bd427c3444. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup>
This commit is contained in:
@@ -711,6 +711,32 @@ export default class InventoryModuleService
|
||||
return result
|
||||
}
|
||||
|
||||
@InjectManager()
|
||||
@EmitEvents()
|
||||
// @ts-expect-error
|
||||
async deleteReservationItems(
|
||||
ids: string | string[],
|
||||
@MedusaContext() context: Context = {}
|
||||
): Promise<void> {
|
||||
return await this.deleteReservationItems_(ids, context)
|
||||
}
|
||||
|
||||
@InjectTransactionManager()
|
||||
protected async deleteReservationItems_(
|
||||
ids: string | string[],
|
||||
@MedusaContext() context: Context = {}
|
||||
): Promise<void> {
|
||||
const reservations: InventoryTypes.ReservationItemDTO[] =
|
||||
await this.reservationItemService_.list({ id: ids }, {}, context)
|
||||
|
||||
await super.deleteReservationItems(ids, context)
|
||||
|
||||
await this.adjustInventoryLevelsForReservationsDeletion(
|
||||
reservations,
|
||||
context
|
||||
)
|
||||
}
|
||||
|
||||
@InjectManager()
|
||||
@EmitEvents()
|
||||
// @ts-expect-error
|
||||
|
||||
Reference in New Issue
Block a user