.. -*- Mode: doctest -*-

Doctest for domain/base.txt

The `base
<http://www.async.com.br/projects/stoq/docs/package/public/stoqlib.domain.base-module.html>`_
module has all abstract mixin classes used to build all domain classes.

These classes are mixin for domain components, domain
interfaces. The component model is based on top of twisted components and
the persistent layer use Storm to store all domain information on SQL
database.

Domain is the base class of all domain classes

We need to import modules and classes inherited from classes defined in
stoqlib/domain/base.py.

    >>> from stoqlib.database.runtime import new_store
    >>> from stoqlib.domain.product import Product

Create a new store object:

    >>> store = new_store()

To create a unique code for a Sellable object, I use datetime
module

    >>> import datetime
    >>> product_barcode = u'test_code' + unicode(datetime.datetime.now())
    >>> description = u'Red Mustang, 1960'

To create a sellable you need to pass in the required information.

    >>> from stoqlib.domain.sellable import Sellable
    >>> import decimal
    >>> sellable = Sellable(description=description,
    ...                     price=decimal.Decimal('1500.45'),
    ...                     store=store)

Create a new instance of Product class:

    >>> test_product = Product(sellable=sellable, store=store)

To clone a domain class instance, you need to use the clone method.

    >>> test_product_clone = test_product.clone()

This new product is an entire new object and have a different registry on
the database:

    >>> assert test_product is not test_product_clone

To get the current store of a given instance you must access the store
property.

    >>> assert store is test_product.store

Cloned instances must have the same store attribute of your original
instance.

    >>> assert (test_product.store is
    ...         test_product_clone.store)

    >>> store.close()
