<odoo>
    <data>

        <record id="mklab_dms_document.res_partner_inherit" model="ir.ui.view">
            <field name="name">mklab_dms_document.res_partner_inherit</field>
            <field name="model">res.partner</field>
            <field name="inherit_id" ref="base.view_partner_form"/>
            <field name="arch" type="xml">
                <xpath expr="//div[@name='button_box']" position="inside">
                    <button class="oe_stat_button" type="object" icon="fa-book" name="action_show_document_incoming"
                            string="Входящие документы"/>
                    <button class="oe_stat_button" type="object" icon="fa-book" name="action_show_document_outgoing"
                            string="Исходящие документы"/>
                </xpath>
            </field>
        </record>

        <record id="mklab_dms_document.rule_company_document" model="ir.rule">
            <field name="name">Документы</field>
            <field name="model_id" ref="model_dms_document"/>
            <field name="global" eval="True"/>
            <field name="domain_force">['|',('company_id','=',False),('company_id', 'in', company_ids)]</field>
        </record>

        <record model="ir.ui.view" id="mklab_dms_document.form_template_wiz">
            <field name="name">mklab_dms_document form_template_wiz</field>
            <field name="model">dms.choise_template</field>
            <field name="arch" type="xml">
                <form>
                    <header>
                    </header>
                    <sheet>
                        <group>
                            <field name="temp_id"/>
                            <field name="doc_id" invisible='1'/>
                            <field name="company_id" invisible='1'/>
                        </group>
                    </sheet>
                    <footer>
                        <button string="Выбрать" name='get_choise' type="object"/>
                        <button string="Отмена" special="cancel"/>
                    </footer>
                </form>
            </field>
        </record>

        <record model="ir.ui.view" id="mklab_dms_document.list_template">
            <field name="name">mklab_dms_document list_template</field>
            <field name="model">dms.template</field>
            <field name="arch" type="xml">
                <list>
                    <field name="name"/>
                    <field name="company_id"/>
                </list>
            </field>
        </record>

        <record model="ir.ui.view" id="mklab_dms_document.list">
            <field name="name">mklab_dms_document list</field>
            <field name="model">dms.document</field>
            <field name="arch" type="xml">
                <list>
                    <field name="name"/>
                    <field name="date"/>
                    <field name="partner_id"/>
                    <field name="state"/>
                    <field name="company_id"/>
                </list>
            </field>
        </record>

        <record model="ir.ui.view" id="mklab_dms_document.form_template">
            <field name="name">mklab_dms_document form_template</field>
            <field name="model">dms.template</field>
            <field name="arch" type="xml">
                <form>
                    <header>
                    </header>
                    <sheet>
                        <h1>
                            <field name="name"/>
                        </h1>
                        <field name="text"/>
                        <group>
                            <field name="company_id"/>
                        </group>

                    </sheet>
                </form>
            </field>
        </record>

        <record model="ir.ui.view" id="mklab_dms_document.form">
            <field name="name">mklab_dms_document form</field>
            <field name="model">dms.document</field>
            <field name="arch" type="xml">
                <form>
                    <header>
                        <!--button name='render_template' type='object' string='render'/-->
                        <button name='open_choise_template' type='object' string='Создать текст из шаблона'
                                invisible="type_document != 'outgoing' or state =='done'"/>
                        <button name='create_pdf' type='object' string='Сформировать PDF и записать в хранилище'
                                invisible="type_document != 'outgoing' or state == 'done'"/>
                        <button name='create_pdf' type='object' string='Записать в хранилище'
                                invisible="type_document != 'incoming' or state == 'done'"/>
                        <button
                                name="request_validation"
                                string="Request Validation"
                                invisible="need_validation != True or rejected == True or state not in ['draft']"
                                type="object"
                        />
                        <button
                                name="restart_validation"
                                string="Restart Validation"
                                invisible="not review_ids or state not in ['draft']"
                                type="object"
                        />
                        <field name="state" widget="statusbar"/>
                    </header>
                    <field name="need_validation" invisible="1"/>
                    <field name="validated" invisible="1"/>
                    <field name="rejected" invisible="1"/>
                    <div
                            class="alert alert-warning"
                            role="alert"
                            invisible="validated == True or state not in ['draft'] or rejected == True or not review_ids"
                            style="margin-bottom:0px;"
                    >
                        <p><i class="fa fa-info-circle"/>Требуется валидация
                            <field name="can_review" invisible="1"/>
                            <button
                                    name="validate_tier"
                                    string="Validate"
                                    invisible="can_review == False"
                                    type="object"
                                    class="oe_inline oe_button btn-success"
                                    icon="fa-thumbs-up"
                            />
                            <button
                                    name="reject_tier"
                                    string="Reject"
                                    invisible="can_review == False"
                                    type="object"
                                    class="btn-icon btn-danger"
                                    icon="fa-thumbs-down"
                            />
                        </p>
                    </div>
                    <div
                            class="alert alert-success"
                            role="alert"
                            invisible="validated != True or state not in ['draft'] or not review_ids"
                            style="margin-bottom:0px;"
                    >
                        <p>
                            <i class="fa fa-thumbs-up"/>
                            <b>Валидация прошла успешно</b>!
                        </p>
                    </div>
                    <div
                            class="alert alert-danger"
                            role="alert"
                            invisible="rejected != True or state not in ['draft'] or not review_ids"
                            style="margin-bottom:0px;"
                    >
                        <p>
                            <i class="fa fa-thumbs-down"/>
                            Валидация <b>отклонена</b>.
                        </p>
                    </div>

                    <sheet>
                        <h1>
                            <field name="name" readonly="state == 'done'"/>
                        </h1>
                        <group>
                            <group>
                                <field name="date" readonly="state == 'done'"/>
                                <field name="partner_id" readonly="state == 'done'"/>
                                <field name="type_document" readonly='True'/>
                                <field name="print_head" readonly="state == 'done'"/>
                                <field name="company_id" readonly="state == 'done'"/>
                            </group>
                            <group>
                                <field name="file" readonly="state == 'done'"/>
                                <field name="directory_id" readonly="state == 'done'"/>
                                <field name="link_model" readonly="state == 'done'"/>
                                <field name="res_id" readonly="state == 'done'"/>
                                <field name="parent_id" readonly="state == 'done'"/>
                            </group>
                        </group>

                        <notebook>
                            <page name='page_document' string='Документ'>
                                <field name="text"
                                       invisible="type_document != 'outgoing'" readonly="state == 'done'"/>
                                <field name="text_str" invisible='1'/>
                                <field name="text_render" invisible='1'/>
                                <field name="text_render" invisible='1'/>
                                <group>
                                    <field name="incoming_file_type"
                                           invisible="type_document != 'incoming'" readonly="state == 'done'"/>
                                    <field name="incoming_file"
                                           invisible="type_document != 'incoming' or incoming_file_type != 'pdf'" readonly="state == 'done'"
                                           widget="pdf_viewer"/>
                                    <field name="incoming_file" string="Сформированный документ"
                                           invisible="type_document == 'incoming' and state != 'done'" readonly="state == 'done'"
                                           widget="pdf_viewer"/>
                                    <field name="incoming_file_other"
                                           invisible="type_document == 'incoming' or state != 'done'" readonly="state == 'done'"/>
                                </group>
                            </page>
                            <page name='page_chain_document' string='Цепочка документов'>
                                <field name="child_ids" readonly="state == 'done'"/>
                            </page>
                        </notebook>

                        <label for="create_uid" string="Автор документа: "/>
                        <field name="create_uid"/>
                    </sheet>
                    <field
                            name="review_ids"
                            widget="tier_validation"
                            invisible="not review_ids"
                    />
                    <div class="oe_chatter"/>
                </form>
            </field>
        </record>


        <record model="ir.actions.act_window" id="mklab_dms_document.action_window_template">
            <field name="name">Шаблоны</field>
            <field name="res_model">dms.template</field>
            <field name="view_mode">list,form</field>
        </record>

        <record model="ir.actions.act_window" id="mklab_dms_document.action_window_incoming">
            <field name="name">Входящие</field>
            <field name="res_model">dms.document</field>
            <field name="view_mode">list,form</field>
            <field name="context">{'default_type_document':'incoming'}</field>
            <field name="domain">[('type_document', '=', 'incoming')]</field>
        </record>

        <record model="ir.actions.act_window" id="mklab_dms_document.action_window_outgoing">
            <field name="name">Исходящие</field>
            <field name="res_model">dms.document</field>
            <field name="view_mode">list,form</field>
            <field name="context">{'default_type_document':'outgoing'}</field>
            <field name="domain">[('type_document', '=', 'outgoing')]</field>
        </record>

        <record model="ir.actions.act_window" id="mklab_dms_document.action_window_internal">
            <field name="name">Внутренние</field>
            <field name="res_model">dms.document</field>
            <field name="view_mode">list,form</field>
            <field name="context">{'default_type_document':'internal'}</field>
            <field name="domain">[('type_document', '=', 'internal')]</field>
        </record>

        <menuitem name="Документы" id="mklab_dms_document.documents" parent="dms.main_menu_dms"/>
        <menuitem name="Шаблоны" id="mklab_dms_document.template_menu" parent="mklab_dms_document.documents"
                  action="mklab_dms_document.action_window_template"/>
        <menuitem name="Входящие" id="mklab_dms_document.incoming" parent="mklab_dms_document.documents"
                  action="mklab_dms_document.action_window_incoming"/>
        <menuitem name="Исходящие" id="mklab_dms_document.outgoing" parent="mklab_dms_document.documents"
                  action="mklab_dms_document.action_window_outgoing"/>
        <!--menuitem name="Внутренние" id="mklab_dms_document.internal" parent="mklab_dms_document.documents" action="mklab_dms_document.action_window_internal"/-->

    </data>
</odoo>