<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
  <data>

    <!-- list automatic price tick in product sheet -->
    <record model="ir.ui.view" id="product_view_inherit_list_price_auto">
      <field name="name">product.list.price.automatic.form</field>
      <field name="model">product.template</field>
      <field name="inherit_id" ref="product.product_template_form_view" />
      <field name="arch" type="xml">
        <field name="standard_price" position="attributes">
            <attribute name="readonly">
                last_purchase_price_compute_type != 'manual_update'
            </attribute>
        </field>
        <xpath expr="//group[@name='group_standard_price']" position="after">
            <group string="Automatic Price Update">
                <field name="last_purchase_price_compute_type" />
                <button
              name="action_update_list_price"
              type="object"
              string="Update Price"
              class="oe_highlight"
              icon="fa-refresh"
              invisible="last_purchase_price_compute_type == 'manual_update'"
            />
                <field
              name="last_purchase_price_received"
              widget="monetary"
              options="{'currency_field': 'currency_id', 'field_digits': True}"
              readonly="1"
            />
                <field
              name="list_price_theoritical"
              widget="monetary"
              options="{'currency_field': 'currency_id', 'field_digits': True}"
              readonly="1"
            />
                <field name="last_purchase_price_updated" readonly="1" />
            </group>
        </xpath>
      </field>
    </record>

    <record id="product_view_inherit_tree_price_auto" model="ir.ui.view">
      <field name="name">product.template.tree.price.automatic</field>
      <field name="model">product.template</field>
      <field name="inherit_id" ref="product.product_template_tree_view" />
      <field name="arch" type="xml">
        <xpath expr="//field[@name='list_price']" position="after">
          <field name="list_price_theoritical" optional="hide" />
          <field name="last_purchase_price_received" optional="hide" />
          <field name="last_purchase_price_compute_type" column_invisible="1" />
          <button
            name="action_update_list_price"
            type="object"
            string="Update Price"
            icon="fa-refresh"
            invisible="last_purchase_price_compute_type == 'manual_update'"
          />
        </xpath>
      </field>
    </record>

    <record id="res_config_settings_view_form_pricelists" model="ir.ui.view">
        <field
        name="name"
      >product.sale.price.pricelist.res.config.settings.form</field>
        <field name="model">res.config.settings</field>
        <field name="inherit_id" ref="sale.res_config_settings_view_form" />
        <field name="arch" type="xml">
            <setting id="pricelist_configuration" position="after">
                <setting
            id="automatic_price_calculation"
            string="Automatic Price from Purchase"
            help="Automatically calculate product sale prices from purchase prices using a pricelist"
          >
                    <field
              name="product_pricelist_automatic"
              invisible="not group_product_pricelist"
              domain="[('active', '=', True)]"
            />
                    <div class="text-muted">
                        Select the pricelist used to calculate sale prices from last purchase prices
                    </div>
                </setting>
            </setting>
        </field>
    </record>

    <!--Filter
    for products that should update its sales price -->
    <record id="view_product_search_form_inherit_updated" model="ir.ui.view">
      <field name="name">view.product.search.form.inherit.updated</field>
      <field name="model">product.template</field>
      <field name="inherit_id" ref="product.product_template_search_view" />
      <field name="arch" type="xml">
        <xpath expr="//filter[@name='services']" position="before">
          <separator />
          <filter
            string="To update sales price"
            name="products_updated_filter"
            domain="[('last_purchase_price_updated', '=', True), ('last_purchase_price_compute_type', '!=', 'manual_update')]"
          />
        </xpath>
      </field>
    </record>

  </data>
</odoo>
