<?xml version="1.0"?>
<!-- This file is part of Tryton.  The COPYRIGHT file at the top level of
this repository contains the full copyright notices and license terms. -->
<tryton>
    <data>
        <record model="res.group" id="group_sale">
            <field name="name">Sales</field>
        </record>
        <record model="res.group" id="group_sale_admin">
            <field name="name">Sales Administrator</field>
        </record>
        <record model="res.user-res.group" id="user_admin_group_sale">
            <field name="user" ref="res.user_admin"/>
            <field name="group" ref="group_sale"/>
        </record>
        <record model="res.user-res.group" id="user_admin_group_sale_admin">
            <field name="user" ref="res.user_admin"/>
            <field name="group" ref="group_sale_admin"/>
        </record>

        <record model="res.user-res.group" id="user_trigger_group_sale">
            <field name="user" ref="res.user_trigger"/>
            <field name="group" ref="group_sale"/>
        </record>
        <record model="res.user-res.group" id="user_trigger_group_sale_admin">
            <field name="user" ref="res.user_trigger"/>
            <field name="group" ref="group_sale_admin"/>
        </record>

        <menuitem name="Sales" id="menu_sale" sequence="5"/>
        <record model="ir.ui.menu-res.group" id="menu_sale_group_sale">
            <field name="menu" ref="menu_sale"/>
            <field name="group" ref="group_sale"/>
        </record>

        <record model="ir.action.wizard" id="wizard_shipment_handle_exception">
            <field name="name">Handle Shipment Exception</field>
            <field name="wiz_name">sale.handle.shipment.exception</field>
            <field name="model">sale.sale</field>
        </record>

        <record model="ir.action.wizard" id="wizard_invoice_handle_exception">
            <field name="name">Handle Invoice Exception</field>
            <field name="wiz_name">sale.handle.invoice.exception</field>
            <field name="model">sale.sale</field>
        </record>

        <record model="ir.ui.view" id="sale_view_form">
            <field name="model">sale.sale</field>
            <field name="type">form</field>
            <field name="arch" type="xml">
                <![CDATA[
                <form string="Sale" col="6">
                    <label name="party"/>
                    <field name="party"/>
                    <label name="invoice_address"/>
                    <field name="invoice_address"/>
                    <label name="shipment_address"/>
                    <field name="shipment_address"/>
                    <label name="description"/>
                    <field name="description" colspan="3"/>
                    <label name="reference"/>
                    <field name="reference"/>
                    <notebook colspan="6">
                        <page string="Sale" id="sale">
                            <label name="sale_date"/>
                            <field name="sale_date"/>
                            <label name="payment_term"/>
                            <field name="payment_term"/>
                            <label name="warehouse"/>
                            <field name="warehouse"/>
                            <label name="currency"/>
                            <field name="currency"/>
                            <field name="lines" colspan="4"
                                view_ids="sale.sale_line_view_tree_sequence"/>
                            <group col="2" colspan="2" id="states">
                                <label name="invoice_state"/>
                                <field name="invoice_state"/>
                                <label name="shipment_state"/>
                                <field name="shipment_state"/>
                                <label name="state"/>
                                <field name="state"/>
                            </group>
                            <group col="2" colspan="2" id="amount_buttons">
                                <label name="untaxed_amount" xalign="1.0" xexpand="1"/>
                                <field name="untaxed_amount" xalign="1.0" xexpand="0"/>
                                <label name="tax_amount" xalign="1.0" xexpand="1"/>
                                <field name="tax_amount" xalign="1.0" xexpand="0"/>
                                <label name="total_amount" xalign="1.0" xexpand="1"/>
                                <field name="total_amount" xalign="1.0" xexpand="0"/>
                                <group col="7" colspan="2" id="buttons">
                                    <button name="cancel" type="object" string="Cancel"
                                        icon="tryton-cancel"/>
                                    <button name="draft" type="object" string="Draft"
                                        icon="tryton-go-previous"/>
                                    <button name="quote" type="object" string="Quote"
                                        icon="tryton-go-next"/>
                                    <button name="%(wizard_invoice_handle_exception)d"
                                            string="Handle Invoice Exception"
                                            type="action"
                                            states="{'invisible': Or(Not(Equal(Eval('invoice_state'), 'exception')), Equal(Eval('state'), 'cancel')), 'readonly': Not(In(%(group_sale)d, Eval('groups', [])))}"
                                            icon="tryton-go-next"/>
                                    <button name="%(wizard_shipment_handle_exception)d"
                                            type="action"
                                            string="Handle Shipment Exception"
                                            states="{'invisible': Or(Not(Equal(Eval('shipment_state'), 'exception')), Equal(Eval('state'), 'cancel')), 'readonly': Not(In(%(group_sale)d, Eval('groups', [])))}"
                                            icon="tryton-go-next"/>
                                    <button name="confirm" type="object" string="Confirm"
                                        icon="tryton-go-next"/>
                                    <button name="process" type="object" string="Process"
                                        icon="tryton-go-next"/>
                                </group>
                            </group>
                        </page>
                        <page string="Other Info" id="other">
                            <label name="company"/>
                            <field name="company"/>
                            <newline/>
                            <label name="invoice_method"/>
                            <field name="invoice_method"/>
                            <label name="shipment_method"/>
                            <field name="shipment_method"/>
                            <separator name="comment" colspan="4"/>
                            <field name="comment" colspan="4" spell="Eval('party_lang')"/>
                        </page>
                        <page string="Invoices" id="invoices">
                            <field name="invoices" colspan="4"/>
                        </page>
                        <page string="Shipments" id="shipments">
                            <field name="moves" colspan="4"
                                view_ids="sale.move_view_list_shipment"/>
                            <field name="shipments" colspan="4"/>
                            <field name="shipment_returns" colspan="4"/>
                        </page>
                    </notebook>
                    <field name="currency_digits" invisible="1" colspan="6"/>
                    <field name="party_lang" invisible="1" colspan="6"/>
                </form>
                ]]>
            </field>
        </record>
        <record model="ir.ui.view" id="sale_view_tree">
            <field name="model">sale.sale</field>
            <field name="type">tree</field>
            <field name="arch" type="xml">
                <![CDATA[
                <tree string="Sales">
                    <field name="reference"/>
                    <field name="sale_date"/>
                    <field name="party"/>
                    <field name="warehouse"/>
                    <field name="currency"/>
                    <field name="untaxed_amount"/>
                    <field name="total_amount"/>
                    <field name="state"/>
                    <field name="invoice_state"/>
                    <field name="shipment_state"/>
                    <field name="description"/>
                    <field name="currency_digits" tree_invisible="1"/>
                    <field name="create_date" tree_invisible="1"/>
                </tree>
                ]]>
            </field>
        </record>

        <record model="ir.ui.view" id="handle_shipment_exception_ask_view_form">
            <field name="model">sale.handle.shipment.exception.ask</field>
            <field name="type">form</field>
            <field name="arch" type="xml">
                <![CDATA[
                <form string="Handle shipment Exception" col="2">
                    <image name="tryton-dialog-information" xexpand="0"
                        xfill="0"/>
                    <label string="Choose move to recreate"
                        id="choose"
                        yalign="0.0" xalign="0.0" xexpand="1"/>
                    <field name="recreate_moves" colspan="2"
                        view_ids="stock.move_view_tree"/>
                </form>
                ]]>
            </field>
        </record>

        <record model="ir.ui.view" id="handle_invoice_exception_ask_view_form">
            <field name="model">sale.handle.invoice.exception.ask</field>
            <field name="type">form</field>
            <field name="arch" type="xml">
                <![CDATA[
                <form string="Handle Invoice Exception" col="2">
                    <image name="tryton-dialog-information" xexpand="0"
                        xfill="0"/>
                    <label string="Choose invoices to recreate"
                        id="choose"
                        yalign="0.0" xalign="0.0" xexpand="1"/>
                    <field name="recreate_invoices" colspan="2"/>
                </form>
                ]]>
            </field>
        </record>

        <record model="ir.action.act_window" id="act_shipment_form">
            <field name="name">Shipments</field>
            <field name="res_model">stock.shipment.out</field>
            <field name="domain">[("id", "in", Eval('shipments'))]</field>
        </record>
        <record model="ir.action.keyword"
                id="act_open_shipment_keyword1">
            <field name="keyword">form_relate</field>
            <field name="model">sale.sale,-1</field>
            <field name="action" ref="act_shipment_form"/>
        </record>
        <record model="ir.action.act_window" id="act_return_form">
            <field name="name">Returns</field>
            <field name="res_model">stock.shipment.out.return</field>
            <field name="domain">[("id", "in", Eval('shipment_returns'))]</field>
        </record>
        <record model="ir.action.keyword" id="act_open_shipment_return_keyword1">
            <field name="keyword">form_relate</field>
            <field name="model">sale.sale,-1</field>
            <field name="action" ref="act_return_form"/>
        </record>
        <record model="ir.action.act_window" id="act_invoice_form">
            <field name="name">Invoices</field>
            <field name="res_model">account.invoice</field>
            <field name="domain">[("id", "in", Eval('invoices'))]</field>
        </record>
        <record model="ir.action.keyword"
                id="act_open_invoice_keyword1">
            <field name="keyword">form_relate</field>
            <field name="model">sale.sale,-1</field>
            <field name="action" ref="act_invoice_form"/>
        </record>

        <record model="ir.action.act_window" id="act_sale_form">
            <field name="name">Sales</field>
            <field name="res_model">sale.sale</field>
            <field name="search_value">[('create_date', '>=', DateTime(hour=0, minute=0, second=0, microsecond=0, delta_years=-1))]</field>
        </record>
        <record model="ir.action.act_window.view" id="act_sale_form_view1">
            <field name="sequence" eval="10"/>
            <field name="view" ref="sale_view_tree"/>
            <field name="act_window" ref="act_sale_form"/>
        </record>
        <record model="ir.action.act_window.view" id="act_sale_form_view2">
            <field name="sequence" eval="20"/>
            <field name="view" ref="sale_view_form"/>
            <field name="act_window" ref="act_sale_form"/>
        </record>
        <menuitem parent="menu_sale" action="act_sale_form"
            id="menu_sale_form" sequence="10"/>
        <record model="ir.ui.menu-res.group" id="menu_sale_form_group_sale">
            <field name="menu" ref="menu_sale_form"/>
            <field name="group" ref="group_sale"/>
        </record>

        <record model="ir.action.act_window" id="act_sale_form_draft">
            <field name="name">Draft Sales</field>
            <field name="res_model">sale.sale</field>
            <field name="domain">[('state', '=', 'draft')]</field>
        </record>
        <record model="ir.action.act_window.view" id="act_sale_form_draft_view1">
            <field name="sequence" eval="10"/>
            <field name="view" ref="sale_view_tree"/>
            <field name="act_window" ref="act_sale_form_draft"/>
        </record>
        <record model="ir.action.act_window.view" id="act_sale_form_draft_view2">
            <field name="sequence" eval="20"/>
            <field name="view" ref="sale_view_form"/>
            <field name="act_window" ref="act_sale_form_draft"/>
        </record>
        <menuitem parent="menu_sale_form" action="act_sale_form_draft"
            id="menu_sale_form_draft" sequence="20"/>

        <record model="ir.action.act_window" id="act_sale_form_quotation">
            <field name="name">Quotation Sales</field>
            <field name="res_model">sale.sale</field>
            <field name="domain">[('state', '=', 'quotation')]</field>
        </record>
        <record model="ir.action.act_window.view" id="act_sale_form_quotation_view1">
            <field name="sequence" eval="10"/>
            <field name="view" ref="sale_view_tree"/>
            <field name="act_window" ref="act_sale_form_quotation"/>
        </record>
        <record model="ir.action.act_window.view" id="act_sale_form_quotation_view2">
            <field name="sequence" eval="20"/>
            <field name="view" ref="sale_view_form"/>
            <field name="act_window" ref="act_sale_form_quotation"/>
        </record>
        <menuitem parent="menu_sale_form" action="act_sale_form_quotation"
            id="menu_sale_form_quotation" sequence="30"/>

        <record model="ir.action.act_window" id="act_sale_form_confirmed">
            <field name="name">Confirmed Sales</field>
            <field name="res_model">sale.sale</field>
            <field name="domain">[('state', '=', 'confirmed')]</field>
        </record>
        <record model="ir.action.act_window.view" id="act_sale_form_confirmed_view1">
            <field name="sequence" eval="10"/>
            <field name="view" ref="sale_view_tree"/>
            <field name="act_window" ref="act_sale_form_confirmed"/>
        </record>
        <record model="ir.action.act_window.view" id="act_sale_form_confirmed_view2">
            <field name="sequence" eval="20"/>
            <field name="view" ref="sale_view_form"/>
            <field name="act_window" ref="act_sale_form_confirmed"/>
        </record>
        <menuitem parent="menu_sale_form" action="act_sale_form_confirmed"
            id="menu_sale_form_confirmed" sequence="40"/>

        <record model="ir.action.act_window" id="act_sale_form_processing">
            <field name="name">Processing Sales</field>
            <field name="res_model">sale.sale</field>
            <field name="domain">[('state', '=', 'processing')]</field>
        </record>
        <record model="ir.action.act_window.view" id="act_sale_form_processing_view1">
            <field name="sequence" eval="10"/>
            <field name="view" ref="sale_view_tree"/>
            <field name="act_window" ref="act_sale_form_processing"/>
        </record>
        <record model="ir.action.act_window.view" id="act_sale_form_processing_view2">
            <field name="sequence" eval="20"/>
            <field name="view" ref="sale_view_form"/>
            <field name="act_window" ref="act_sale_form_processing"/>
        </record>
        <menuitem parent="menu_sale_form" action="act_sale_form_processing"
            id="menu_sale_form_processing" sequence="50"/>

        <record model="ir.model.access" id="access_sale">
            <field name="model" search="[('model', '=', 'sale.sale')]"/>
            <field name="perm_read" eval="False"/>
            <field name="perm_write" eval="False"/>
            <field name="perm_create" eval="False"/>
            <field name="perm_delete" eval="False"/>
        </record>
        <record model="ir.model.access" id="access_sale_sale">
            <field name="model" search="[('model', '=', 'sale.sale')]"/>
            <field name="group" ref="group_sale"/>
            <field name="perm_read" eval="True"/>
            <field name="perm_write" eval="True"/>
            <field name="perm_create" eval="True"/>
            <field name="perm_delete" eval="True"/>
        </record>

        <record model="ir.model.button" id="sale_cancel_button">
            <field name="name">cancel</field>
            <field name="model" search="[('model', '=', 'sale.sale')]"/>
        </record>
        <record model="ir.model.button-res.group" id="sale_cancel_button_group_sale">
            <field name="button" ref="sale_cancel_button"/>
            <field name="group" ref="group_sale"/>
        </record>

        <record model="ir.model.button" id="sale_draft_button">
            <field name="name">draft</field>
            <field name="model" search="[('model', '=', 'sale.sale')]"/>
        </record>
        <record model="ir.model.button-res.group" id="sale_draft_button_group_sale">
            <field name="button" ref="sale_draft_button"/>
            <field name="group" ref="group_sale"/>
        </record>

        <record model="ir.model.button" id="sale_quote_button">
            <field name="name">quote</field>
            <field name="model" search="[('model', '=', 'sale.sale')]"/>
        </record>
        <record model="ir.model.button-res.group" id="sale_quote_button_group_sale">
            <field name="button" ref="sale_quote_button"/>
            <field name="group" ref="group_sale"/>
        </record>

        <record model="ir.model.button" id="sale_confirm_button">
            <field name="name">confirm</field>
            <field name="model" search="[('model', '=', 'sale.sale')]"/>
        </record>
        <record model="ir.model.button-res.group" id="sale_confirm_button_group_sale">
            <field name="button" ref="sale_confirm_button"/>
            <field name="group" ref="group_sale"/>
        </record>

        <record model="ir.model.button" id="sale_process_button">
            <field name="name">process</field>
            <field name="model" search="[('model', '=', 'sale.sale')]"/>
        </record>
        <record model="ir.model.button-res.group" id="sale_process_button_group_sale">
            <field name="button" ref="sale_process_button"/>
            <field name="group" ref="group_sale"/>
        </record>

        <record model="ir.sequence.type" id="sequence_type_sale">
            <field name="name">Sale</field>
            <field name="code">sale.sale</field>
        </record>
        <record model="ir.sequence.type-res.group"
            id="sequence_type_sale_group_admin">
            <field name="sequence_type" ref="sequence_type_sale"/>
            <field name="group" ref="res.group_admin"/>
        </record>
        <record model="ir.sequence.type-res.group"
            id="sequence_type_sale_group_sale_admin">
            <field name="sequence_type" ref="sequence_type_sale"/>
            <field name="group" ref="group_sale_admin"/>
        </record>

        <record model="ir.sequence" id="sequence_sale">
            <field name="name">Sale</field>
            <field name="code">sale.sale</field>
        </record>

        <record model="ir.action.report" id="report_sale">
            <field name="name">Sale</field>
            <field name="model">sale.sale</field>
            <field name="report_name">sale.sale</field>
            <field name="report">sale/sale.odt</field>
            <field name="style">company/header_A4.odt</field>
        </record>
        <record model="ir.action.keyword" id="report_sale_keyword">
            <field name="keyword">form_print</field>
            <field name="model">sale.sale,-1</field>
            <field name="action" ref="report_sale"/>
        </record>

        <record model="ir.ui.view" id="sale_line_view_form">
            <field name="model">sale.line</field>
            <field name="type">form</field>
            <field name="arch" type="xml">
                <![CDATA[
                <form string="Sale Line" cursor="product">
                    <label name="sale"/>
                    <field name="sale" colspan="3"/>
                    <notebook colspan="4">
                        <page string="General" id="general">
                            <label name="type"/>
                            <field name="type"/>
                            <label name="sequence"/>
                            <field name="sequence"/>
                            <label name="product"/>
                            <field name="product"
                                view_ids="sale.product_view_list_sale_line"/>
                            <newline/>
                            <label name="description"/>
                            <field name="description" colspan="3"
                                spell="Get(Eval('_parent_sale', {}), 'party_lang')"/>
                            <label name="quantity"/>
                            <field name="quantity"/>
                            <label name="unit"/>
                            <field name="unit"/>
                            <label name="unit_price"/>
                            <field name="unit_price"/>
                            <label name="amount"/>
                            <field name="amount"/>
                            <label name="delivery_date"/>
                            <field name="delivery_date"/>
                            <field name="taxes" colspan="4"/>
                        </page>
                        <page string="Notes" id="notes">
                            <separator name="note" colspan="4"/>
                            <field name="note" colspan="4"
                                spell="Get(Eval('_parent_sale', {}), 'party_lang')"/>
                        </page>
                    </notebook>
                    <field name="unit_digits" invisible="1" colspan="4"/>
                </form>
                ]]>
            </field>
        </record>

        <record model="ir.ui.view" id="sale_line_view_tree">
            <field name="model">sale.line</field>
            <field name="type">tree</field>
            <field name="priority" eval="10"/>
            <field name="arch" type="xml">
                <![CDATA[
                <tree string="Sale Lines">
                    <field name="sale"/>
                    <field name="type"/>
                    <field name="product"/>
                    <field name="description"/>
                    <field name="quantity"/>
                    <field name="unit"/>
                    <field name="unit_price"/>
                    <field name="taxes"/>
                    <field name="amount"/>
                    <field name="unit_digits" tree_invisible="1"/>
                </tree>
                ]]>
            </field>
        </record>

        <record model="ir.ui.view" id="sale_line_view_tree_sequence">
            <field name="model">sale.line</field>
            <field name="type">tree</field>
            <field name="priority" eval="20"/>
            <field name="arch" type="xml">
                <![CDATA[
                <tree string="Sale Lines" sequence="sequence">
                    <field name="type"/>
                    <field name="product"/>
                    <field name="description"/>
                    <field name="quantity"/>
                    <field name="unit"/>
                    <field name="unit_price"/>
                    <field name="taxes"/>
                    <field name="amount" expand="1"/>
                    <field name="unit_digits" tree_invisible="1"/>
                </tree>
                ]]>
            </field>
        </record>

        <record model="ir.model.access" id="access_sale_line">
            <field name="model" search="[('model', '=', 'sale.line')]"/>
            <field name="perm_read" eval="False"/>
            <field name="perm_write" eval="False"/>
            <field name="perm_create" eval="False"/>
            <field name="perm_delete" eval="False"/>
        </record>
        <record model="ir.model.access" id="access_sale_line_sale">
            <field name="model" search="[('model', '=', 'sale.line')]"/>
            <field name="group" ref="group_sale"/>
            <field name="perm_read" eval="True"/>
            <field name="perm_write" eval="True"/>
            <field name="perm_create" eval="True"/>
            <field name="perm_delete" eval="True"/>
        </record>

        <record model="ir.ui.view" id="template_view_form">
            <field name="model">product.template</field>
            <field name="inherit" ref="product.template_view_form"/>
            <field name="arch" type="xml">
                <![CDATA[
                <data>
                    <xpath expr="/form/notebook/page[@id=&quot;general&quot;]/field[@name=&quot;cost_price_method&quot;]"
                        position="after">
                        <label name="salable"/>
                        <field name="salable"/>
                    </xpath>
                    <xpath expr="/form/notebook/page[@id=&quot;general&quot;]"
                        position="after">
                        <page string="Customers"
                            states="{'invisible': Not(Bool(Eval('salable')))}"
                            id="customers">
                            <label name="salable"/>
                            <field name="salable"/>
                            <label name="sale_uom"/>
                            <field name="sale_uom"/>
                            <label name="delivery_time"/>
                            <field name="delivery_time"/>
                        </page>
                    </xpath>
                </data>
                ]]>
            </field>
        </record>
        <record model="ir.ui.view" id="template_view_tree">
            <field name="model">product.template</field>
            <field name="inherit" ref="product.template_view_tree"/>
            <field name="arch" type="xml">
                <![CDATA[
                <data>
                    <xpath expr="/tree/field[@name=&quot;default_uom&quot;]"
                        position="after">
                        <field name="salable"/>
                    </xpath>
                </data>
                ]]>
            </field>
        </record>

        <record model="ir.action.wizard" id="act_open_customer">
            <field name="name">Parties associated to Sales</field>
            <field name="wiz_name">sale.open_customer</field>
        </record>
        <menuitem name="Parties associated to Sales"
            parent="party.menu_party_form"
            action="act_open_customer"
            icon="tryton-list"
            id="menu_customer"/>

        <record model="ir.action.wizard" id="wizard_return_sale">
            <field name="name">Create Return Sale</field>
            <field name="wiz_name">sale.return_sale</field>
            <field name="model">sale.sale</field>
        </record>
        <record model="ir.action.keyword" id="act_wizard_return_sale_keyword">
            <field name="keyword">form_action</field>
            <field name="model">sale.sale,-1</field>
            <field name="action" ref="wizard_return_sale"/>
        </record>

        <record model="ir.rule.group" id="rule_group_sale">
            <field name="model" search="[('model', '=', 'sale.sale')]"/>
            <field name="global_p" eval="True"/>
        </record>
        <record model="ir.rule" id="rule_sale1">
            <field name="field" search="[('name', '=', 'company'), ('model.model', '=', 'sale.sale')]"/>
            <field name="operator">=</field>
            <field name="operand">User/Current Company</field>
            <field name="rule_group" ref="rule_group_sale"/>
        </record>

        <record model="ir.model.access" id="access_invoice_sale">
            <field name="model" search="[('model', '=', 'account.invoice')]"/>
            <field name="group" ref="group_sale"/>
            <field name="perm_read" eval="True"/>
            <field name="perm_write" eval="False"/>
            <field name="perm_create" eval="False"/>
            <field name="perm_delete" eval="False"/>
        </record>

        <record model="ir.model.access" id="access_invoice_line_sale">
            <field name="model" search="[('model', '=', 'account.invoice.line')]"/>
            <field name="group" ref="group_sale"/>
            <field name="perm_read" eval="True"/>
            <field name="perm_write" eval="False"/>
            <field name="perm_create" eval="False"/>
            <field name="perm_delete" eval="False"/>
        </record>

        <record model="ir.model.access" id="access_move_group_sale">
            <field name="model" search="[('model', '=', 'stock.move')]"/>
            <field name="group" ref="group_sale"/>
            <field name="perm_read" eval="True"/>
            <field name="perm_write" eval="False"/>
            <field name="perm_create" eval="False"/>
            <field name="perm_delete" eval="False"/>
        </record>

        <record model="ir.model.access" id="access_shipment_out_group_sale">
            <field name="model" search="[('model', '=', 'stock.shipment.out')]"/>
            <field name="group" ref="group_sale"/>
            <field name="perm_read" eval="True"/>
            <field name="perm_write" eval="False"/>
            <field name="perm_create" eval="False"/>
            <field name="perm_delete" eval="False"/>
        </record>

    </data>
</tryton>
