-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(medusa, inventory): Inventory Management module #2956
Conversation
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Would be good to get eyes other than mine on this too though :)
/** | ||
* Deletes a reservation item by line item id. | ||
* @param {string} lineItemId - the id of the line item to delete. | ||
* @returns {Promise<void>} - an empty promise | ||
*/ | ||
async deleteByLineItem(lineItemId: string): Promise<void> { | ||
await this.atomicPhase_(async (manager) => { | ||
const itemRepository = manager.getRepository(ReservationItem) | ||
|
||
const items = await this.list({ line_item_id: lineItemId }) | ||
|
||
const ops: Promise<unknown>[] = [] | ||
for (const item of items) { | ||
ops.push(itemRepository.softRemove({ line_item_id: lineItemId })) | ||
ops.push( | ||
this.inventoryLevelService_ | ||
.withTransaction(manager) | ||
.adjustReservedQuantity( | ||
item.inventory_item_id, | ||
item.location_id, | ||
item.quantity * -1 | ||
) | ||
) | ||
} | ||
await Promise.all(ops) | ||
}) | ||
|
||
await this.eventBusService_.emit( | ||
ReservationItemService.Events.DELETED_BY_LINE_ITEM, | ||
{ | ||
line_item_id: lineItemId, | ||
} | ||
) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thought (non-blocking): wonder if the existence of a line_item_id
is a bad pattern as it couples the InventoryService with the design of the core.
It could be argued that a cleaner approach would be to have a LineItemReservations
table in the core with:
line_item_id
: id of a cart/order line itemreservation_item_id
: id of a reservation in the inventory system
It is not a big deal for me, but would like to hear your opinion. (cc: @pKorsholm)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this case to me makes more sense the inventory service managing reservations and holding the external relation (line_item_id).
Having a LineItemReservation would transfer the responsibility of managing reservations to the line item, which is somewhat duplicating the business logic.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense - I was thinking of a scenario where a user integrates a third party IMS tool through our interfaces. With the current implementation, we assume that the third party tool's representation of a reservation/allocation is able to hold a field to represent the line_item_id
. This was the assumption I wanted to challenge, but I think it is fair to go on as is and not delve too much on this right now :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good! I only have a couple of nits, but nothing major!
Remember Fixes CORE-921
😄
packages/inventory/src/migrations/schema-migrations/1665748086258-inventory_setup.ts
Outdated
Show resolved
Hide resolved
export const service = InventoryService | ||
export const migrations = [SchemaMigration] | ||
export const loaders = [ConnectionLoader] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion(non-blocking): maybe for a different pr, I talked to @adrien2p and he suggested creating a defined shape for module exports.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm thinking we could add it in a follow up pr 😄 no need to do anything about it here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with that, and we also will probably need to expand it a bit to optionaly integrate the module to the core while loading it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
What:
Module to manage inventory items in multiple locations
FIXES: CORE-921