Skip to content

feat: update stock on order (task1)#8

Closed
melinayg wants to merge 3 commits intomainfrom
feature/update-stock-on-order
Closed

feat: update stock on order (task1)#8
melinayg wants to merge 3 commits intomainfrom
feature/update-stock-on-order

Conversation

@melinayg
Copy link
Copy Markdown
Collaborator

Description

What does this PR do?
The create_order() function is updated to have the stock quantities reflect the new amount of stock after an order is placed. Inventory is now updated real-time after orders are placed.

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce.

Tested within test_create_order_success that the inventory stock decreases by the amount of chocolate orders placed per order ID. Also created test_stock_not_updated_with_failed_order to check that the stock inventory doesn't change if the order is greater than the current stock inventory value.

Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

Copy link
Copy Markdown
Collaborator

@BeWelsh BeWelsh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@melinayg Good job! The commit history is clean, the PR description is great, and you clearly have a good grasp on API development. Make sure to read the comment below for other changes.

Additionally, it is important to update docstrings! Sorry but this was slightly evil of me, since I didn't mention it explicilty in the ticket, but updating docstrings to reflect changes in functionality (in this case, service + router for create_order) is very important!

Overall great job - once you make these changes request another review!

item_total = chocolate["price"] * item["quantity"]
total_price += item_total
# Deduct stock
chocolate["stock_quantity"] -= item["quantity"]
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@melinayg There is a slight issue in subtracting from stock quantity while still iteratively checking if there is sufficient stock. Just to clarify, if an order is not valid (there is a specific chocolate with too little stock fulfill the order), the order will not be placed and all stock will remain the same. If you now notice the issue, add a new commit with the changes + a test covering the edge case.

@BeWelsh BeWelsh closed this Feb 2, 2026
@BeWelsh BeWelsh deleted the feature/update-stock-on-order branch February 3, 2026 15:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants