# Inventory

> Track stock of your products: each invoice takes out what it sells, and you see what's in each warehouse, the stock ledger and its adjustments.

A product with `track_stock: true` tracks stock. Each invoice that sells it (with its `product`, or with its SKU or barcode as `NoIdentificacion`) takes what it sells out of its branch's warehouse the moment it's stamped, and a cancelled invoice puts it back. It's the same Inventario as in the app: what you do there (purchases, transfers, counts) shows here, and vice versa.

## Warehouses

The issuer has a warehouse per place it invoices from: the Matriz's and one per [branch](https://fiscalisto.com/en/docs/api/sucursales), created on their own.

```bash tab="cURL"
curl https://api.fiscalisto.com/v1/warehouses \
  -H "Authorization: Bearer $FISCALISTO_API_KEY"
```

```ts tab="TypeScript"
import { Fiscalisto } from "fiscalisto";

// The key comes from FISCALISTO_API_KEY.
const fiscalisto = new Fiscalisto();

const { data } = await fiscalisto.warehouses.list();
```

```python tab="Python"
from fiscalisto import Fiscalisto

# The key comes from FISCALISTO_API_KEY.
fiscalisto = Fiscalisto()

data = fiscalisto.warehouses.list()["data"]
```

```php tab="PHP"
<?php

use Fiscalisto\Fiscalisto;

// The key comes from FISCALISTO_API_KEY.
$fiscalisto = new Fiscalisto();

$data = $fiscalisto->warehouses->list()['data'];
```

```go tab="Go"
package main

import (
	"context"
	"fmt"
	"log"

	fiscalisto "fiscalisto.com/go"
)

func main() {
	// The key comes from FISCALISTO_API_KEY.
	client, err := fiscalisto.NewClient("")
	if err != nil {
		log.Fatal(err)
	}
	ctx := context.Background()

	warehouseList, err := client.Warehouses.List(ctx, nil)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("%+v\n", *warehouseList)
}
```

```java tab="Java"
import com.fiscalisto.FiscalistoClient;

// The key comes from FISCALISTO_API_KEY.
var fiscalisto = new FiscalistoClient();

var warehouseList = fiscalisto.warehouses().list();
System.out.println(warehouseList);
```

```csharp tab="C#"
using Fiscalisto;

// The key comes from FISCALISTO_API_KEY.
var fiscalisto = new FiscalistoClient();

var warehouseList = await fiscalisto.Warehouses.ListAsync();
```

An invoice sells from its branch's warehouse (`branch`), or the Matriz's without one. To take it out of another, send `warehouse` (`whs_…`) on the invoice.

## Opening stock

Mark the product with `track_stock: true` (when creating it or with `POST /v1/products/{id}`) and put in what you have with an adjustment:

```bash tab="cURL"
curl https://api.fiscalisto.com/v1/stock_adjustments \
  -H "Authorization: Bearer $FISCALISTO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "reason": "initial",
    "note": "Inventario de apertura",
    "lines": [{ "product": "prd_OufpKqnrvx9p2", "quantity": 50, "unit_cost": 90 }]
  }'
```

```ts tab="TypeScript"
import { Fiscalisto } from "fiscalisto";

// The key comes from FISCALISTO_API_KEY.
const fiscalisto = new Fiscalisto();

const stockAdjustment = await fiscalisto.stockAdjustments.create({
  reason: "initial",
  note: "Inventario de apertura",
  lines: [
    {
      product: "prd_OufpKqnrvx9p2",
      quantity: 50,
      unit_cost: 90,
    },
  ],
});
```

```python tab="Python"
from fiscalisto import Fiscalisto

# The key comes from FISCALISTO_API_KEY.
fiscalisto = Fiscalisto()

stock_adjustment = fiscalisto.stock_adjustments.create({
    "reason": "initial",
    "note": "Inventario de apertura",
    "lines": [
        {
            "product": "prd_OufpKqnrvx9p2",
            "quantity": 50,
            "unit_cost": 90,
        },
    ],
})
```

```php tab="PHP"
<?php

use Fiscalisto\Fiscalisto;

// The key comes from FISCALISTO_API_KEY.
$fiscalisto = new Fiscalisto();

$stockAdjustment = $fiscalisto->stockAdjustments->create([
    'reason' => 'initial',
    'note' => 'Inventario de apertura',
    'lines' => [
        [
            'product' => 'prd_OufpKqnrvx9p2',
            'quantity' => 50,
            'unit_cost' => 90,
        ],
    ],
]);
```

```go tab="Go"
package main

import (
	"context"
	"fmt"
	"log"

	fiscalisto "fiscalisto.com/go"
)

func main() {
	// The key comes from FISCALISTO_API_KEY.
	client, err := fiscalisto.NewClient("")
	if err != nil {
		log.Fatal(err)
	}
	ctx := context.Background()

	stockAdjustment, err := client.StockAdjustments.Create(ctx, &fiscalisto.CreateStockAdjustmentParams{
		Reason: "initial",
		Note:   fiscalisto.String("Inventario de apertura"),
		Lines: []fiscalisto.CreateStockAdjustmentParamsLine{
			{
				Product:  "prd_OufpKqnrvx9p2",
				Quantity: 50,
				UnitCost: fiscalisto.Float64(90),
			},
		},
	})
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(stockAdjustment.ID)
}
```

```java tab="Java"
import com.fiscalisto.FiscalistoClient;
import com.fiscalisto.model.CreateStockAdjustmentParams;
import com.fiscalisto.model.CreateStockAdjustmentParamsLine;
import java.util.List;

// The key comes from FISCALISTO_API_KEY.
var fiscalisto = new FiscalistoClient();

var stockAdjustment = fiscalisto.stockAdjustments().create(new CreateStockAdjustmentParams()
        .setReason("initial")
        .setNote("Inventario de apertura")
        .setLines(List.of(
                new CreateStockAdjustmentParamsLine()
                        .setProduct("prd_OufpKqnrvx9p2")
                        .setQuantity(50)
                        .setUnitCost(90)
        )));
System.out.println(stockAdjustment.getId());
```

```csharp tab="C#"
using Fiscalisto;

// The key comes from FISCALISTO_API_KEY.
var fiscalisto = new FiscalistoClient();

var stockAdjustment = await fiscalisto.StockAdjustments.CreateAsync(new CreateStockAdjustmentParams
{
    Reason = "initial",
    Note = "Inventario de apertura",
    Lines = new()
    {
        new()
        {
            Product = "prd_OufpKqnrvx9p2",
            Quantity = 50,
            UnitCost = 90,
        },
    },
});
```

Without `warehouse` it goes to the Matriz's warehouse. A positive quantity comes in and a negative one goes out; incoming units are valued at their `unit_cost` (pesos before IVA, or today's average cost without it) and outgoing ones at the issuer's cost (average or FIFO, whichever it chose in the app). The reason (`reason`) is `initial`, `surplus`, `shrinkage`, `theft`, `damage`, `expiration`, `internal_use`, `gift`, `count` or `other`. A product with lots or serial numbers asks for `lot` on each line.

An adjustment applies as soon as it's created (`status` `applied`), unless one of the issuer's **Pasos de aprobación** (approval steps, in the app under Inventario › Configurar inventario) asks for it, for example shrinkage over some amount: then it comes back `pending` and applies once it's approved in the app.

If the issuer chose in the app not to sell without stock, an invoice that asks for more than there is gets refused before it's stamped, and the message says which product. What Inventario can't do in an adjustment (a lot that isn't that product's, another adjustment of the same warehouse at that moment) returns `inventory_refused`.

## What's on hand

```bash tab="cURL"
curl https://api.fiscalisto.com/v1/products/prd_OufpKqnrvx9p2/stock \
  -H "Authorization: Bearer $FISCALISTO_API_KEY"
```

```ts tab="TypeScript"
import { Fiscalisto } from "fiscalisto";

// The key comes from FISCALISTO_API_KEY.
const fiscalisto = new Fiscalisto();

const { data } = await fiscalisto.products.stock("prd_OufpKqnrvx9p2");
```

```python tab="Python"
from fiscalisto import Fiscalisto

# The key comes from FISCALISTO_API_KEY.
fiscalisto = Fiscalisto()

data = fiscalisto.products.stock("prd_OufpKqnrvx9p2")["data"]
```

```php tab="PHP"
<?php

use Fiscalisto\Fiscalisto;

// The key comes from FISCALISTO_API_KEY.
$fiscalisto = new Fiscalisto();

$data = $fiscalisto->products->stock('prd_OufpKqnrvx9p2')['data'];
```

```go tab="Go"
package main

import (
	"context"
	"fmt"
	"log"

	fiscalisto "fiscalisto.com/go"
)

func main() {
	// The key comes from FISCALISTO_API_KEY.
	client, err := fiscalisto.NewClient("")
	if err != nil {
		log.Fatal(err)
	}
	ctx := context.Background()

	stockLevelList, err := client.Products.Stock(ctx, "prd_OufpKqnrvx9p2")
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("%+v\n", *stockLevelList)
}
```

```java tab="Java"
import com.fiscalisto.FiscalistoClient;

// The key comes from FISCALISTO_API_KEY.
var fiscalisto = new FiscalistoClient();

var stockLevelList = fiscalisto.products().stock("prd_OufpKqnrvx9p2");
System.out.println(stockLevelList);
```

```csharp tab="C#"
using Fiscalisto;

// The key comes from FISCALISTO_API_KEY.
var fiscalisto = new FiscalistoClient();

var stockLevelList = await fiscalisto.Products.StockAsync("prd_OufpKqnrvx9p2");
```

One row per warehouse: `on_hand` (what there is), `reserved` (set aside by accepted quotes), `available` (what can be sold), `value` and `average_cost`. `GET /v1/warehouses/{id}/stock` gives the same per product within a warehouse, 100 at a time.

## The stock ledger

`GET /v1/stock_movements` lists every entry and exit, newest first: `type` says what it was (`sale`, `purchase`, `adjustment`, `transfer_out`, `reversal`…) and `source` what caused it (the invoice's UUID, the adjustment's `adj_…`). Filter by `product`, `warehouse`, `type` and by day with `date_gte` and `date_lte`, in Mexico City time: a sale at 11:30 pm on the 31st belongs to the 31st.

## Production

A product with a recipe (its cost sheet in **Compras y gastos › Costos y márgenes**: what it's made of, its waste, other costs and how many units come out) is made with a production order. Create it as a draft with what you'll make:

```bash tab="cURL"
curl https://api.fiscalisto.com/v1/production_orders \
  -H "Authorization: Bearer $FISCALISTO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "product": "prd_OufpKqnrvx9p5",
    "quantity": 20,
    "due_date": "2026-11-20"
  }'
```

```ts tab="TypeScript"
import { Fiscalisto } from "fiscalisto";

// The key comes from FISCALISTO_API_KEY.
const fiscalisto = new Fiscalisto();

const productionOrder = await fiscalisto.productionOrders.create({
  product: "prd_OufpKqnrvx9p5",
  quantity: 20,
  due_date: "2026-11-20",
});
```

```python tab="Python"
from fiscalisto import Fiscalisto

# The key comes from FISCALISTO_API_KEY.
fiscalisto = Fiscalisto()

production_order = fiscalisto.production_orders.create({
    "product": "prd_OufpKqnrvx9p5",
    "quantity": 20,
    "due_date": "2026-11-20",
})
```

```php tab="PHP"
<?php

use Fiscalisto\Fiscalisto;

// The key comes from FISCALISTO_API_KEY.
$fiscalisto = new Fiscalisto();

$productionOrder = $fiscalisto->productionOrders->create([
    'product' => 'prd_OufpKqnrvx9p5',
    'quantity' => 20,
    'due_date' => '2026-11-20',
]);
```

```go tab="Go"
package main

import (
	"context"
	"fmt"
	"log"

	fiscalisto "fiscalisto.com/go"
)

func main() {
	// The key comes from FISCALISTO_API_KEY.
	client, err := fiscalisto.NewClient("")
	if err != nil {
		log.Fatal(err)
	}
	ctx := context.Background()

	productionOrder, err := client.ProductionOrders.Create(ctx, &fiscalisto.CreateProductionOrderParams{
		Product:  "prd_OufpKqnrvx9p5",
		Quantity: 20,
		DueDate:  fiscalisto.String("2026-11-20"),
	})
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(productionOrder.ID)
}
```

```java tab="Java"
import com.fiscalisto.FiscalistoClient;
import com.fiscalisto.model.CreateProductionOrderParams;

// The key comes from FISCALISTO_API_KEY.
var fiscalisto = new FiscalistoClient();

var productionOrder = fiscalisto.productionOrders().create(new CreateProductionOrderParams()
        .setProduct("prd_OufpKqnrvx9p5")
        .setQuantity(20)
        .setDueDate("2026-11-20"));
System.out.println(productionOrder.getId());
```

```csharp tab="C#"
using Fiscalisto;

// The key comes from FISCALISTO_API_KEY.
var fiscalisto = new FiscalistoClient();

var productionOrder = await fiscalisto.ProductionOrders.CreateAsync(new CreateProductionOrderParams
{
    Product = "prd_OufpKqnrvx9p5",
    Quantity = 20,
    DueDate = "2026-11-20",
});
```

Its `components` come from the recipe for that quantity, with their waste, and its `other_costs` are scaled to it. Nothing moves until you start it: `POST /v1/production_orders/{id}/start` takes the components out of the warehouse (send `components` with `quantity_used` if you used a different amount of one). When it's done, say how many came out:

```bash tab="cURL"
curl https://api.fiscalisto.com/v1/production_orders/mfo_OufpKqnrvx9p1/complete \
  -H "Authorization: Bearer $FISCALISTO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "quantity_made": 19 }'
```

```ts tab="TypeScript"
import { Fiscalisto } from "fiscalisto";

// The key comes from FISCALISTO_API_KEY.
const fiscalisto = new Fiscalisto();

const productionOrder = await fiscalisto.productionOrders.complete("mfo_OufpKqnrvx9p1", { quantity_made: 19 });
```

```python tab="Python"
from fiscalisto import Fiscalisto

# The key comes from FISCALISTO_API_KEY.
fiscalisto = Fiscalisto()

production_order = fiscalisto.production_orders.complete("mfo_OufpKqnrvx9p1", {"quantity_made": 19})
```

```php tab="PHP"
<?php

use Fiscalisto\Fiscalisto;

// The key comes from FISCALISTO_API_KEY.
$fiscalisto = new Fiscalisto();

$productionOrder = $fiscalisto->productionOrders->complete('mfo_OufpKqnrvx9p1', ['quantity_made' => 19]);
```

```go tab="Go"
package main

import (
	"context"
	"fmt"
	"log"

	fiscalisto "fiscalisto.com/go"
)

func main() {
	// The key comes from FISCALISTO_API_KEY.
	client, err := fiscalisto.NewClient("")
	if err != nil {
		log.Fatal(err)
	}
	ctx := context.Background()

	productionOrder, err := client.ProductionOrders.Complete(ctx, "mfo_OufpKqnrvx9p1", &fiscalisto.CompleteProductionOrderParams{
		QuantityMade: fiscalisto.Float64(19),
	})
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(productionOrder.ID)
}
```

```java tab="Java"
import com.fiscalisto.FiscalistoClient;
import com.fiscalisto.model.CompleteProductionOrderParams;

// The key comes from FISCALISTO_API_KEY.
var fiscalisto = new FiscalistoClient();

var productionOrder = fiscalisto.productionOrders().complete("mfo_OufpKqnrvx9p1", new CompleteProductionOrderParams().setQuantityMade(19));
System.out.println(productionOrder.getId());
```

```csharp tab="C#"
using Fiscalisto;

// The key comes from FISCALISTO_API_KEY.
var fiscalisto = new FiscalistoClient();

var productionOrder = await fiscalisto.ProductionOrders.CompleteAsync("mfo_OufpKqnrvx9p1", new CompleteProductionOrderParams { QuantityMade = 19 });
```

What was made goes into `destination_warehouse` at its real cost: (`materials_cost` + `other_costs`) ÷ `quantity_made`. With $520 of components, $80 of gas and 19 units, each goes in at $31.58. `POST /v1/production_orders/{id}/cancel` puts the components back and takes out what was made. In the ledger, its movements are `production_consumption` and `production_output`, with `source` `production` and the order's `mfo_…`.
