Issue Fetching Item Quantity from Specific Warehouse in Bin Doctype

Hi everyone,

I’m currently facing an issue while attempting to fetch the stock quantity of a specific item from a designated warehouse using the Bin doctype. My script is designed to pull the actual_qty based on the item_code and warehouse filters.

When I run the script without the warehouse filter, it retrieves the data as expected. However, when I include the warehouse filter, the script doesn’t return any results despite the record existing in the database.

Here’s the code snippet for reference:

import frappe

@frappe.whitelist()
def get_tool_stock_level(item_code):
    stock_level = frappe.db.get_value(
        'Bin',
        filters={
            'item_code': item_code,
            'warehouse': 'Haag Shop - CH DE'
            
        },
        fieldname='actual_qty'
    )
    
    return stock_level or 0

Has anyone encountered a similar issue or can provide insights into what might be going wrong? Your assistance would be invaluable.

Thank you in advance!
Owen

@Owen_Hooker

Try this

import frappe

@frappe.whitelist()
def get_tool_stock_level(item_code):
    stock_level = frappe.db.get_value('Bin',{'item_code': item_code, 'warehouse': 'Haag Shop - CH DE' }, 'actual_qty') or 0
    
    return stock_level

@Owen_Hooker Hi there, is the ability to track the bins is customized in your app? I’ve been looking for a way to do the same for our inventory.