
.. DO NOT EDIT.
.. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY.
.. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE:
.. "auto_examples/order_control_rich_model_machine.py"
.. LINE NUMBERS ARE GIVEN BELOW.

.. only:: html

    .. note::
        :class: sphx-glr-download-link-note

        Click :ref:`here <sphx_glr_download_auto_examples_order_control_rich_model_machine.py>`
        to download the full example code

.. rst-class:: sphx-glr-example-title

.. _sphx_glr_auto_examples_order_control_rich_model_machine.py:


Order control machine (rich model)
==================================

An StateMachine that demonstrates :ref:`Actions` being used on a rich model.

.. GENERATED FROM PYTHON SOURCE LINES 8-53

.. code-block:: default

    from statemachine import State
    from statemachine import StateMachine
    from statemachine.exceptions import AttrNotFound


    class Order(object):
        def __init__(self):
            self.order_total = 0
            self.payments = []
            self.payment_received = False

        def payments_enough(self, amount):
            return sum(self.payments) + amount >= self.order_total

        def add_to_order(self, amount):
            self.order_total += amount
            return self.order_total

        def on_receive_payment(self, amount):
            self.payments.append(amount)
            return self.payments

        def after_receive_payment(self):
            self.payment_received = True

        def wait_for_payment(self):
            self.payment_received = False


    class OrderControl(StateMachine):
        waiting_for_payment = State(
            "Waiting for payment", initial=True, enter="wait_for_payment"
        )
        processing = State("Processing")
        shipping = State("Shipping")
        completed = State("Completed", final=True)

        add_to_order = waiting_for_payment.to(waiting_for_payment, before="add_to_order")
        receive_payment = waiting_for_payment.to(
            processing, cond="payments_enough"
        ) | waiting_for_payment.to(waiting_for_payment, unless="payments_enough")
        process_order = processing.to(shipping, cond="payment_received")
        ship_order = shipping.to(completed)





.. image-sg:: /auto_examples/images/sphx_glr_order_control_rich_model_machine_001.svg
   :alt: order control rich model machine
   :srcset: /auto_examples/images/sphx_glr_order_control_rich_model_machine_001.svg
   :class: sphx-glr-single-img





.. GENERATED FROM PYTHON SOURCE LINES 54-60

Testing
-------

Let's first try to create a statemachine instance, using the default dummy model that don't have
the needed methods to complete the state machine. Since the required methods will not be found
either in the state machine or in the model, an exception ``AttrNotFound`` will be raised.

.. GENERATED FROM PYTHON SOURCE LINES 60-66

.. code-block:: default


    try:
        control = OrderControl()
    except AttrNotFound as e:
        assert str(e) == "Did not found name 'payment_received' from model or statemachine"








.. GENERATED FROM PYTHON SOURCE LINES 67-68

Now initializing with a proper ``order`` instance.

.. GENERATED FROM PYTHON SOURCE LINES 68-72

.. code-block:: default


    order = Order()
    control = OrderControl(order)








.. GENERATED FROM PYTHON SOURCE LINES 73-74

Send events to add to order

.. GENERATED FROM PYTHON SOURCE LINES 74-78

.. code-block:: default


    assert control.send("add_to_order", 3) == 3
    assert control.send("add_to_order", 7) == 10








.. GENERATED FROM PYTHON SOURCE LINES 79-80

Receive a payment of $4...

.. GENERATED FROM PYTHON SOURCE LINES 80-83

.. code-block:: default


    control.send("receive_payment", 4)





.. rst-class:: sphx-glr-script-out

 .. code-block:: none


    [4]



.. GENERATED FROM PYTHON SOURCE LINES 84-85

Since there's still $6 left to fulfill the payment, we cannot process the order.

.. GENERATED FROM PYTHON SOURCE LINES 85-90

.. code-block:: default

    try:
        control.send("process_order")
    except StateMachine.TransitionNotAllowed as err:
        print(err)





.. rst-class:: sphx-glr-script-out

 .. code-block:: none

    Can't process_order when in Waiting for payment.




.. GENERATED FROM PYTHON SOURCE LINES 91-94

.. code-block:: default


    control






.. raw:: html

    <div class="output_subarea output_html rendered_html output_result">
    <div class="statemachine"><?xml version="1.0" encoding="UTF-8" standalone="no"?>
    <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
     "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
    <!-- Generated by graphviz version 2.40.1 (20161225.0304)
     -->
    <!-- Title: list Pages: 1 -->
    <svg width="651pt" height="133pt"
     viewBox="0.00 0.00 651.00 133.00" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
    <g id="graph0" class="graph" transform="scale(1 1) rotate(0) translate(4 129)">
    <title>list</title>
    <polygon fill="#ffffff" stroke="transparent" points="-4,4 -4,-129 647,-129 647,4 -4,4"/>
    <text text-anchor="middle" x="321.5" y="-7" font-family="Times,serif" font-size="10.00" fill="#000000">OrderControl</text>
    <!-- i -->
    <g id="node1" class="node">
    <title>i</title>
    <ellipse fill="#000000" stroke="#000000" cx="7" cy="-41" rx="7" ry="7"/>
    <text text-anchor="middle" x="7" y="-40.7" font-family="Times,serif" font-size="1.00" fill="#000000">i</text>
    </g>
    <!-- waiting_for_payment -->
    <g id="node2" class="node">
    <title>waiting_for_payment</title>
    <path fill="#40e0d0" stroke="#000000" stroke-width="2" d="M159,-59C159,-59 63,-59 63,-59 57,-59 51,-53 51,-47 51,-47 51,-35 51,-35 51,-29 57,-23 63,-23 63,-23 159,-23 159,-23 165,-23 171,-29 171,-35 171,-35 171,-47 171,-47 171,-53 165,-59 159,-59"/>
    <text text-anchor="middle" x="111" y="-44" font-family="Times,serif" font-size="10.00" fill="#000000">Waiting for payment</text>
    <text text-anchor="middle" x="111" y="-33" font-family="Times,serif" font-size="10.00" fill="#000000">entry / wait_for_payment</text>
    </g>
    <!-- i&#45;&gt;waiting_for_payment -->
    <g id="edge1" class="edge">
    <title>i&#45;&gt;waiting_for_payment</title>
    <path fill="none" stroke="#0000ff" d="M14.1483,-41C20.2971,-41 29.8602,-41 40.6296,-41"/>
    <polygon fill="#0000ff" stroke="#0000ff" points="40.7957,-44.5001 50.7957,-41 40.7957,-37.5001 40.7957,-44.5001"/>
    </g>
    <!-- waiting_for_payment&#45;&gt;waiting_for_payment -->
    <g id="edge4" class="edge">
    <title>waiting_for_payment&#45;&gt;waiting_for_payment</title>
    <path fill="none" stroke="#0000ff" d="M103.9446,-59.1527C102.8591,-68.5391 105.2109,-77 111,-77 114.5277,-77 116.779,-73.8581 117.754,-69.2796"/>
    <polygon fill="#0000ff" stroke="#0000ff" points="121.2562,-69.2525 118.0554,-59.1527 114.2593,-69.0441 121.2562,-69.2525"/>
    <text text-anchor="middle" x="111" y="-79.8" font-family="Times,serif" font-size="9.00" fill="#000000">add_to_order</text>
    </g>
    <!-- waiting_for_payment&#45;&gt;waiting_for_payment -->
    <g id="edge6" class="edge">
    <title>waiting_for_payment&#45;&gt;waiting_for_payment</title>
    <path fill="none" stroke="#0000ff" d="M99.1743,-59.2576C93.0425,-76.4023 96.9844,-95 111,-95 122.2782,-95 127.0334,-82.9576 125.2657,-69.3202"/>
    <polygon fill="#0000ff" stroke="#0000ff" points="128.5837,-68.1512 122.8257,-59.2576 121.7809,-69.8008 128.5837,-68.1512"/>
    <text text-anchor="middle" x="111" y="-107.8" font-family="Times,serif" font-size="9.00" fill="#000000">receive_payment</text>
    <text text-anchor="middle" x="111" y="-97.8" font-family="Times,serif" font-size="9.00" fill="#000000">[!payments_enough]</text>
    </g>
    <!-- processing -->
    <g id="node4" class="node">
    <title>processing</title>
    <path fill="#ffffff" stroke="#000000" d="M326,-59C326,-59 290,-59 290,-59 284,-59 278,-53 278,-47 278,-47 278,-35 278,-35 278,-29 284,-23 290,-23 290,-23 326,-23 326,-23 332,-23 338,-29 338,-35 338,-35 338,-47 338,-47 338,-53 332,-59 326,-59"/>
    <text text-anchor="middle" x="308" y="-38.5" font-family="Times,serif" font-size="10.00" fill="#000000">Processing</text>
    </g>
    <!-- waiting_for_payment&#45;&gt;processing -->
    <g id="edge5" class="edge">
    <title>waiting_for_payment&#45;&gt;processing</title>
    <path fill="none" stroke="#0000ff" d="M171.1769,-41C202.4813,-41 239.9039,-41 267.6928,-41"/>
    <polygon fill="#0000ff" stroke="#0000ff" points="267.8387,-44.5001 277.8387,-41 267.8386,-37.5001 267.8387,-44.5001"/>
    <text text-anchor="middle" x="224.5" y="-53.8" font-family="Times,serif" font-size="9.00" fill="#000000">receive_payment</text>
    <text text-anchor="middle" x="224.5" y="-43.8" font-family="Times,serif" font-size="9.00" fill="#000000">[payments_enough]</text>
    </g>
    <!-- completed -->
    <g id="node3" class="node">
    <title>completed</title>
    <path fill="#ffffff" stroke="#000000" d="M627,-59C627,-59 589,-59 589,-59 583,-59 577,-53 577,-47 577,-47 577,-35 577,-35 577,-29 583,-23 589,-23 589,-23 627,-23 627,-23 633,-23 639,-29 639,-35 639,-35 639,-47 639,-47 639,-53 633,-59 627,-59"/>
    <path fill="none" stroke="#000000" d="M631,-63C631,-63 585,-63 585,-63 579,-63 573,-57 573,-51 573,-51 573,-31 573,-31 573,-25 579,-19 585,-19 585,-19 631,-19 631,-19 637,-19 643,-25 643,-31 643,-31 643,-51 643,-51 643,-57 637,-63 631,-63"/>
    <text text-anchor="middle" x="608" y="-38.5" font-family="Times,serif" font-size="10.00" fill="#000000">Completed</text>
    </g>
    <!-- shipping -->
    <g id="node5" class="node">
    <title>shipping</title>
    <path fill="#ffffff" stroke="#000000" d="M486,-59C486,-59 456,-59 456,-59 450,-59 444,-53 444,-47 444,-47 444,-35 444,-35 444,-29 450,-23 456,-23 456,-23 486,-23 486,-23 492,-23 498,-29 498,-35 498,-35 498,-47 498,-47 498,-53 492,-59 486,-59"/>
    <text text-anchor="middle" x="471" y="-38.5" font-family="Times,serif" font-size="10.00" fill="#000000">Shipping</text>
    </g>
    <!-- processing&#45;&gt;shipping -->
    <g id="edge2" class="edge">
    <title>processing&#45;&gt;shipping</title>
    <path fill="none" stroke="#0000ff" d="M338.277,-41C365.2542,-41 404.8233,-41 433.7361,-41"/>
    <polygon fill="#0000ff" stroke="#0000ff" points="433.863,-44.5001 443.863,-41 433.8629,-37.5001 433.863,-44.5001"/>
    <text text-anchor="middle" x="391" y="-53.8" font-family="Times,serif" font-size="9.00" fill="#000000">process_order</text>
    <text text-anchor="middle" x="391" y="-43.8" font-family="Times,serif" font-size="9.00" fill="#000000">[payment_received]</text>
    </g>
    <!-- shipping&#45;&gt;completed -->
    <g id="edge3" class="edge">
    <title>shipping&#45;&gt;completed</title>
    <path fill="none" stroke="#0000ff" d="M498.0668,-41C516.4958,-41 541.3337,-41 562.7377,-41"/>
    <polygon fill="#0000ff" stroke="#0000ff" points="562.9262,-44.5001 572.9262,-41 562.9261,-37.5001 562.9262,-44.5001"/>
    <text text-anchor="middle" x="535.5" y="-43.8" font-family="Times,serif" font-size="9.00" fill="#000000">ship_order</text>
    </g>
    </g>
    </svg>
    </div>
    </div>
    <br />
    <br />

.. GENERATED FROM PYTHON SOURCE LINES 95-96

Now paying the left amount, we can proceed.

.. GENERATED FROM PYTHON SOURCE LINES 96-99

.. code-block:: default


    control.send("receive_payment", 6)





.. rst-class:: sphx-glr-script-out

 .. code-block:: none


    [4, 6]



.. GENERATED FROM PYTHON SOURCE LINES 100-103

.. code-block:: default


    control






.. raw:: html

    <div class="output_subarea output_html rendered_html output_result">
    <div class="statemachine"><?xml version="1.0" encoding="UTF-8" standalone="no"?>
    <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
     "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
    <!-- Generated by graphviz version 2.40.1 (20161225.0304)
     -->
    <!-- Title: list Pages: 1 -->
    <svg width="651pt" height="133pt"
     viewBox="0.00 0.00 651.00 133.00" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
    <g id="graph0" class="graph" transform="scale(1 1) rotate(0) translate(4 129)">
    <title>list</title>
    <polygon fill="#ffffff" stroke="transparent" points="-4,4 -4,-129 647,-129 647,4 -4,4"/>
    <text text-anchor="middle" x="321.5" y="-7" font-family="Times,serif" font-size="10.00" fill="#000000">OrderControl</text>
    <!-- i -->
    <g id="node1" class="node">
    <title>i</title>
    <ellipse fill="#000000" stroke="#000000" cx="7" cy="-41" rx="7" ry="7"/>
    <text text-anchor="middle" x="7" y="-40.7" font-family="Times,serif" font-size="1.00" fill="#000000">i</text>
    </g>
    <!-- waiting_for_payment -->
    <g id="node2" class="node">
    <title>waiting_for_payment</title>
    <path fill="#ffffff" stroke="#000000" d="M159,-59C159,-59 63,-59 63,-59 57,-59 51,-53 51,-47 51,-47 51,-35 51,-35 51,-29 57,-23 63,-23 63,-23 159,-23 159,-23 165,-23 171,-29 171,-35 171,-35 171,-47 171,-47 171,-53 165,-59 159,-59"/>
    <text text-anchor="middle" x="111" y="-44" font-family="Times,serif" font-size="10.00" fill="#000000">Waiting for payment</text>
    <text text-anchor="middle" x="111" y="-33" font-family="Times,serif" font-size="10.00" fill="#000000">entry / wait_for_payment</text>
    </g>
    <!-- i&#45;&gt;waiting_for_payment -->
    <g id="edge1" class="edge">
    <title>i&#45;&gt;waiting_for_payment</title>
    <path fill="none" stroke="#0000ff" d="M14.1483,-41C20.2971,-41 29.8602,-41 40.6296,-41"/>
    <polygon fill="#0000ff" stroke="#0000ff" points="40.7957,-44.5001 50.7957,-41 40.7957,-37.5001 40.7957,-44.5001"/>
    </g>
    <!-- waiting_for_payment&#45;&gt;waiting_for_payment -->
    <g id="edge4" class="edge">
    <title>waiting_for_payment&#45;&gt;waiting_for_payment</title>
    <path fill="none" stroke="#0000ff" d="M103.9446,-59.1527C102.8591,-68.5391 105.2109,-77 111,-77 114.5277,-77 116.779,-73.8581 117.754,-69.2796"/>
    <polygon fill="#0000ff" stroke="#0000ff" points="121.2562,-69.2525 118.0554,-59.1527 114.2593,-69.0441 121.2562,-69.2525"/>
    <text text-anchor="middle" x="111" y="-79.8" font-family="Times,serif" font-size="9.00" fill="#000000">add_to_order</text>
    </g>
    <!-- waiting_for_payment&#45;&gt;waiting_for_payment -->
    <g id="edge6" class="edge">
    <title>waiting_for_payment&#45;&gt;waiting_for_payment</title>
    <path fill="none" stroke="#0000ff" d="M99.1743,-59.2576C93.0425,-76.4023 96.9844,-95 111,-95 122.2782,-95 127.0334,-82.9576 125.2657,-69.3202"/>
    <polygon fill="#0000ff" stroke="#0000ff" points="128.5837,-68.1512 122.8257,-59.2576 121.7809,-69.8008 128.5837,-68.1512"/>
    <text text-anchor="middle" x="111" y="-107.8" font-family="Times,serif" font-size="9.00" fill="#000000">receive_payment</text>
    <text text-anchor="middle" x="111" y="-97.8" font-family="Times,serif" font-size="9.00" fill="#000000">[!payments_enough]</text>
    </g>
    <!-- processing -->
    <g id="node4" class="node">
    <title>processing</title>
    <path fill="#40e0d0" stroke="#000000" stroke-width="2" d="M326,-59C326,-59 290,-59 290,-59 284,-59 278,-53 278,-47 278,-47 278,-35 278,-35 278,-29 284,-23 290,-23 290,-23 326,-23 326,-23 332,-23 338,-29 338,-35 338,-35 338,-47 338,-47 338,-53 332,-59 326,-59"/>
    <text text-anchor="middle" x="308" y="-38.5" font-family="Times,serif" font-size="10.00" fill="#000000">Processing</text>
    </g>
    <!-- waiting_for_payment&#45;&gt;processing -->
    <g id="edge5" class="edge">
    <title>waiting_for_payment&#45;&gt;processing</title>
    <path fill="none" stroke="#0000ff" d="M171.1769,-41C202.4813,-41 239.9039,-41 267.6928,-41"/>
    <polygon fill="#0000ff" stroke="#0000ff" points="267.8387,-44.5001 277.8387,-41 267.8386,-37.5001 267.8387,-44.5001"/>
    <text text-anchor="middle" x="224.5" y="-53.8" font-family="Times,serif" font-size="9.00" fill="#000000">receive_payment</text>
    <text text-anchor="middle" x="224.5" y="-43.8" font-family="Times,serif" font-size="9.00" fill="#000000">[payments_enough]</text>
    </g>
    <!-- completed -->
    <g id="node3" class="node">
    <title>completed</title>
    <path fill="#ffffff" stroke="#000000" d="M627,-59C627,-59 589,-59 589,-59 583,-59 577,-53 577,-47 577,-47 577,-35 577,-35 577,-29 583,-23 589,-23 589,-23 627,-23 627,-23 633,-23 639,-29 639,-35 639,-35 639,-47 639,-47 639,-53 633,-59 627,-59"/>
    <path fill="none" stroke="#000000" d="M631,-63C631,-63 585,-63 585,-63 579,-63 573,-57 573,-51 573,-51 573,-31 573,-31 573,-25 579,-19 585,-19 585,-19 631,-19 631,-19 637,-19 643,-25 643,-31 643,-31 643,-51 643,-51 643,-57 637,-63 631,-63"/>
    <text text-anchor="middle" x="608" y="-38.5" font-family="Times,serif" font-size="10.00" fill="#000000">Completed</text>
    </g>
    <!-- shipping -->
    <g id="node5" class="node">
    <title>shipping</title>
    <path fill="#ffffff" stroke="#000000" d="M486,-59C486,-59 456,-59 456,-59 450,-59 444,-53 444,-47 444,-47 444,-35 444,-35 444,-29 450,-23 456,-23 456,-23 486,-23 486,-23 492,-23 498,-29 498,-35 498,-35 498,-47 498,-47 498,-53 492,-59 486,-59"/>
    <text text-anchor="middle" x="471" y="-38.5" font-family="Times,serif" font-size="10.00" fill="#000000">Shipping</text>
    </g>
    <!-- processing&#45;&gt;shipping -->
    <g id="edge2" class="edge">
    <title>processing&#45;&gt;shipping</title>
    <path fill="none" stroke="#0000ff" d="M338.277,-41C365.2542,-41 404.8233,-41 433.7361,-41"/>
    <polygon fill="#0000ff" stroke="#0000ff" points="433.863,-44.5001 443.863,-41 433.8629,-37.5001 433.863,-44.5001"/>
    <text text-anchor="middle" x="391" y="-53.8" font-family="Times,serif" font-size="9.00" fill="#000000">process_order</text>
    <text text-anchor="middle" x="391" y="-43.8" font-family="Times,serif" font-size="9.00" fill="#000000">[payment_received]</text>
    </g>
    <!-- shipping&#45;&gt;completed -->
    <g id="edge3" class="edge">
    <title>shipping&#45;&gt;completed</title>
    <path fill="none" stroke="#0000ff" d="M498.0668,-41C516.4958,-41 541.3337,-41 562.7377,-41"/>
    <polygon fill="#0000ff" stroke="#0000ff" points="562.9262,-44.5001 572.9262,-41 562.9261,-37.5001 562.9262,-44.5001"/>
    <text text-anchor="middle" x="535.5" y="-43.8" font-family="Times,serif" font-size="9.00" fill="#000000">ship_order</text>
    </g>
    </g>
    </svg>
    </div>
    </div>
    <br />
    <br />

.. GENERATED FROM PYTHON SOURCE LINES 104-107

.. code-block:: default


    control.send("process_order")








.. GENERATED FROM PYTHON SOURCE LINES 108-111

.. code-block:: default


    control






.. raw:: html

    <div class="output_subarea output_html rendered_html output_result">
    <div class="statemachine"><?xml version="1.0" encoding="UTF-8" standalone="no"?>
    <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
     "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
    <!-- Generated by graphviz version 2.40.1 (20161225.0304)
     -->
    <!-- Title: list Pages: 1 -->
    <svg width="651pt" height="133pt"
     viewBox="0.00 0.00 651.00 133.00" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
    <g id="graph0" class="graph" transform="scale(1 1) rotate(0) translate(4 129)">
    <title>list</title>
    <polygon fill="#ffffff" stroke="transparent" points="-4,4 -4,-129 647,-129 647,4 -4,4"/>
    <text text-anchor="middle" x="321.5" y="-7" font-family="Times,serif" font-size="10.00" fill="#000000">OrderControl</text>
    <!-- i -->
    <g id="node1" class="node">
    <title>i</title>
    <ellipse fill="#000000" stroke="#000000" cx="7" cy="-41" rx="7" ry="7"/>
    <text text-anchor="middle" x="7" y="-40.7" font-family="Times,serif" font-size="1.00" fill="#000000">i</text>
    </g>
    <!-- waiting_for_payment -->
    <g id="node2" class="node">
    <title>waiting_for_payment</title>
    <path fill="#ffffff" stroke="#000000" d="M159,-59C159,-59 63,-59 63,-59 57,-59 51,-53 51,-47 51,-47 51,-35 51,-35 51,-29 57,-23 63,-23 63,-23 159,-23 159,-23 165,-23 171,-29 171,-35 171,-35 171,-47 171,-47 171,-53 165,-59 159,-59"/>
    <text text-anchor="middle" x="111" y="-44" font-family="Times,serif" font-size="10.00" fill="#000000">Waiting for payment</text>
    <text text-anchor="middle" x="111" y="-33" font-family="Times,serif" font-size="10.00" fill="#000000">entry / wait_for_payment</text>
    </g>
    <!-- i&#45;&gt;waiting_for_payment -->
    <g id="edge1" class="edge">
    <title>i&#45;&gt;waiting_for_payment</title>
    <path fill="none" stroke="#0000ff" d="M14.1483,-41C20.2971,-41 29.8602,-41 40.6296,-41"/>
    <polygon fill="#0000ff" stroke="#0000ff" points="40.7957,-44.5001 50.7957,-41 40.7957,-37.5001 40.7957,-44.5001"/>
    </g>
    <!-- waiting_for_payment&#45;&gt;waiting_for_payment -->
    <g id="edge4" class="edge">
    <title>waiting_for_payment&#45;&gt;waiting_for_payment</title>
    <path fill="none" stroke="#0000ff" d="M103.9446,-59.1527C102.8591,-68.5391 105.2109,-77 111,-77 114.5277,-77 116.779,-73.8581 117.754,-69.2796"/>
    <polygon fill="#0000ff" stroke="#0000ff" points="121.2562,-69.2525 118.0554,-59.1527 114.2593,-69.0441 121.2562,-69.2525"/>
    <text text-anchor="middle" x="111" y="-79.8" font-family="Times,serif" font-size="9.00" fill="#000000">add_to_order</text>
    </g>
    <!-- waiting_for_payment&#45;&gt;waiting_for_payment -->
    <g id="edge6" class="edge">
    <title>waiting_for_payment&#45;&gt;waiting_for_payment</title>
    <path fill="none" stroke="#0000ff" d="M99.1743,-59.2576C93.0425,-76.4023 96.9844,-95 111,-95 122.2782,-95 127.0334,-82.9576 125.2657,-69.3202"/>
    <polygon fill="#0000ff" stroke="#0000ff" points="128.5837,-68.1512 122.8257,-59.2576 121.7809,-69.8008 128.5837,-68.1512"/>
    <text text-anchor="middle" x="111" y="-107.8" font-family="Times,serif" font-size="9.00" fill="#000000">receive_payment</text>
    <text text-anchor="middle" x="111" y="-97.8" font-family="Times,serif" font-size="9.00" fill="#000000">[!payments_enough]</text>
    </g>
    <!-- processing -->
    <g id="node4" class="node">
    <title>processing</title>
    <path fill="#ffffff" stroke="#000000" d="M326,-59C326,-59 290,-59 290,-59 284,-59 278,-53 278,-47 278,-47 278,-35 278,-35 278,-29 284,-23 290,-23 290,-23 326,-23 326,-23 332,-23 338,-29 338,-35 338,-35 338,-47 338,-47 338,-53 332,-59 326,-59"/>
    <text text-anchor="middle" x="308" y="-38.5" font-family="Times,serif" font-size="10.00" fill="#000000">Processing</text>
    </g>
    <!-- waiting_for_payment&#45;&gt;processing -->
    <g id="edge5" class="edge">
    <title>waiting_for_payment&#45;&gt;processing</title>
    <path fill="none" stroke="#0000ff" d="M171.1769,-41C202.4813,-41 239.9039,-41 267.6928,-41"/>
    <polygon fill="#0000ff" stroke="#0000ff" points="267.8387,-44.5001 277.8387,-41 267.8386,-37.5001 267.8387,-44.5001"/>
    <text text-anchor="middle" x="224.5" y="-53.8" font-family="Times,serif" font-size="9.00" fill="#000000">receive_payment</text>
    <text text-anchor="middle" x="224.5" y="-43.8" font-family="Times,serif" font-size="9.00" fill="#000000">[payments_enough]</text>
    </g>
    <!-- completed -->
    <g id="node3" class="node">
    <title>completed</title>
    <path fill="#ffffff" stroke="#000000" d="M627,-59C627,-59 589,-59 589,-59 583,-59 577,-53 577,-47 577,-47 577,-35 577,-35 577,-29 583,-23 589,-23 589,-23 627,-23 627,-23 633,-23 639,-29 639,-35 639,-35 639,-47 639,-47 639,-53 633,-59 627,-59"/>
    <path fill="none" stroke="#000000" d="M631,-63C631,-63 585,-63 585,-63 579,-63 573,-57 573,-51 573,-51 573,-31 573,-31 573,-25 579,-19 585,-19 585,-19 631,-19 631,-19 637,-19 643,-25 643,-31 643,-31 643,-51 643,-51 643,-57 637,-63 631,-63"/>
    <text text-anchor="middle" x="608" y="-38.5" font-family="Times,serif" font-size="10.00" fill="#000000">Completed</text>
    </g>
    <!-- shipping -->
    <g id="node5" class="node">
    <title>shipping</title>
    <path fill="#40e0d0" stroke="#000000" stroke-width="2" d="M486,-59C486,-59 456,-59 456,-59 450,-59 444,-53 444,-47 444,-47 444,-35 444,-35 444,-29 450,-23 456,-23 456,-23 486,-23 486,-23 492,-23 498,-29 498,-35 498,-35 498,-47 498,-47 498,-53 492,-59 486,-59"/>
    <text text-anchor="middle" x="471" y="-38.5" font-family="Times,serif" font-size="10.00" fill="#000000">Shipping</text>
    </g>
    <!-- processing&#45;&gt;shipping -->
    <g id="edge2" class="edge">
    <title>processing&#45;&gt;shipping</title>
    <path fill="none" stroke="#0000ff" d="M338.277,-41C365.2542,-41 404.8233,-41 433.7361,-41"/>
    <polygon fill="#0000ff" stroke="#0000ff" points="433.863,-44.5001 443.863,-41 433.8629,-37.5001 433.863,-44.5001"/>
    <text text-anchor="middle" x="391" y="-53.8" font-family="Times,serif" font-size="9.00" fill="#000000">process_order</text>
    <text text-anchor="middle" x="391" y="-43.8" font-family="Times,serif" font-size="9.00" fill="#000000">[payment_received]</text>
    </g>
    <!-- shipping&#45;&gt;completed -->
    <g id="edge3" class="edge">
    <title>shipping&#45;&gt;completed</title>
    <path fill="none" stroke="#0000ff" d="M498.0668,-41C516.4958,-41 541.3337,-41 562.7377,-41"/>
    <polygon fill="#0000ff" stroke="#0000ff" points="562.9262,-44.5001 572.9262,-41 562.9261,-37.5001 562.9262,-44.5001"/>
    <text text-anchor="middle" x="535.5" y="-43.8" font-family="Times,serif" font-size="9.00" fill="#000000">ship_order</text>
    </g>
    </g>
    </svg>
    </div>
    </div>
    <br />
    <br />

.. GENERATED FROM PYTHON SOURCE LINES 112-115

.. code-block:: default


    control.send("ship_order")








.. GENERATED FROM PYTHON SOURCE LINES 116-117

Just checking the final expected state

.. GENERATED FROM PYTHON SOURCE LINES 117-120

.. code-block:: default


    order.order_total





.. rst-class:: sphx-glr-script-out

 .. code-block:: none


    10



.. GENERATED FROM PYTHON SOURCE LINES 121-124

.. code-block:: default


    order.payments





.. rst-class:: sphx-glr-script-out

 .. code-block:: none


    [4, 6]



.. GENERATED FROM PYTHON SOURCE LINES 125-128

.. code-block:: default


    control.completed.is_active





.. rst-class:: sphx-glr-script-out

 .. code-block:: none


    True



.. GENERATED FROM PYTHON SOURCE LINES 129-133

.. code-block:: default


    control







.. raw:: html

    <div class="output_subarea output_html rendered_html output_result">
    <div class="statemachine"><?xml version="1.0" encoding="UTF-8" standalone="no"?>
    <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
     "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
    <!-- Generated by graphviz version 2.40.1 (20161225.0304)
     -->
    <!-- Title: list Pages: 1 -->
    <svg width="651pt" height="133pt"
     viewBox="0.00 0.00 651.00 133.00" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
    <g id="graph0" class="graph" transform="scale(1 1) rotate(0) translate(4 129)">
    <title>list</title>
    <polygon fill="#ffffff" stroke="transparent" points="-4,4 -4,-129 647,-129 647,4 -4,4"/>
    <text text-anchor="middle" x="321.5" y="-7" font-family="Times,serif" font-size="10.00" fill="#000000">OrderControl</text>
    <!-- i -->
    <g id="node1" class="node">
    <title>i</title>
    <ellipse fill="#000000" stroke="#000000" cx="7" cy="-41" rx="7" ry="7"/>
    <text text-anchor="middle" x="7" y="-40.7" font-family="Times,serif" font-size="1.00" fill="#000000">i</text>
    </g>
    <!-- waiting_for_payment -->
    <g id="node2" class="node">
    <title>waiting_for_payment</title>
    <path fill="#ffffff" stroke="#000000" d="M159,-59C159,-59 63,-59 63,-59 57,-59 51,-53 51,-47 51,-47 51,-35 51,-35 51,-29 57,-23 63,-23 63,-23 159,-23 159,-23 165,-23 171,-29 171,-35 171,-35 171,-47 171,-47 171,-53 165,-59 159,-59"/>
    <text text-anchor="middle" x="111" y="-44" font-family="Times,serif" font-size="10.00" fill="#000000">Waiting for payment</text>
    <text text-anchor="middle" x="111" y="-33" font-family="Times,serif" font-size="10.00" fill="#000000">entry / wait_for_payment</text>
    </g>
    <!-- i&#45;&gt;waiting_for_payment -->
    <g id="edge1" class="edge">
    <title>i&#45;&gt;waiting_for_payment</title>
    <path fill="none" stroke="#0000ff" d="M14.1483,-41C20.2971,-41 29.8602,-41 40.6296,-41"/>
    <polygon fill="#0000ff" stroke="#0000ff" points="40.7957,-44.5001 50.7957,-41 40.7957,-37.5001 40.7957,-44.5001"/>
    </g>
    <!-- waiting_for_payment&#45;&gt;waiting_for_payment -->
    <g id="edge4" class="edge">
    <title>waiting_for_payment&#45;&gt;waiting_for_payment</title>
    <path fill="none" stroke="#0000ff" d="M103.9446,-59.1527C102.8591,-68.5391 105.2109,-77 111,-77 114.5277,-77 116.779,-73.8581 117.754,-69.2796"/>
    <polygon fill="#0000ff" stroke="#0000ff" points="121.2562,-69.2525 118.0554,-59.1527 114.2593,-69.0441 121.2562,-69.2525"/>
    <text text-anchor="middle" x="111" y="-79.8" font-family="Times,serif" font-size="9.00" fill="#000000">add_to_order</text>
    </g>
    <!-- waiting_for_payment&#45;&gt;waiting_for_payment -->
    <g id="edge6" class="edge">
    <title>waiting_for_payment&#45;&gt;waiting_for_payment</title>
    <path fill="none" stroke="#0000ff" d="M99.1743,-59.2576C93.0425,-76.4023 96.9844,-95 111,-95 122.2782,-95 127.0334,-82.9576 125.2657,-69.3202"/>
    <polygon fill="#0000ff" stroke="#0000ff" points="128.5837,-68.1512 122.8257,-59.2576 121.7809,-69.8008 128.5837,-68.1512"/>
    <text text-anchor="middle" x="111" y="-107.8" font-family="Times,serif" font-size="9.00" fill="#000000">receive_payment</text>
    <text text-anchor="middle" x="111" y="-97.8" font-family="Times,serif" font-size="9.00" fill="#000000">[!payments_enough]</text>
    </g>
    <!-- processing -->
    <g id="node4" class="node">
    <title>processing</title>
    <path fill="#ffffff" stroke="#000000" d="M326,-59C326,-59 290,-59 290,-59 284,-59 278,-53 278,-47 278,-47 278,-35 278,-35 278,-29 284,-23 290,-23 290,-23 326,-23 326,-23 332,-23 338,-29 338,-35 338,-35 338,-47 338,-47 338,-53 332,-59 326,-59"/>
    <text text-anchor="middle" x="308" y="-38.5" font-family="Times,serif" font-size="10.00" fill="#000000">Processing</text>
    </g>
    <!-- waiting_for_payment&#45;&gt;processing -->
    <g id="edge5" class="edge">
    <title>waiting_for_payment&#45;&gt;processing</title>
    <path fill="none" stroke="#0000ff" d="M171.1769,-41C202.4813,-41 239.9039,-41 267.6928,-41"/>
    <polygon fill="#0000ff" stroke="#0000ff" points="267.8387,-44.5001 277.8387,-41 267.8386,-37.5001 267.8387,-44.5001"/>
    <text text-anchor="middle" x="224.5" y="-53.8" font-family="Times,serif" font-size="9.00" fill="#000000">receive_payment</text>
    <text text-anchor="middle" x="224.5" y="-43.8" font-family="Times,serif" font-size="9.00" fill="#000000">[payments_enough]</text>
    </g>
    <!-- completed -->
    <g id="node3" class="node">
    <title>completed</title>
    <path fill="#40e0d0" stroke="#000000" stroke-width="2" d="M627,-59C627,-59 589,-59 589,-59 583,-59 577,-53 577,-47 577,-47 577,-35 577,-35 577,-29 583,-23 589,-23 589,-23 627,-23 627,-23 633,-23 639,-29 639,-35 639,-35 639,-47 639,-47 639,-53 633,-59 627,-59"/>
    <path fill="none" stroke="#000000" stroke-width="2" d="M631,-63C631,-63 585,-63 585,-63 579,-63 573,-57 573,-51 573,-51 573,-31 573,-31 573,-25 579,-19 585,-19 585,-19 631,-19 631,-19 637,-19 643,-25 643,-31 643,-31 643,-51 643,-51 643,-57 637,-63 631,-63"/>
    <text text-anchor="middle" x="608" y="-38.5" font-family="Times,serif" font-size="10.00" fill="#000000">Completed</text>
    </g>
    <!-- shipping -->
    <g id="node5" class="node">
    <title>shipping</title>
    <path fill="#ffffff" stroke="#000000" d="M486,-59C486,-59 456,-59 456,-59 450,-59 444,-53 444,-47 444,-47 444,-35 444,-35 444,-29 450,-23 456,-23 456,-23 486,-23 486,-23 492,-23 498,-29 498,-35 498,-35 498,-47 498,-47 498,-53 492,-59 486,-59"/>
    <text text-anchor="middle" x="471" y="-38.5" font-family="Times,serif" font-size="10.00" fill="#000000">Shipping</text>
    </g>
    <!-- processing&#45;&gt;shipping -->
    <g id="edge2" class="edge">
    <title>processing&#45;&gt;shipping</title>
    <path fill="none" stroke="#0000ff" d="M338.277,-41C365.2542,-41 404.8233,-41 433.7361,-41"/>
    <polygon fill="#0000ff" stroke="#0000ff" points="433.863,-44.5001 443.863,-41 433.8629,-37.5001 433.863,-44.5001"/>
    <text text-anchor="middle" x="391" y="-53.8" font-family="Times,serif" font-size="9.00" fill="#000000">process_order</text>
    <text text-anchor="middle" x="391" y="-43.8" font-family="Times,serif" font-size="9.00" fill="#000000">[payment_received]</text>
    </g>
    <!-- shipping&#45;&gt;completed -->
    <g id="edge3" class="edge">
    <title>shipping&#45;&gt;completed</title>
    <path fill="none" stroke="#0000ff" d="M498.0668,-41C516.4958,-41 541.3337,-41 562.7377,-41"/>
    <polygon fill="#0000ff" stroke="#0000ff" points="562.9262,-44.5001 572.9262,-41 562.9261,-37.5001 562.9262,-44.5001"/>
    <text text-anchor="middle" x="535.5" y="-43.8" font-family="Times,serif" font-size="9.00" fill="#000000">ship_order</text>
    </g>
    </g>
    </svg>
    </div>
    </div>
    <br />
    <br />

.. GENERATED FROM PYTHON SOURCE LINES 134-137

.. code-block:: default

    assert order.order_total == 10
    assert order.payments == [4, 6]
    assert control.completed.is_active








.. _sphx_glr_download_auto_examples_order_control_rich_model_machine.py:

.. only:: html

  .. container:: sphx-glr-footer sphx-glr-footer-example


    .. container:: sphx-glr-download sphx-glr-download-python

      :download:`Download Python source code: order_control_rich_model_machine.py <order_control_rich_model_machine.py>`

    .. container:: sphx-glr-download sphx-glr-download-jupyter

      :download:`Download Jupyter notebook: order_control_rich_model_machine.ipynb <order_control_rich_model_machine.ipynb>`
