Skip to Content
Odoo Menú
  • Registra entrada
  • Prova-ho gratis
  • Aplicacions
    Finances
    • Comptabilitat
    • Facturació
    • Despeses
    • Full de càlcul (IA)
    • Documents
    • Signatura
    Vendes
    • CRM
    • Vendes
    • Punt de venda per a botigues
    • Punt de venda per a restaurants
    • Subscripcions
    • Lloguer
    Imatges de llocs web
    • Creació de llocs web
    • Comerç electrònic
    • Blog
    • Fòrum
    • Xat en directe
    • Aprenentatge en línia
    Cadena de subministrament
    • Inventari
    • Fabricació
    • PLM
    • Compres
    • Manteniment
    • Qualitat
    Recursos humans
    • Empleats
    • Reclutament
    • Absències
    • Avaluacions
    • Recomanacions
    • Flota
    Màrqueting
    • Màrqueting Social
    • Màrqueting per correu electrònic
    • Màrqueting per SMS
    • Esdeveniments
    • Automatització del màrqueting
    • Enquestes
    Serveis
    • Projectes
    • Fulls d'hores
    • Servei de camp
    • Suport
    • Planificació
    • Cites
    Productivitat
    • Converses
    • Validacions
    • IoT
    • VoIP
    • Coneixements
    • WhatsApp
    Aplicacions de tercers Odoo Studio Plataforma d'Odoo al núvol
  • Sectors
    Comerç al detall
    • Llibreria
    • Botiga de roba
    • Botiga de mobles
    • Botiga d'ultramarins
    • Ferreteria
    • Botiga de joguines
    Food & Hospitality
    • Bar i pub
    • Restaurant
    • Menjar ràpid
    • Guest House
    • Distribuïdor de begudes
    • Hotel
    Real Estate
    • Real Estate Agency
    • Estudi d'arquitectura
    • Construcció
    • Gestió immobiliària
    • Jardineria
    • Associació de propietaris de béns immobles
    Consulting
    • Accounting Firm
    • Partner d'Odoo
    • Agència de màrqueting
    • Bufet d'advocats
    • Captació de talent
    • Auditoria i certificació
    Fabricació
    • Textile
    • Metal
    • Furnitures
    • Food
    • Brewery
    • Regals corporatius
    Salut i fitness
    • Club d'esport
    • Òptica
    • Centre de fitness
    • Especialistes en benestar
    • Farmàcia
    • Perruqueria
    Trades
    • Servei de manteniment
    • Hardware i suport informàtic
    • Solar Energy Systems
    • Shoe Maker
    • Serveis de neteja
    • HVAC Services
    Others
    • Nonprofit Organization
    • Agència del medi ambient
    • Lloguer de panells publicitaris
    • Fotografia
    • Lloguer de bicicletes
    • Distribuïdors de programari
    Browse all Industries
  • Comunitat
    Aprèn
    • Tutorials
    • Documentació
    • Certificacions
    • Formació
    • Blog
    • Pòdcast
    Potenciar l'educació
    • Programa educatiu
    • Scale-Up! El joc empresarial
    • Visita Odoo
    Obtindre el programari
    • Descarregar
    • Comparar edicions
    • Novetats de les versions
    Col·laborar
    • GitHub
    • Fòrum
    • Esdeveniments
    • Traduccions
    • Converteix-te en partner
    • Services for Partners
    • Registra la teva empresa comptable
    Obtindre els serveis
    • Troba un partner
    • Troba un comptable
    • Contacta amb un expert
    • Serveis d'implementació
    • Referències del client
    • Suport
    • Actualitzacions
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Programar una demo
  • Preus
  • Ajuda

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • CRM
  • e-Commerce
  • Comptabilitat
  • Inventari
  • PoS
  • Projectes
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Etiquetes (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Etiquetes (View all)
odoo accounting v14 pos v15
About this forum
Ajuda

[V11]Override everything in existing views

Subscriure's

Get notified when there's activity on this post

This question has been flagged
xmlviewbuttonoverride
3 Respostes
8959 Vistes
Avatar
Cayprol

Hi all,

I am trying to replace the position of smart button "Purchase" when viewing a product.

This smart button is injected by app "purchase" in the form view named "product.template.purchase.button.inherit"

Code is located in "purchase_views.xml" as below

<record id="view_product_template_purchase_buttons_from" model="ir.ui.view">

            <field name="name">product.template.purchase.button.inherit</field>
            <field name="model">product.template</field>
            <field name="inherit_id" ref="product.product_template_only_form_view"/>
            <field name="groups_id" eval="[(4, ref('purchase.group_purchase_user'))]"/>
            <field name="arch" type="xml">
                <button name="toggle_active" position="before">
                   <button class="oe_stat_button" name="%(purchase.action_purchase_line_product_tree)d"
                       type="action" icon="fa-shopping-cart">
                       <field string="Purchases" name="purchase_count" widget="statinfo"/>
                   </button>
                </button>
            </field>
</record>

Most smart buttons are placed by view inheritance with """ <button name="toggle_active" position="before"> """ in another module/app

I'd like to override everything in this view record by creating and loading a new xml file in my custom module. My understanding is that I need to refer to the right record id to override it.

My xml code:

 <?xml version="1.0" encoding="utf-8" ?>

<odoo>
 <data>
      <record id="purchase.view_product_template_purchase_buttons_from" model="ir.ui.view">
         <field name="name">product.template.purchase.button.inherit</field>
         <field name="model">product.template</field>
         <field name="inherit_id" ref="product.product_template_only_form_view"/>
         <field name="groups_id" eval="[(4, ref('purchase.group_purchase_user'))]"/>
         <field name="arch" type="xml">
            <button name="action_view_sales" position="after">
             <button class="oe_stat_button" name="%(purchase.action_purchase_line_product_tree)d" type="action" icon="fa-shopping-cart">
               <field string="Purchases" name="purchase_count" widget="statinfo"/>
             </button>
            </button>
         </field>
      </record>
 </data>
</odoo>

With my code, the error shows "purchase_count" is not found in model.

What is the correct way of replacing everything in existing view?

0
Avatar
Descartar
Pujara Geet

Did You Taken Field "purchase_count" on .py File?.

Avatar
Zbik
Best Answer


 

In __manifest__.py (in your module), try this

'depends': ['purchase'],

0
Avatar
Descartar
Avatar
Cayprol
Autor Best Answer

Hey guys, thank you for your help.

I did some testing today, though I am able to solve the problem by using Zbik's answer by including purchase module as dependency.
However, not every field needed to be addressed or CAN be addressed by adding module to dependencies.

I also tried to override record id "product_template_form_view_procurement_button" in the stock module(product.views.xml).
The button name to "Update Qty on Hand" cannot be found due to error shown as "Not being able to locate action_view_change_product_quantity", the original code:

<header position="inside">
    <button string="Update Qty On Hand"
            type="action" name="%(action_view_change_product_quantity)d"
            attrs="{'invisible': [('type', '!=', 'product')]}"/>
</header> 

In my override xml file, I solved the problem by changing this sector of code to:

<header position="inside">
    <button string="Update Qty On Hand"
            name="%(stock.action_view_change_product_quantity)d"             type="action"             attrs="{'invisible': [('type', '!=', 'product')]}"/>
</header>

With this, I don't need to include stock in 'depends' = ['stock'] in __manifest__.py

I am very curious why, but I suppose it has to do with the sequence of Odoo loading each module?


Here's all the override xml code

<?xml version="1.0" encoding="utf-8" ?>


<odoo>
 <data>

  <!-- Override view_product_template_purchase_buttons_from in purchase -->
        <record id="purchase.view_product_template_purchase_buttons_from" model="ir.ui.view">
         <field name="name">product.template.purchase.button.inherit</field>
         <field name="model">product.template</field>
         <field name="inherit_id" ref="product.product_template_only_form_view"/>
         <field name="groups_id" eval="[(4, ref('purchase.group_purchase_user'))]"/>
         <field name="arch" type="xml">
    <button name="action_view_sales" position="after">
     <button class="oe_stat_button" name="%(purchase.action_purchase_line_product_tree)d" type="action" icon="fa-shopping-cart">
      <field string="Purchases" name="purchase_count" widget="statinfo"/>
     </button>
    </button>
   </field>
  </record>

  <!-- Override product_template_form_view_procurement_button in stock -->
  <record id="stock.product_template_form_view_procurement_button" model="ir.ui.view">
   <field name="name">product.template_procurement</field>
   <field name="model">product.template</field>
   <field name="inherit_id" ref="product.product_template_only_form_view"/>
   <field name="arch" type="xml">
    <data>

     <header position="inside">
      <button name="%(stock.action_view_change_product_quantity)d" string="Update Qty On Hand" type="action" attrs="{'invisible': [('type', '!=', 'product')]}"/>
     </header>

     <button name="toggle_active" position="before">

      <button type="object" name="action_open_quants" attrs="{'invisible':[('type', '!=', 'product')]}" class="oe_stat_button" icon="fa-building-o">
       <field name="qty_available" widget="statinfo" string="On Hand"/>
      </button>

      <button string="Product Moves" type="object" name= "action_view_stock_move_lines" attrs="{'invisible':[('type', 'not in', ['product', 'consu'])]}" class="oe_stat_button" icon="fa-arrows-v" groups="stock.group_stock_user"/>
      <button type="object"
                      name="action_view_orderpoints"
                      attrs="{'invisible':['|',('type', '!=', 'product'),('nbr_reordering_rules', '==', 1)]}"
                      class="oe_stat_button"
                      icon="fa-refresh">
       <field name="nbr_reordering_rules" widget="statinfo"/>
      </button>

      <button type="object" name="action_view_orderpoints" attrs="{'invisible':['|',('type', '!=', 'product'),('nbr_reordering_rules', '!=', 1)]}" class="oe_stat_button" icon="fa-refresh">
       <div class="o_field_widget o_stat_info mr4">
        <span class="o_stat_text">Min:</span>
        <span class="o_stat_text">Max:</span>
       </div>
       <div class="o_field_widget o_stat_info">
        <span class="o_stat_value"><field name="reordering_min_qty"/></span>
        <span class="o_stat_value"><field name="reordering_max_qty"/></span>
       </div>
      </button>

      <button string="Routes" type="object" name="action_view_routes" attrs="{'invisible':[('type', '!=', 'product')]}" class="oe_stat_button" icon="fa-cogs" groups="base.group_no_one"/>

      <button string="Lot/Serial Number" type="object" name="action_open_product_lot" attrs="{'invisible': [('tracking', '=', 'none')]}" class="oe_stat_button" icon="fa-bars" groups="stock.group_production_lot"/>

     </button>

     <button name="toggle_active" position="after">
      <button type="action" name="%(stock.action_stock_level_forecast_report_template)d" attrs="{'invisible':[('type', '!=', 'product')]}" class="oe_stat_button" icon="fa-building-o">
       <div class="o_field_widget o_stat_info">
        <span class="o_stat_value"><field name="virtual_available" widget="statinfo" nolabel="1"/>
         <span attrs="{'invisible':[('outgoing_qty', '=', 0),('incoming_qty','=',0)]}" groups="base.group_no_one">
                                  (-<field name="outgoing_qty" widget="statinfo" nolabel="1"/>+<field name="incoming_qty" widget="statinfo" nolabel="1"/>)
         </span>
        </span>
        <span class="o_stat_text">Forecasted</span>
       </div>
      </button>
     </button>


     <xpath expr="//group[@name='group_lots_and_weight']" position="attributes">
      <attribute name="attrs">{'invisible':['|', ('type', 'not in', ['product', 'consu']), ('product_variant_count', '&gt;', 1)]}</attribute>
     </xpath>

     <xpath expr="//group[@name='group_lots_and_weight']" position="inside">
      <field name="responsible_id"/>
     </xpath>

          </data>
      </field>
  </record>

 </data>
</odoo>
Link to final result screenshot: https://imgur.com/h19PeLI

0
Avatar
Descartar
Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Registrar-se
Related Posts Respostes Vistes Activitat
[8.0] How to put a button at the label position? Solved
xml view button
Avatar
Avatar
1
d’abr. 17
4598
Dear Odoo, Can You Please Add "disabled" Attribute? Solved
attrs xml view button attributes
Avatar
Avatar
Avatar
2
de set. 24
5314
how shall I put a button in the center of its line? Solved
xml button
Avatar
Avatar
Avatar
2
de jul. 19
9804
How do I remove a button from the sale.order.form? Solved
xml view
Avatar
Avatar
Avatar
Avatar
Avatar
6
de set. 17
9300
display view if user is anonymous
xml view
Avatar
Avatar
1
de març 15
5090
Community
  • Tutorials
  • Documentació
  • Fòrum
Codi obert
  • Descarregar
  • GitHub
  • Runbot
  • Traduccions
Serveis
  • Allotjament a Odoo.sh
  • Suport
  • Actualització
  • Desenvolupaments personalitzats
  • Educació
  • Troba un comptable
  • Troba un partner
  • Converteix-te en partner
Sobre nosaltres
  • La nostra empresa
  • Actius de marca
  • Contacta amb nosaltres
  • Llocs de treball
  • Esdeveniments
  • Pòdcast
  • Blog
  • Clients
  • Informació legal • Privacitat
  • Seguretat
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo és un conjunt d'aplicacions empresarials de codi obert que cobreix totes les necessitats de la teva empresa: CRM, comerç electrònic, comptabilitat, inventari, punt de venda, gestió de projectes, etc.

La proposta única de valor d'Odoo és ser molt fàcil d'utilitzar i estar totalment integrat, ambdues alhora.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now