Skip to Content
Odoo Menu
  • Log ind
  • Prøv gratis
  • Apps
    Økonomi
    • Bogføring
    • Fakturering
    • Udgifter
    • Regneark (BI)
    • Dokumenter
    • e-Signatur
    Salg
    • CRM
    • Salg
    • POS Butik
    • POS Restaurant
    • Abonnementer
    • Udlejning
    Hjemmeside
    • Hjemmesidebygger
    • e-Handel
    • Blog
    • Forum
    • LiveChat
    • e-Læring
    Forsyningskæde
    • Lagerbeholdning
    • Produktion
    • PLM
    • Indkøb
    • Vedligeholdelse
    • Kvalitet
    HR
    • Medarbejdere
    • Rekruttering
    • Fravær
    • Medarbejdersamtaler
    • Anbefalinger
    • Flåde
    Marketing
    • Markedsføring på sociale medier
    • E-mailmarketing
    • SMS-marketing
    • Arrangementer
    • Automatiseret marketing
    • Spørgeundersøgelser
    Tjenester
    • Projekt
    • Timesedler
    • Udkørende Service
    • Kundeservice
    • Planlægning
    • Aftaler
    Produktivitet
    • Dialog
    • Godkendelser
    • IoT
    • VoIP
    • Vidensdeling
    • WhatsApp
    Tredjepartsapps Odoo Studio Odoo Cloud-platform
  • Brancher
    Detailhandel
    • Boghandel
    • Tøjforretning
    • Møbelforretning
    • Dagligvarebutik
    • Byggemarked
    • Legetøjsforretning
    Mad og værtsskab
    • Bar og pub
    • Restaurant
    • Fastfood
    • Gæstehus
    • Drikkevareforhandler
    • Hotel
    Ejendom
    • Ejendomsmægler
    • Arkitektfirma
    • Byggeri
    • Ejendomsadministration
    • Havearbejde
    • Boligejerforening
    Rådgivning
    • Regnskabsfirma
    • Odoo-partner
    • Marketingbureau
    • Advokatfirma
    • Rekruttering
    • Audit & certificering
    Produktion
    • Tekstil
    • Metal
    • Møbler
    • Fødevareproduktion
    • Bryggeri
    • Firmagave
    Heldbred & Fitness
    • Sportsklub
    • Optiker
    • Fitnesscenter
    • Kosmetolog
    • Apotek
    • Frisør
    Håndværk
    • Handyman
    • IT-hardware og support
    • Solenergisystemer
    • Skomager
    • Rengøringsservicer
    • VVS- og ventilationsservice
    Andet
    • Nonprofitorganisation
    • Miljøagentur
    • Udlejning af billboards
    • Fotografi
    • Cykeludlejning
    • Softwareforhandler
    Gennemse alle brancher
  • Community
    Få mere at vide
    • Tutorials
    • Dokumentation
    • Certificeringer
    • Oplæring
    • Blog
    • Podcast
    Bliv klogere
    • Udannelselsesprogram
    • Scale Up!-virksomhedsspillet
    • Besøg Odoo
    Få softwaren
    • Download
    • Sammenlign versioner
    • Udgaver
    Samarbejde
    • Github
    • Forum
    • Arrangementer
    • Oversættelser
    • Bliv partner
    • Tjenester til partnere
    • Registrér dit regnskabsfirma
    Modtag tjenester
    • Find en partner
    • Find en bogholder
    • Kontakt en rådgiver
    • Implementeringstjenester
    • Kundereferencer
    • Support
    • Opgraderinger
    Github Youtube Twitter LinkedIn Instagram Facebook Spotify
    +1 (650) 691-3277
    Få en demo
  • Prissætning
  • Hjælp

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

  • CRM
  • e-Commerce
  • Bogføring
  • Lager
  • PoS
  • Projekt
  • MRP
All apps
Du skal være registreret for at interagere med fællesskabet.
All Posts People Emblemer
Tags (View all)
odoo accounting v14 pos v15
Om dette forum
Du skal være registreret for at interagere med fællesskabet.
All Posts People Emblemer
Tags (View all)
odoo accounting v14 pos v15
Om dette forum
Hjælp

Dynamic placeholder: different placeholders for same view shown in different menus

Tilmeld

Få besked, når der er aktivitet på dette indlæg

Dette spørgsmål er blevet anmeldt
viewinheritancedynamicplaceholder
2 Besvarelser
13016 Visninger
Avatar
Anton Chepurov

How can I inherit a view such that it shows different placeholders when shown from different menus?

It seems that inheritance is not a mechanism that would allow this, am I right?

If so, are there any other ways of achieving the same view but with different placeholders?

Copy-pasting the view wouldn't work as the inherited views won't be considered/pulled in.


A widget, probably?

Ah, I think fields_view_get() should fix the issue :) Will try it out.


0
Avatar
Kassér
Avatar
Temur
Bedste svar

You can have different views per menu (you can define explicitly which view should be used on which menu using xml id). Say, for two menu, try to create two views, with different name and xml id,  adapt placehoders in both views, then bind the two views to the corresponding menus. You can also leverage "sequence" field of view in some way.


UPDATE:

(example code is for Odoo 8.0, requires Sales module to be installed )

the following example adds two pages, using different inherited views per menu, as suggested above.

first page: "/Sales/Products/Products AAA"

        <record model="ir.ui.view" id="product_product_aaa_page_view">
<field name="name">aaa.text.product.form.view</field>
<field name="model">product.template</field>
<field name="inherit_id" ref="product.product_template_only_form_view" />
<field name="mode">primary</field>
<field name="arch" type="xml">
<field name="description" position="attributes">
<attribute name="placeholder">You are on "/Sales/Products/Products AAA" page!</attribute>
</field>
</field>
</record>


<record id="product_action_aaa" model="ir.actions.act_window">
<field name="name">Product AAA</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">product.template</field>
<field name="view_mode">kanban,tree,form</field>
<field name="view_type">form</field>
<field name="view_id" ref="product_product_aaa_page_view"/>
</record>

<menuitem action="product_action_aaa"
id="menu_product_template_aaaa"
parent="base.menu_product" sequence="2" />

and here is second page: "/Sales/Products/Products BBB"

        <record model="ir.ui.view" id="product_product_bbb_page_view">
<field name="name">bbb.text.product.form.view</field>
<field name="model">product.template</field>
<field name="inherit_id" ref="product.product_template_only_form_view" />
<field name="mode">primary</field>
<field name="arch" type="xml">
<field name="description" position="attributes">
<attribute name="placeholder">You are on "/Sales/Products/Products BBB" page!</attribute>
</field>
</field>
</record>

<record id="product_action_bbb" model="ir.actions.act_window">
<field name="name">Product BBB</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">product.template</field>
<field name="view_mode">kanban,tree,form</field>
<field name="view_type">form</field>
<field name="view_id" ref="product_product_bbb_page_view"/>
</record>

<menuitem action="product_action_bbb"
id="menu_product_template_bbbb"
parent="base.menu_product" sequence="3" />

1
Avatar
Kassér
Anton Chepurov
Forfatter

I'm sorry, but you didn't bother reading the question, did you? Nah, this happens more often than not on this forum... :/

Temur

You're welcome. There is always several ways to achieve the same thing, so it's normal to get alternatives either on this forum or elsewhere...

Anton Chepurov
Forfatter

@Temur, it was too rude of me, I'm sorry. I didn't mean that. I'm really sorry. What I meant was that your answer doesn't solve the described problem - and I've explained why in the question itself: > Copy-pasting the view wouldn't work as the inherited views won't be considered/pulled in. I lost my cool because for almost every question I post here I get an answer which I have beforehand deliberately explained in the question that it doesn't work for the given problem. So was yours, too. So that's not an alternative, as you say. It doesn't achieve what the problem formulates. I'm sorry once again.

Temur

Apology accepted. BUT, [1] you have combined multiple (4 or 5) questions in the one, probably my answer is not covers all of them, but I think it answers some of them. [2] I have not to be agree whatever you're explaining in your question, but it does not mean I have not read it! Yes, I read that you explained as if "inherited views won't be considered/pulled in", but I disagree with this assumption and I stated clearly in my answer that you CAN have different views per menu, if you use xml id to bind views to menus. I mentioned also sequence (i.e. priority of view). if you bind view to menu with it's xml id as I suggested, then this view is used, regardless of sequence, otherwise (as in most cases) as we do not bind view to menu, then view is chosen according it's sequence(priority). I do not argue about how good the alternative is, and is it best fit for your case or not. but you can gather some knowledge from it and maybe it'll be best fit in other cases. So, what my message was all about is that answer to your question #2 in the post is NO, and further explanation about how to do #1. and it's clearly an alternative and I thought it should be interesting for you, as YOU ASKED ABOUT IT. I'll add an example code to my answer, you can check it and see yourself answer to your #1 question. BUT, my answer was explaining in words the case, that you can see in the example code, you should not require the example for understanding that.

Temur

Example is added. Now you can try it, and see with your eyes different placeholder shown from different menus, using inherited view. BTW, congrats with your own solution and +1. As your problem is solved, it's not necessary to continue further discussion on this thread I think. But you have not to be agree with me, as you like..

Anton Chepurov
Forfatter

Temur, thank you for your time providing me with an example! It is absolutely identical to the first idea that came to my mind -- and I tried it -- and it doesn't work. To be absolutely sure, I've looked up the history of the file in the Local History of IntelliJ, and yes, it's absolutely identical. I've copy-pasted it to my answer (see above). Could you explain where is the difference between your solution and mine and why it doesn't work in my particular case? (always the last overridden view is chosen and shown in both menus regardless of the different view_id-s specified).

Temur

<field name="mode">primary</field>
'primary' mode - means more independent view, then default 'extension' mode. Quote from help msg:
* if extension (default), if this view is requested the closest primary view is looked up (via inherit_id), then all views inheriting from it with this view's model are applied
* if primary, the closest primary view is fully resolved (even if it uses a different model than this one), then this view's inheritance specs () are applied, and the result is used as if it were this view's actual arch.

Avatar
Anton Chepurov
Forfatter Bedste svar

Yep, fields_view_get() + context key set in the menu solved that.

Here's the solution.

Context:                        (note the bold part)

        <record id="action_picking_int_form" model="ir.actions.act_window">
<field name="name">Move Items</field>
<field name="res_model">stock.picking</field>
<field name="type">ir.actions.act_window</field>
<field name="view_type">form</field>
<field name="view_mode">form</field>
<field name="view_id" ref="view_picking_form"/>
<field name="target">current</field>
<field name="context">{'picking_type': 'int'}</field>
</record>

And view_get():

    def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False):
res = super(stock_picking, self).fields_view_get(cr, uid, view_id=view_id, view_type=view_type, context=context, toolbar=toolbar, submenu=submenu)
if view_type == 'form':
doc = etree.XML(res['arch'])
note = doc.xpath("//field[@name='note']")

picking_type = context.get('picking_type')
if picking_type == 'in':
note[0].attrib['placeholder'] = 'Model | Serial Number | Model | Serial Number | ...'
elif picking_type == 'int':
note[0].attrib['placeholder'] = 'Location Barcode | Quant ID | Quant ID | Quant ID | ...'

res['arch'] = etree.tostring(doc)
return res


UPDATE:

Why does this solution show the same placeholder for both menus - for Receive New Products and for Move Products?

Both menus show Location | Barcode as a placeholder (taken from the last view definition). If smb asks, <data> tag doesn't have a noupdate flag.

<record id="view_picking_form" model="ir.ui.view">
<field name="name">stock.picking.form</field>
<field name="model">stock.picking</field>
<field name="inherit_id" ref="stock.view_picking_form"/>
<field name="arch" type="xml">
<field name="note" position="replace">
<group col="4">
<field name="note" class="oe_inline" colspan="2" nolabel="1" placeholder="Add an internal note..."/>
<field name="info" style="color: blue;" colspan="2" nolabel="1"/>
</group>
</field>
</field>
</record>
<record id="view_picking_in_form" model="ir.ui.view">
<field name="name">stock.picking.in.form</field>
<field name="model">stock.picking</field>
<field name="inherit_id" ref="view_picking_form"/>
<field name="arch" type="xml">
<field name="note" position="attributes">
<attribute name="placeholder">Model | Serial_Number</attribute>
</field>
</field>
</record>
<record id="view_picking_int_form" model="ir.ui.view">
<field name="name">stock.picking.int.form</field>
<field name="model">stock.picking</field>
<field name="inherit_id" ref="view_picking_form"/>
<field name="arch" type="xml">
<field name="note" position="attributes">
<attribute name="placeholder">Location | Barcode</attribute>
</field>
</field>
</record>

<record id="action_picking_form" model="ir.actions.act_window">
<field name="name">Receive New Products</field>
<field name="res_model">stock.picking</field>
<field name="type">ir.actions.act_window</field>
<field name="view_type">form</field>
<field name="view_mode">form</field>
<field name="view_id" ref="view_picking_in_form"/>
<field name="target">current</field>
<field name="context">{'picking_type': 'in'}</field>
</record>
<menuitem action="action_picking_form" id="menu_action_picking_form" parent="stock.menu_stock_warehouse_mgmt" sequence="3"/>
<record id="action_picking_int_form" model="ir.actions.act_window">
<field name="name">Move Products</field>
<field name="res_model">stock.picking</field>
<field name="type">ir.actions.act_window</field>
<field name="view_type">form</field>
<field name="view_mode">form</field>
<field name="view_id" ref="view_picking_int_form"/>
<field name="target">current</field>
<field name="context">{'picking_type': 'int'}</field>
</record>
<menuitem action="action_picking_int_form" id="menu_action_picking_int_form" parent="stock.menu_stock_warehouse_mgmt" sequence="10"/>

Receive New Items: https://www.dropbox.com/s/uco8b99arlz2qf8/Receive_New_Items.png?dl=0

Move Items: https://www.dropbox.com/s/x706dftvmfieh0n/Move_Items.png?dl=0


If I set priorities for both views (and strictly for both views, just for one is not enough!) like this:

        <record id="view_picking_in_form" model="ir.ui.view">
<field name="name">stock.picking.in.form</field>
<field name="model">stock.picking</field>
<field name="inherit_id" ref="view_picking_form"/>
<field name="priority" eval="21"/>
<field name="arch" type="xml">
<field name="note" position="attributes">
<attribute name="placeholder">Model | Serial_Number</attribute>
</field>
</field>
</record>
<record id="view_picking_int_form" model="ir.ui.view">
<field name="name">stock.picking.int.form</field>
<field name="model">stock.picking</field>
<field name="inherit_id" ref="view_picking_form"/>
<field name="priority" eval="20"/>
<field name="arch" type="xml">
<field name="note" position="attributes">
<attribute name="placeholder">Location | Barcode</attribute>
</field>
</field>
</record>

... then Model | Serial_Number placeholder is shown in both menus.

Hence, it is either a bug in Odoo's view inheritance mechanism, or inheritance simply doesn't allow such tuning of placeholders and hence the only solution known to me so far is overriding the fields_view_get().

1
Avatar
Kassér
Enjoying the discussion? Don't just read, join in!

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

Tilmeld dig
Related Posts Besvarelser Visninger Aktivitet
View inheritance Løst
view inheritance
Avatar
Avatar
1
mar. 20
4412
How do I remove fields from a view in a custom module? Løst
view inheritance
Avatar
Avatar
Avatar
Avatar
12
dec. 18
36261
Weird error "Expression cannot be located in parent view" in view inheritance Løst
view inheritance
Avatar
Avatar
1
jul. 16
7962
Two-level view inheritance, what am I missing?
view inheritance
Avatar
Avatar
2
mar. 15
6903
view inheritance in openerp
view inheritance
Avatar
Avatar
1
mar. 15
4380
Community
  • Tutorials
  • Dokumentation
  • Forum
Open Source
  • Download
  • Github
  • Runbot
  • Oversættelser
Tjenester
  • Odoo.sh-hosting
  • Support
  • Opgradere
  • Individuelt tilpasset udvikling
  • Uddannelse
  • Find en bogholder
  • Find en partner
  • Bliv partner
Om os
  • Vores virksomhed
  • Brandaktiver
  • Kontakt os
  • Stillinger
  • Arrangementer
  • Podcast
  • Blog
  • Kunder
  • Juridiske dokumenter • Privatlivspolitik
  • Sikkerhedspolitik
الْعَرَبيّة 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 er en samling open source-forretningsapps, der dækker alle dine virksomhedsbehov – lige fra CRM, e-handel og bogføring til lagerstyring, POS, projektledelse og meget mere.

Det unikke ved Odoo er, at systemet både er brugervenligt og fuldt integreret.

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