Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/frappe/erpnext/llms.txt

Use this file to discover all available pages before exploring further.

Stock Module API

The Stock module provides APIs for inventory management, stock movements, item details, and warehouse operations.

Item Details APIs

get_item_details

Retrieve comprehensive item details including pricing, stock levels, tax templates, and warehouse information.
import frappe

item_details = frappe.call(
    "erpnext.stock.get_item_details.get_item_details",
    args={
        "item_code": "ITEM-0001",
        "warehouse": "Stores - C",
        "doctype": "Sales Order",
        "company": "Company A",
        "selling_price_list": "Standard Selling",
        "customer": "CUST-0001",
        "qty": 10
    }
)
item_code
string
required
Item code/ID
warehouse
string
default:"null"
Warehouse for stock information
doctype
string
required
Document type (e.g., “Sales Order”, “Purchase Order”, “Delivery Note”)
company
string
required
Company name
customer
string
default:"null"
Customer name for customer-specific pricing
supplier
string
default:"null"
Supplier name for supplier-specific details
qty
float
default:"1"
Quantity for pricing calculations
selling_price_list
string
default:"null"
Price list for selling transactions
buying_price_list
string
default:"null"
Price list for buying transactions
item_details
dict
Comprehensive item information
  • item_code: Item code
  • item_name: Item name
  • description: Item description
  • stock_uom: Stock unit of measure
  • price_list_rate: Rate from price list
  • discount_percentage: Applicable discount
  • rate: Final rate after discount
  • amount: Total amount (qty × rate)
  • actual_qty: Available quantity in warehouse
  • projected_qty: Projected quantity
  • warehouse: Default warehouse
  • item_tax_template: Tax template
  • item_tax_rate: Tax rates as JSON
  • has_serial_no: Whether item has serial numbers
  • has_batch_no: Whether item has batch numbers
  • conversion_factor: UOM conversion factor

Stock Balance APIs

get_stock_balance

Get current stock balance for an item in a warehouse.
balance = frappe.call(
    "erpnext.stock.utils.get_stock_balance",
    item_code="ITEM-0001",
    warehouse="Stores - C",
    posting_date="2024-03-31",
    with_valuation_rate=True
)
# Returns: (qty, valuation_rate) or qty based on with_valuation_rate
item_code
string
required
Item code
warehouse
string
required
Warehouse name
posting_date
date
default:"today"
Date for balance calculation
posting_time
time
default:"current time"
Time for balance calculation
with_valuation_rate
bool
default:"false"
Include valuation rate in response
balance
float or tuple
Stock quantity, or tuple of (quantity, valuation_rate) if with_valuation_rate=True

get_stock_value_on

Get total stock value for warehouses on a specific date.
stock_value = frappe.call(
    "erpnext.stock.utils.get_stock_value_on",
    warehouses=["Stores - C", "Finished Goods - C"],
    posting_date="2024-03-31",
    item_code="ITEM-0001",
    company="Company A"
)
warehouses
list
default:"null"
List of warehouse names
posting_date
date
default:"today"
Date for valuation
item_code
string
default:"null"
Filter by specific item
company
string
default:"null"
Filter by company
stock_value
float
Total stock value

Stock Entry APIs

make_stock_entry

Create a stock entry for material movements.
from erpnext.stock.doctype.stock_entry.stock_entry_utils import make_stock_entry

stock_entry = make_stock_entry(
    item_code="ITEM-0001",
    source="Stores - C",
    target="Work In Progress - C",
    qty=10,
    purpose="Material Transfer for Manufacture",
    do_not_save=False,
    do_not_submit=False
)
item_code
string
required
Item code
source
string
default:"null"
Source warehouse
target
string
default:"null"
Target warehouse
qty
float
required
Quantity to transfer
purpose
string
required
Purpose: “Material Issue”, “Material Receipt”, “Material Transfer”, “Material Transfer for Manufacture”, “Manufacture”, “Repack”
rate
float
default:"null"
Item rate (auto-calculated if not provided)
company
string
default:"null"
Company name
do_not_save
bool
default:"false"
Return doc without saving
do_not_submit
bool
default:"false"
Save but don’t submit
stock_entry
Document
Stock Entry document

Barcode & Serial Number APIs

scan_barcode

Scan barcode and retrieve item, serial number, batch, or warehouse information.
result = frappe.call(
    "erpnext.stock.utils.scan_barcode",
    search_value="BARCODE123",
    ctx={
        "company": "Company A",
        "doctype": "Delivery Note"
    }
)
search_value
string
required
Barcode, serial number, batch number, or warehouse to scan
ctx
dict
default:"null"
Context with company and doctype information
scan_result
dict
Scanned entity information
Barcode Match:
  • barcode: Barcode value
  • item_code: Associated item
  • uom: Unit of measure
Serial Number Match:
  • serial_no: Serial number
  • item_code: Associated item
  • batch_no: Batch if applicable
Batch Match:
  • batch_no: Batch number
  • item_code: Associated item
Warehouse Match:
  • warehouse: Warehouse name

Valuation APIs

get_incoming_rate

Get incoming rate for an item based on valuation method (FIFO/LIFO/Moving Average).
rate = frappe.call(
    "erpnext.stock.utils.get_incoming_rate",
    args={
        "item_code": "ITEM-0001",
        "warehouse": "Stores - C",
        "posting_date": "2024-03-15",
        "posting_time": "10:00:00",
        "qty": 10,
        "serial_no": "",
        "company": "Company A"
    }
)
item_code
string
required
Item code
warehouse
string
required
Warehouse name
posting_date
date
required
Transaction date
qty
float
required
Quantity
company
string
required
Company name
rate
float
Incoming/valuation rate

get_valuation_method

Get valuation method for an item.
method = frappe.call(
    "erpnext.stock.utils.get_valuation_method",
    item_code="ITEM-0001",
    company="Company A"
)
# Returns: "FIFO", "LIFO", or "Moving Average"
item_code
string
required
Item code
company
string
default:"null"
Company name
method
string
Valuation method: “FIFO”, “LIFO”, or “Moving Average”

Warehouse APIs

validate_warehouse_company

Validate that warehouse belongs to the specified company.
frappe.call(
    "erpnext.stock.utils.validate_warehouse_company",
    warehouse="Stores - C",
    company="Company A"
)
warehouse
string
required
Warehouse name
company
string
required
Company name
validation
null
Raises exception if validation fails

Usage Examples

Getting Item Details for Sales Order

import frappe

# Get comprehensive item details
item_info = frappe.call(
    "erpnext.stock.get_item_details.get_item_details",
    args={
        "item_code": "LAPTOP-001",
        "warehouse": "Finished Goods - C",
        "doctype": "Sales Order",
        "company": "Tech Corp",
        "customer": "CUST-00001",
        "selling_price_list": "Standard Selling",
        "qty": 5,
        "transaction_date": "2024-03-15"
    }
)

print(f"Item Rate: {item_info['rate']}")
print(f"Available Qty: {item_info['actual_qty']}")
print(f"Total Amount: {item_info['amount']}")

Creating Material Transfer

from erpnext.stock.doctype.stock_entry.stock_entry_utils import make_stock_entry

# Transfer material from Stores to Production
stock_entry = make_stock_entry(
    item_code="RAW-MATERIAL-001",
    source="Stores - C",
    target="Work In Progress - C",
    qty=100,
    purpose="Material Transfer for Manufacture",
    company="Manufacturing Inc"
)

print(f"Stock Entry Created: {stock_entry.name}")

Checking Stock Balance

import frappe

# Check stock with valuation
qty, rate = frappe.call(
    "erpnext.stock.utils.get_stock_balance",
    item_code="ITEM-0001",
    warehouse="Stores - C",
    with_valuation_rate=True
)

value = qty * rate
print(f"Quantity: {qty}, Rate: {rate}, Value: {value}")

Scanning Barcode in POS

import frappe

# Scan barcode in POS transaction
scan_result = frappe.call(
    "erpnext.stock.utils.scan_barcode",
    search_value="8901234567890",
    ctx={
        "company": "Retail Store",
        "doctype": "POS Invoice",
        "selling_price_list": "Retail Price"
    }
)

if scan_result.get("item_code"):
    print(f"Item Found: {scan_result['item_code']}")
    if scan_result.get("has_batch_no"):
        print(f"Batch: {scan_result.get('batch_no')}")

Build docs developers (and LLMs) love