<?xml version="1.0" encoding="utf-8" ?>
<!-- Copyright 2017 Jairo Llopis <jairo.llopis@tecnativa.com>
     Copyright 2020 Tecnativa - Pedro M. Baeza
     License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
<odoo>
    <record id="sale_order_recommendation_view_form" model="ir.ui.view">
        <field name="name">Recommended Products for this Customer</field>
        <field name="model">sale.order.recommendation</field>
        <field name="arch" type="xml">
            <form>
                <sheet>
                    <group invisible="line_ids">
                        <group>
                            <field name="order_id" invisible="1" />
                            <field name="months" widget="numeric_step" />
                            <field name="line_amount" widget="numeric_step" />
                        </group>
                        <group>
                            <field name="sale_recommendation_price_origin" />
                            <field name="use_delivery_address" />
                            <field name="recommendations_order" />
                        </group>
                    </group>
                    <group col="2">
                        <field
                            name="line_ids"
                            nolabel="1"
                            mode="list,kanban"
                            colspan="2"
                            invisible="not line_ids"
                        >
                            <list create="0" delete="0" editable="top">
                                <field
                                    name="product_is_favorite"
                                    widget="boolean_favorite"
                                    optional="show"
                                    nolabel="1"
                                />
                                <field name="currency_id" column_invisible="1" />
                                <field name="sale_line_id" column_invisible="1" />
                                <field
                                    name="product_categ_complete_name"
                                    optional="show"
                                />
                                <field
                                    name="product_id"
                                    readonly="1"
                                    force_save="1"
                                    optional="hide"
                                />
                                <field name="product_default_code" optional="show" />
                                <field name="product_name" optional="show" />
                                <field name="price_unit" optional="show" />
                                <field name="times_delivered" optional="show" />
                                <field name="units_delivered" optional="show" />
                                <field name="units_included" widget="numeric_step" />
                                <field
                                    name="product_uom_category_id"
                                    column_invisible="1"
                                />
                                <field
                                    name="product_uom_readonly"
                                    column_invisible="1"
                                />
                                <field
                                    name="sale_uom_id"
                                    optional="show"
                                    groups="uom.group_uom"
                                    readonly="product_uom_readonly"
                                />
                            </list>
                            <kanban
                                class="o_kanban_mobile"
                                quick_create="0"
                                create="0"
                                delete="0"
                            >
                                <field name="id" />
                                <field name="product_id" />
                                <field name="sale_line_id" />
                                <field name="price_unit" />
                                <field name="sale_uom_id" />
                                <field name="times_delivered" />
                                <field name="units_delivered" />
                                <field name="units_included" />
                                <field name="currency_id" />
                                <templates>
                                    <t t-name="card">
                                        <div class="oe_kanban_global_click">
                                            <div class="o_kanban_image me-1">
                                                <img
                                                    t-att-src="kanban_image('product.product', 'image_128', record.product_id.raw_value)"
                                                    alt="Product"
                                                    class="o_image_64_contain"
                                                />
                                            </div>
                                            <div class="oe_kanban_details">
                                                <div class="o_kanban_record_top mb-0">
                                                    <div
                                                        class="o_kanban_record_headings"
                                                    >
                                                        <field
                                                            name="product_id"
                                                            class="o_kanban_record_title"
                                                        />
                                                    </div>
                                                    <field
                                                        class="w-auto mb-0"
                                                        name="product_is_favorite"
                                                        widget="priority"
                                                    />
                                                </div>
                                                <div>Price: <field
                                                    name="price_unit"
                                                    widget="monetary"
                                                    options="{'currency_field': 'currency_id', 'field_digits': True}"
                                                    class="oe_inline mt-0 mb-0"
                                                /></div>
                                                <div>Delivered: <field
                                                    name="times_delivered"
                                                /> times - <field
                                                    name="units_delivered"
                                                /> <field name="sale_uom_id" /></div>
                                                <div>
                                                    <strong>
                                                        <span>To be included: </span>
                                                        <field name="units_included" />
                                                        <span />
                                                        <field
                                                            name="sale_uom_id"
                                                            groups="uom.group_uom"
                                                        />
                                                    </strong>
                                                </div>
                                            </div>
                                        </div>
                                    </t>
                                </templates>
                            </kanban>
                            <form>
                                <group>
                                    <field name="wizard_id" invisible="1" />
                                    <field
                                        name="product_id"
                                        readonly="1"
                                        force_save="1"
                                    />
                                    <field name="price_unit" />
                                    <field
                                        name="units_included"
                                        widget="numeric_step"
                                    />
                                </group>
                            </form>
                        </field>
                    </group>
                </sheet>
                <footer>
                    <button
                        invisible="line_ids"
                        class="btn-primary"
                        icon="fa-refresh"
                        name="generate_recommendations"
                        string="Get recommendations"
                        type="object"
                    />
                    <button
                        invisible="not line_ids"
                        name="action_accept"
                        type="object"
                        string="Accept"
                        class="oe_highlight"
                    />
                    <button
                        invisible="not line_ids"
                        confirm="You will lose any changes you have made. Are you sure?"
                        name="action_reset"
                        string="Change criteria"
                        type="object"
                    />
                    <button special="cancel" string="Cancel" />
                </footer>
            </form>
        </field>
    </record>

    <record id="sale_order_recommendation_action" model="ir.actions.act_window">
        <field name="name">Recommended Products for this Customer</field>
        <field name="res_model">sale.order.recommendation</field>
        <field name="view_mode">form</field>
        <field name="target">new</field>
    </record>
</odoo>
