<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<template id="report_saleorder_document">
    <t t-call="report.external_layout">
        <div class="page">
            <div class="oe_structure"/>
            <div class="row">
                <div class="col-xs-6">
                    <strong t-if="o.partner_shipping_id == o.partner_invoice_id">Invoice and shipping address:</strong>
                    <strong t-if="o.partner_shipping_id != o.partner_invoice_id">Invoice address:</strong>
                    <div t-field="o.partner_invoice_id" 
                        t-field-options='{"widget": "contact", "fields": ["address", "name", "phone", "fax"], "no_marker": true}'/>
                    <p t-if="o.partner_id.vat">VAT: <span t-field="o.partner_id.vat"/></p>
                    <div t-if="o.partner_shipping_id != o.partner_invoice_id" class="mt8">
                        <strong>Shipping address:</strong>
                        <div t-field="o.partner_shipping_id" 
                            t-field-options='{"widget": "contact", "fields": ["address", "name", "phone", "fax"], "no_marker": true}'/>
                        <p t-if="o.partner_id.vat">VAT: <span t-field="o.partner_id.vat"/></p>
                    </div>                        
                </div>
                <div class="col-xs-5 col-xs-offset-1">
                    <div t-field="o.partner_id"
                        t-field-options='{"widget": "contact", "fields": ["address", "name"], "no_marker": true}' />
                </div>
            </div>

            <h2>
                <span t-if="o.state not in ['draft','sent']">Order N° </span>
                <span t-if="o.state in ['draft','sent']">Quotation N° </span>
                <span t-field="o.name"/>
            </h2>

            <div class="row mt32 mb32" id="informations">
                <div t-if="o.client_order_ref" class="col-xs-3">
                    <strong>Your Reference:</strong>
                    <p t-field="o.client_order_ref"/>
                </div>
                <div t-if="o.date_order" class="col-xs-3">
                    <strong t-if="o.state not in ['draft','sent']">Date Ordered:</strong>
                    <strong t-if="o.state in ['draft','sent']">Quotation Date:</strong>
                    <p t-field="o.date_order"/>
                </div>
                <div t-if="o.user_id.name" class="col-xs-3">
                    <strong>Salesperson:</strong>
                    <p t-field="o.user_id.name"/>
                </div>
                <div t-if="o.payment_term" class="col-xs-3">
                    <strong>Payment Term:</strong>
                    <p t-field="o.payment_term"/>
                </div>
            </div>

            <table class="table table-condensed">
                <thead>
                    <tr>
                        <th>Description</th>
                        <th>Taxes</th>
                        <th class="text-right">Quantity</th>
                        <th class="text-right">Unit Price</th>
                        <th groups="sale.group_discount_per_so_line">Disc.(%)</th>
                        <th class="text-right">Price</th>
                    </tr>
               </thead>
               <tbody class="sale_tbody">
                    <tr t-foreach="o.order_line" t-as="l">
                        <td>
                           <span t-field="l.name"/>
                        </td>
                        <td>
                            <span t-esc="', '.join(map(lambda x: x.name, l.tax_id))"/>
                        </td>
                        <td class="text-right">
                            <span t-field="l.product_uom_qty"/>
                            <span groups="product.group_uom" t-field="l.product_uom"/>
                        </td>
                        <td class="text-right">
                            <span t-field="l.price_unit"/>
                        </td>
                        <td groups="sale.group_discount_per_so_line">
                            <span t-field="l.discount"/>
                        </td>
                        <td class="text-right">
                            <span t-field="l.price_subtotal"
                                t-field-options='{"widget": "monetary", "display_currency": "o.pricelist_id.currency_id"}'/>
                        </td>
                    </tr>
                </tbody>
            </table>

            <div class="row">
                <div class="col-xs-4 pull-right">
                    <table class="table table-condensed">
                        <tr class="border-black">
                            <td><strong>Total Without Taxes</strong></td>
                            <td class="text-right">
                                <span t-field="o.amount_untaxed"
                                    t-field-options='{"widget": "monetary", "display_currency": "o.pricelist_id.currency_id"}'/>
                            </td>
                        </tr>
                        <tr>
                            <td>Taxes</td>
                            <td class="text-right">
                                <span t-field="o.amount_tax"
                                    t-field-options='{"widget": "monetary", "display_currency": "o.pricelist_id.currency_id"}'/>
                            </td>
                        </tr>
                        <tr class="border-black">
                            <td><strong>Total</strong></td>
                            <td class="text-right">
                                <span t-field="o.amount_total"
                                    t-field-options='{"widget": "monetary", "display_currency": "o.pricelist_id.currency_id"}'/>
                            </td>
                        </tr>
                    </table>
                </div>
            </div>

            <p t-field="o.note" />
            <p t-if="o.payment_term.note">
                <strong>Payment Term:</strong>
                <span t-field="o.payment_term.note"/>
            </p>
            <div class="oe_structure"/>
        </div>
    </t>
</template>

<template id="report_saleorder">
    <t t-call="report.html_container">
        <t t-foreach="doc_ids" t-as="doc_id">
            <t t-raw="translate_doc(doc_id, doc_model, 'partner_id.lang', 'sale.report_saleorder_document')"/>
        </t>
    </t>
</template>
</data>
</openerp>
