<?xml version="1.0" encoding="utf-8"?>
<terp>
    <data>
        <!-- This file must be loaded  _after_  account_demo.xml ! --> 
        <record id="test_invoice_1" model="account.invoice">
            <field name="currency_id" ref="base.EUR"/>
            <field name="company_id" ref="base.main_company"/>
            <field name="address_invoice_id" ref="base.res_partner_address_tang"/>
            <field name="partner_id" ref="base.res_partner_asus"/>
            <field name="journal_id" ref="account.sales_journal"/>
            <field name="state">draft</field>
            <field name="type">out_invoice</field>
            <field name="account_id" ref="account.a_recv"/>
            <field name="name">Test invoice 1</field>
            <field name="address_contact_id" ref="base.res_partner_address_tang"/>
        </record>
        <record id="test_invoice_1_line_1" model="account.invoice.line">
            <field name="name">Basic computer with Dvorak keyboard and left-handed mouse</field>
            <field name="invoice_id" ref="test_invoice_1"/>
            <field name="price_unit">250</field>
            <field name="quantity">1</field>
            <field name="account_id" ref="account.a_sale"/>
        </record>
        <record id="test_invoice_1_line_2" model="account.invoice.line">
            <field name="name">Little server with raid 1 and 512ECC ram</field>
            <field name="invoice_id" ref="test_invoice_1"/>
            <field name="price_unit">800</field>
            <field name="quantity">2</field>
            <field name="account_id" ref="account.a_sale"/>
        </record>
        
        <assert id="test_invoice_1" model="account.invoice" string="The currency unit of Test invoice 1 is EUR">
            <test expr="currency_id.code">EUR</test>
        </assert>
        
        <assert id="test_invoice_1" model="account.invoice" severity="error" string="The amount of Test invoice 1 is correct">
            <test expr="sum([l.price_subtotal for l in invoice_line]) == 1850"/>
            <test expr="sum([l.price_subtotal for l in invoice_line]) == amount_untaxed"/>
        </assert>
        
        <workflow action="invoice_open" model="account.invoice" ref="test_invoice_1"/>
        
        <assert id="test_invoice_1" model="account.invoice" string="Test invoice 1 is now open">
            <test expr="state">open</test>
        </assert>
        
        <!--
		 journal_id: bank_journal
		 period_id: period_7 (or 'period_' +time.strftime('m'))
		 pay_amount: 1850 (or amount_total)
		 acc_id = pool.get('account.journal').browse(cr, uid, journal_id, context).default_credit_account_id.id
		 pay_and_reconcile(self, cr, uid,
		 	ids,
			pay_amount,
			pay_account_id,
			period_id,
			pay_journal_id,
			writeoff_acc_id,
			writeoff_period_id,
			writeoff_journal_id,
			context={}):
		-->
        <function model="account.invoice" name="pay_and_reconcile">
            <value eval="[ref('test_invoice_1')]"/>
            <value eval="1850"/>
            <value eval="ref('cash')"/>
            <value eval="ref('account.period_' + str(int(time.strftime('%m'))))"/>
            <value eval="ref('bank_journal')"/>
            <value eval="ref('cash')"/>
            <value eval="ref('account.period_' + str(int(time.strftime('%m'))))"/>
            <value eval="ref('bank_journal')"/>
        </function>
        
        <assert id="test_invoice_1" model="account.invoice" string="Test invoice 1 is now paid">
            <test expr="state">paid</test>
        </assert>
    </data>
</terp>