<odoo>
    <data>
        <record id="visits_form_kanban_view" model="ir.ui.view">
            <field name="name">visit.location.kanban</field>
            <field name="model">visit.location</field>
            <field name="arch" type="xml">
                <kanban default_group_by="state" quick_create="false" records_draggable="0">
                    <field name="name"/>
                    <field name="color"/>
                    <field name="visit_date"/>
                    <field name="visit_types"/>
                    <field name="benefit_code"/>
                    <field name="benefit_id"/>
                    <field name="researcher_team"/>
                    <field name="state"/>
                    <field name="activity_state"/>
                    <field name="activity_ids"/>
                    <progressbar field="activity_state"
                                 colors='{"planned": "success", "overdue": "danger", "today": "warning"}'/>
                    <templates>
                        <t t-name="kanban-box">
                            <div t-attf-class="{{!selection_mode ? 'oe_kanban_color_' + kanban_getcolor(record.color.raw_value) : ''}} oe_kanban_global_click">
                                <div class="o_dropdown_kanban dropdown">

                                    <a class="dropdown-toggle o-no-caret btn" role="button" data-toggle="dropdown"
                                       data-display="static" href="#" aria-label="Dropdown menu" title="Dropdown menu">
                                        <span class="fa fa-ellipsis-v"/>
                                    </a>
                                    <div class="dropdown-menu" role="menu">
                                        <t t-if="widget.editable">
                                            <a role="menuitem" type="edit" class="dropdown-item">Edit</a>
                                        </t>
                                        <t t-if="widget.deletable">
                                            <a role="menuitem" type="delete" class="dropdown-item">Delete</a>
                                        </t>
                                        <ul class="oe_kanban_colorpicker" data-field="color"/>
                                    </div>
                                </div>
                                <div class="oe_kanban_details">
                                    <strong class="o_kanban_record_title">
                                        <strong>
                                            <field name="name"/>
                                        </strong>
                                    </strong>
                                    <div>
                                        <field name="visit_date"/>
                                    </div>
                                    <div>
                                        <field name="visit_types"/>
                                    </div>
                                    <div>
                                        <field name="benefit_code"/>
                                    </div>
                                    <div>
                                        <field name="benefit_id"/>
                                    </div>
                                    <div>
                                        <field name="researcher_team"/>
                                    </div>
                                    <div>
                                        <field name="state" widget="badge"
                                               decoration-success="state in ['done', 'close']"
                                               decoration-muted="state in ['draft']"
                                               decoration-danger="state in ['cancel']"
                                               decoration-warning="state in ['schedule_a_visit']"
                                               decoration-info="state in ['contact']"/>
                                    </div>
                                </div>
                                <div class="o_kanban_record_bottom">
                                    <div class="oe_kanban_bottom_left">
                                        <field name="evaluation" widget="priority" groups="base.group_user"/>
                                        <field name="activity_ids" widget="kanban_activity"/>
                                    </div>
                                </div>
                            </div>
                        </t>
                    </templates>
                </kanban>
            </field>
        </record>
        <record id="visits_form" model="ir.ui.view">
            <field name="name">visit.location.form</field>
            <field name="model">visit.location</field>
            <field name="arch" type="xml">
                <form string="Visits">
                    <header>
                        <button name="action_contact" string="Family Contact" type="object" class="oe_highlight"
                                states="draft"/>
                        <button name="action_schedule_a_visit" string="Schedule a visit" type="object"
                                class="oe_highlight" states="contact"/>
                        <button name="action_create_new_visit"
                               string="Create New Visit"
                               type="object"
                               states="cancel"/>
                        <button name="action_postpone"
                               string="Postponement"
                               type="object"
                               class="btn-warning"
                               states="contact,schedule_a_visit"/>
                       <button name="action_reschedule"
                               string="Reschedule"
                               type="object"
                               states="pending"/>
                        <button name="action_done" string="Done" type="object" class="oe_highlight"
                                states="schedule_a_visit"/>
                        <button name="action_skip_otp"
                                string="Skip OTP Verification" 
                                states="schedule_a_visit"
                                type="object" 
                                class="btn-danger"
                                groups="odex_benefit.group_otp_manager"/>
                        <button name="action_cancel" 
                            string="Visit Cancel" 
                            type="object" 
                            class="btn-danger"
                            states="contact,schedule_a_visit"/>
                        <!-- <button name="action_close" string="Close" type="object" states="done"/> -->
                        <button name="action_send_survey"
                                attrs="{'invisible':[('state', '!=', 'done')]}"
                                type="object" string="Resend Survey Link" class="oe_highlight"/>
                        <button name="geo_localize" 
                            string="Map" 
                            type="object" 
                            class="oe_highlight"
                            icon="fa-map"
                            attrs="{'invisible':['|',('benefit_id', '=', False),('state', 'in', ('done','close'))]}"/>
                        <field name="state" widget="statusbar"
                               statusbar_visible="draft,contact,schedule_a_visit,cancel,done,close"/>
                    </header>
                    <sheet>
                        <div class="oe_button_box" name="button_box">
                            <button type="object"
                                    class="oe_stat_button"
                                    icon="fa-pencil-square-o"
                                    name="action_view_responses"
                                    attrs="{'invisible': [('response_count', '=', 0)]}">
                                <field string="Surveys" name="response_count" widget="statinfo"/>
                            </button>
                        </div>
                        <div class="oe_title">
                            <h1>
                                <field placeholder="Name" name="name" class="oe_inline"/>
                            </h1>
                        </div>
                        <group>
                            <group>
                                <field name="visit_types_creation_method" invisible="1" />
                                <field name="visit_types" 
                                    domain="[('creation_method','=','manual')]"
                                    attrs="{'readonly':[
                                            '|', 
                                                ('state', 'in', ['close', 'cancel']),
                                                ('visit_types_creation_method', '=', 'automatic')
                                        ]
                                    }" 
                                    required="1"/>
                                <field name="benefit_id" 
                                    attrs="{'readonly':[
                                            '|', 
                                                ('state', 'in', ['close', 'cancel']),
                                                ('visit_types_creation_method', '=', 'automatic')
                                        ]
                                    }"
                                    required="1"/>
                                <field name="benefit_code"/>
                                <field name="sms_phone"/>
                                <field name="researcher_team" required="1"/>
                                <field name="researcher_ids" invisible="1" widget="many2many_tags"
                                       attrs="{'readonly':[('state', 'in', ['close','cancel'])]}" force_save="1"/>
                                <field name="message"
                                       attrs="{'readonly':[('state', 'in', ['close','cancel'])]}"/>
                                <field name="reason"
                                       attrs="{'invisible':[('state', 'not in', ['cancel'])],'readonly':[('state', 'in', ['close','cancel'])]}"/>
                            </group>
                            <group>
                                <field name="visit_date" attrs="{'readonly':[('state', 'in', ['close','cancel'])]}"
                                       required="1"/>
                                <field name="evaluation" widget="priority"/>
                                <field name="visit_objective" invisible="1"
                                       attrs="{'readonly':[('state', 'in', ['close','cancel'])]}"/>
                                <field name="otp_code" invisible="1"/>
                                <field name="otp_generated_at" invisible="1"/>
                                <field name="response_id" invisible="1"/>
                                <field name="survey_url" invisible="1"/>
                            </group>
                        </group>
                    </sheet>
                    <div class="oe_chatter">
                        <field name="message_follower_ids" widget="mail_followers" groups="base.group_user"/>
                        <field name="activity_ids"/>
                        <field name="message_ids" widget="mail_thread"/>
                    </div>
                </form>
            </field>
        </record>
        <record id="visit_tree" model="ir.ui.view">
            <field name="name">visit.location.tree</field>
            <field name="model">visit.location</field>
            <field name="arch" type="xml">
                <tree string="Visits">
                    <field name="name"/>
                    <field name="benefit_code"/>
                    <field name="benefit_id"/>
                    <field name="researcher_team"/>
                    <field name="visit_date"/>
                    <field name="evaluation" widget="priority"/>
                    <field name="visit_objective" invisible="1"/>
                    <field name="activity_ids" widget="list_activity"/>
                    <field name="visit_types"/>
                    <field name="state" widget="badge" decoration-muted="state in ['draft']"
                           decoration-info="state in ['contact']" decoration-warning="state in ['schedule_a_visit']"
                           decoration-success="state in ['done', 'close']" decoration-danger="state in ['cancel']"/>
                </tree>
            </field>
        </record>
        <record id="visit_location_activity_view" model="ir.ui.view">
            <field name="name">visit.location.activity.view</field>
            <field name="model">visit.location</field>
            <field name="arch" type="xml">
                <activity string="Visits Activity">
                    <field name="id"/>
                    <templates>
                        <div t-name="activity-box">
                            <div>
                                <field name="name" display="full"/>
                                <field name="benefit_id" muted="1" display="full"/>
                            </div>
                        </div>
                    </templates>
                </activity>
            </field>
        </record>
        <record id="visit_location_calendar_view" model="ir.ui.view">
            <field name="name">visit.location.calendar.view</field>
            <field name="model">visit.location</field>
            <field name="arch" type="xml">
                <calendar string="visits" date_start="visit_date" mode="month" quick_add="True" color="researcher_team">
                    <field name="name"/>
                    <field name="visit_date"/>
                    <field name="benefit_id"/>
                    <field name="researcher_team"/>
                </calendar>
            </field>
        </record>
        <record model="ir.ui.view" id="visit_search">
            <field name="name">visit.location.search</field>
            <field name="model">visit.location</field>
            <field name="arch" type="xml">
                <search>
                    <field name="benefit_id"/>
                    <field name="benefit_code"/>
                </search>
            </field>
        </record>
    </data>
</odoo>
