Tomorrow's closing stock should be today's opening stock

Hello Team @NCP @avc
Is it possible for ERPNext to generate such a Script Report?

→ There is a shop. Date: 1-1-2024 When I open the shop in the morning the stock is 0. When I close the shop in the evening, the stock is 100.

→ Next Day Date: 2-1-2024 When I opened the shop in the morning my stock was 100. When I close the shop in the evening the total stock will be 200
(Yesterday’s 100 Today’s 100 Total = 200)

→ I will open the shop on the third day Date 3-1-2024 In the morning my stock will be 200. I sold 50 stocks out of it, then the stock increased by 150 in the evening with me
(Yesterday’s 200 Today’s Sell 50 Total = 150)

→ The fourth day is Date 4-1-2026 morning stock is 150. I order 100 items that day. By evening my total stock will be 250
(Yesterday’s 150 Today’s Buy 100 Total = 250)

Example
Date | Opening Stock | In Stock

1-1-2024 | 0 | 100
1-2-2024 | 100 | 200
1-3-2024 | 200 | 150
1-4-2024 | 150 | 250
(Tomorrow’s closing stock should be today’s opening stock)

Thank You

Hi:

Is doable with a script report, using erpnext.stock.utils.get_stock_balance to get the stock for each date (and even time). So, iterate over your date range, and call this method for each day.

Hope this helps.

2 Likes

@avc Thank You
Can you give me one Example? A small script

Hi @Mohammadali:

Something like this

first_date = "2024-01-01"
end_date = frappe.utils.add_to_date(first_date,days=120)
current_date = first_date
stock_history=[]
item_code="SKU007"
warehouse="Goods In Transit - ctgD"

while current_date <= end_date:
    current_stock = frappe.call("erpnext.stock.utils.get_stock_balance", 
        item_code=item_code, 
        posting_date=current_date, 
        warehouse=warehouse)
    
    stock_history.append({
        "date": current_date,
        "stock": current_stock
    })
    
    current_date = frappe.utils.add_to_date(current_date, days=1)

frappe.msgprint(str(stock_history))    

Check existing code, there are a lot of examples.
This is the best way to learn.

Hope this helps.

1 Like