.. -*- Mode: doctest -*-

Doctest for domain/product.txt

Imports that will be used in this doctest:

    >>> from stoqlib.database.runtime import new_store, get_current_branch
    >>> from stoqlib.domain.product import Product, ProductStockItem, Storable
    >>> from stoqlib.domain.product import StockTransactionHistory

Create a new store

    >>> store = new_store()

Create a branch we can use:

    >>> from stoqlib.domain.exampledata import ExampleCreator
    >>> branch = ExampleCreator.create(store, 'Branch')

Create a sellable we can use:

    >>> from stoqlib.domain.exampledata import ExampleCreator
    >>> sellable = ExampleCreator.create(store, 'Sellable')

Create a new Product and attach a storable facet.

    >>> product = Product(store=store, sellable=sellable)
    >>> storable = Storable(product=product, store=store)

The storable needs to have it's stock created, let's do so. Note that a reason
is always required when changing the stock quantity

    >>> storable.increase_stock(10, branch, StockTransactionHistory.TYPE_INITIAL, 0)

A stock item should now be available for the storable:

    >>> stock_item = storable.get_stock_item(branch)
    >>> stock_item
    <ProductStockItem ...>

The branch and storable should be set properly

    >>> stock_item.branch == branch
    True

    >>> stock_item.storable == storable
    True

Fetch the stock item for the current branch and verify that the
stock_items are unique:

    >>> current_branch = get_current_branch(store)
    >>> stock_item2 = storable.get_stock_item(current_branch)
    >>> stock_item != stock_item2
    True

    >>> store.close()
