<?xml version="1.0" encoding="utf-8"?>
<openerp>
    <data>
        <!-- 
            Illustrate bug #399817
            SO not marked picked when 2nd delivery canceled
            
        -->

        <!-- Resource: sale.order -->
        <record id="bug399817" model="sale.order">
            <field name="shop_id" ref="shop" />
            <field name="name">lp:399817</field>
            <field name="note">This Order was created to assert that the following bug is fixed:
                https://bugs.launchpad.net/openobject-addons/+bug/399817
            </field>
            <field model="product.pricelist" name="pricelist_id" search="[]" />
            <field name="user_id" ref="base.user_demo" />
            <field name="partner_id" ref="base.res_partner_3" />
            <field name="partner_invoice_id" ref="base.res_partner_address_zen" />
            <field name="partner_shipping_id" ref="base.res_partner_address_zen" />
            <field name="partner_order_id" ref="base.res_partner_address_zen" />
        </record>
        <record id="bug399817_line1" model="sale.order.line">
            <field name="order_id" ref="bug399817" />
            <field name="name">[PC2] Basic+ PC (assembly on order)</field>
            <field name="product_id" ref="product.product_product_pc2" />
            <field name="product_uom" ref="product.product_uom_unit" />
            <field name="product_uom_qty">4</field>
            <field name="price_unit">750</field>
            <field name="type">make_to_order</field>
            <field name="delay">15</field>
        </record>
        <workflow action="order_confirm" model="sale.order" ref="bug399817" />

        <!-- copy packing and do the first one -->
        <!-- this is similar to what the partial packing wizard does (except for quantities) -->
        <function model="stock.picking" name="copy">
            <value eval="obj(ref('bug399817')).picking_ids[0].id" model="sale.order" />
        </function>
        <function model="stock.picking" name="draft_validate">
            <value eval="[obj(ref('bug399817')).picking_ids[0].id]" model="sale.order" />
        </function>
        <assert id="bug399817" model="sale.order" severity="warning" string="the sale order's first picking is done">
            <test expr="len(picking_ids) == 2" />
            <test expr="picking_ids[0].state">done</test>
        </assert>

        <!-- cancel the second packing -->
        <function model="stock.picking" name="action_cancel">
            <value eval="[obj(ref('bug399817')).picking_ids[1].id]" model="sale.order" />
        </function>
        <assert id="bug399817" model="sale.order" severity="warn" string="the sale order's second picking is cancelled">
            <test expr="picking_ids[1].state">cancel</test>
        </assert>
        <assert id="bug399817" model="sale.order" severity="error" string="the sale order's is picked">
            <test expr="shipped == True" /> <!-- at this stage, the order should be marked picked -->
        </assert>
    </data>
</openerp>
