Stock movement is doubled
See original GitHub issueDescribe the bug We started tracking inventory and found out that each completed order lowered stock by double the size of actual order contents. I believe this piece of code is to blame: in order-state-machine.ts
private async onTransitionEnd(fromState: OrderState, toState: OrderState, data: OrderTransitionData) {
if (toState === 'PaymentAuthorized' || toState === 'PaymentSettled') {
data.order.active = false;
data.order.orderPlacedAt = new Date();
await this.stockMovementService.createSalesForOrder(data.ctx, data.order);
await this.promotionService.addPromotionsToOrder(data.ctx, data.order);
}
To Reproduce Steps to reproduce the behavior:
- Have an order flow that uses both PaymentAuthroized and PaymentSettled states.
- Track inventory
- Make an order and transition it through these both states
- notice that inventory of those products were lowered by double the amount
Expected behavior Should lower the stock exactly to the order. We should be able to define at which point of an order flow should the inventory movement take place. Also this code should take in account the direction of the transition - if we revert state transition (e.g. “Processing” to “PaymentSettled” it should not do stock movement neither.)
Environment (please complete the following information):
- @vendure/core version: .16.3
- Database (mysql/postgres etc): postgres
Issue Analytics
- State:
- Created 3 years ago
- Comments:10 (10 by maintainers)
Top Results From Across the Web
Understanding Stock Splits: How They Work - Investopedia
A stock split is a corporate action in which a company increases the number of its outstanding shares by issuing more shares to...
Read more >These 3 Stocks Have Doubled in Less Than 1 Year - Nasdaq
The S&P 500 is down 14% year to date as of this writing. As it stands, this is the worst year for the...
Read more >S&P 500 doubles from its pandemic bottom, marking ... - CNBC
It took the market 354 trading days to get there, marking the fastest bull market doubling off a bottom, according to a CNBC...
Read more >Stock Market Has Doubled Since Pandemic Low in March 2020
Robo-advisors keep an eye on the market's every move to protect your investments. M1 Finance, a robo-advisor, will monitor the market closely so ......
Read more >11 Stocks More Than Double Your Money The Fastest
You just doubled your money on S&P 500 stocks from the Covid-19 rally. That's great — but it's nothing compared to how some...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
orderPlacedAt
is added to the GraphQL type in my localnext
branch already, and will be in 0.17.0Great! This way we’ll have good default behavior, but also will have option to implement advanced one.
BTW the property I see here orderPlacedAt is on Order entity, but is missing in graphql Object type. Could we make it accessible on both admin-api and shop-api? It’s handy property for data analytics (e.g. we want to know how many orders been placed in between some dates.). And on shop-api handy for making “Order history” page where will be date of placing the order, not creation. Should I make new feature request for this?