Subtract stock from Inventory after adding product to cart

I'm recently new to AppSheet and I want the quantity of products added to the cart to be subtracted from the inventory.

I have these tables: Products, Inventory, Orders, and Order Details. Orders and Inventory are not linked.

Products

Product IDCurrent Stocks (Virtual)
P001
SUM(SELECT(Inventory[Quantity],([Product ID] = [_THISROW].[Product ID])))

Inventory

Inventory IDProduct IDQuantityType
I001P00110Buy

Orders

Order IDCart Details (Virtual)
OR001
REF_ROWS("Cart Details","Order ID")

Order Details

Order Detail IDOrder IDProduct IDQuantity
OD001OR001P0011

I combined these templates: Order Capture How-to and Inventory Management 

I also have these slices (if it helps): Cart and Cart Details. Only 1 order shows up inside Cart view.

Screen Shot 2022-07-16 at 1.56.48 PM.pngScreen Shot 2022-07-16 at 1.57.07 PM.png

What I would like to do is this:

Cart Details (after adding Product to Cart)

Order Detail IDOrder IDProduct IDQuantity
OD001OR001P0012

Inventory

Inventory IDProduct IDQuantityType
I001P00110Buy
I002P001-2Sell

I tried to make a group of actions: Add to Cart then Remove Stock. For some reason, because of the sync delay, the Remove Stock action doesn't work. Even when I tried to disable the delay, it still didn't work. The Remove Stock action works in the Products view though.

Screen Shot 2022-07-16 at 4.52.18 AM.png

LINKTOFORM("Cart Details_Form", "Product ID", [Product ID], "Order ID", SELECT(Cart[Order ID],TRUE))

Screen Shot 2022-07-16 at 4.57.36 AM.png

ABS(LOOKUP([Product ID], "Cart Details", "Product ID", "Quantity"))*-1

Any help will be greatly appreciated. Thank you.

EDIT: Added more details if it helps.

0 1 238
1 REPLY 1

You need to create a view in your database that will compute the transactions table inventory (buy and sell) automatically. 

Inventory

Inventory IDProduct IDQuantityType
I001P00110Buy
I002P001-2Sell

Sample:

Select ProductID,sum(Quantity) as RemainingQTY group by ProductID

Result Table View

ProductIDRemainingQTY
P0018

You can now use this view for another transaction.

Top Labels in this Space