Přejít na obsah
Odoo Menu
  • Přihlásit se
  • Vyzkoušejte zdarma
  • Aplikace
    Finance
    • Účetnictví
    • Fakturace
    • Výdaje
    • Spreadsheet (BI)
    • Dokumenty
    • Podpisy
    Prodej
    • CRM
    • Prodej
    • POS Obchod
    • POS Restaurace
    • Předplatné
    • Pronájem
    Webové stránky
    • Webové stránky
    • E-shop
    • Blog
    • Fórum
    • Živý chat
    • eLearning
    Dodavatelský řetězec
    • Sklad
    • Výroba
    • PLM
    • Nákup
    • Údržba
    • Kvalita
    Lidské zdroje
    • Zaměstnanci
    • Nábor
    • Volno
    • Hodnocení zaměstnanců
    • Doporučení
    • Vozový park
    Marketing
    • Marketing sociálních sítí
    • Emailový marketing
    • SMS Marketing
    • Události
    • Marketingová automatizace
    • Dotazníky
    Služby
    • Projekt
    • Časové výkazy
    • Práce v terénu
    • Helpdesk
    • Plánování
    • Schůzky
    Produktivita
    • Diskuze
    • Schvalování
    • IoT
    • VoIP
    • Znalosti
    • WhatsApp
    Aplikace třetích stran Odoo Studio Odoo cloudová platforma
  • Branže
    Maloobchod
    • Knihkupectví
    • Obchod s oblečením
    • Obchod s nábytkem
    • Potraviny
    • Obchod s hardwarem
    • Hračkářství
    Jídlo a pohostinství
    • Bar a Pub
    • Restaurace
    • Fast Food
    • Penzion
    • Distributor nápojů
    • Hotel
    Nemovitost
    • Realitní kancelář
    • Architektonická firma
    • Stavba
    • Správa nemovitostí
    • Zahradnictví
    • Asociace vlastníků nemovitosti
    Poradenství
    • Účetní firma
    • Odoo Partner
    • Marketingová agentura
    • Právník
    • Akvizice talentů
    • Audit a certifikace
    Výroba
    • Textil
    • Kov
    • Nábytek
    • Jídlo
    • Pivovar
    • Korporátní dárky
    Zdraví a fitness
    • Sportovní klub
    • Prodejna brýli
    • Fitness Centrum
    • Wellness praktikové
    • Lékárna
    • Kadeřnictví
    Transakce
    • Údržbář
    • Podpora IT & hardware
    • Systémy solární energie
    • Výrobce obuvi
    • Úklidové služby
    • Služby HVAC
    Ostatní
    • Nezisková organizace
    • Agentura pro životní prostředí
    • Pronájem billboardů
    • Fotografování
    • Leasing jízdních kol
    • Prodejce softwaru
    Procházet všechna odvětví
  • Komunita
    Edukační program
    • Tutoriály
    • Dokumentace
    • Certifikace
    • Vzdělávání
    • Blog
    • Podcast
    Podpora vzdělávání
    • Vzdělávací program
    • Scale Up! Hra na firmu
    • Navštivte Odoo
    Získat software
    • Stáhnout
    • Porovnejte edice
    • Verze
    Spolupráce
    • Github
    • Fórum
    • Události
    • Překlady
    • Stát se partnerem
    • Služby pro partnery
    • Registrujte svou účetní firmu
    Získat služby
    • Najít partnera
    • Najít účetní
    • Setkejte se s poradcem
    • Implementační služby
    • Zákaznické reference
    • Podpora
    • Upgrady
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Dohodnout demo
  • Ceník
  • Pomoc

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

  • CRM
  • e-Commerce
  • Účetnictví
  • Sklad
  • PoS
  • Projekty
  • MRP
All apps
You need to be registered to interact with the community.
All Posts Lidé Odznaky
Štítky (View all)
odoo accounting v14 pos v15
O tomto fóru
You need to be registered to interact with the community.
All Posts Lidé Odznaky
Štítky (View all)
odoo accounting v14 pos v15
O tomto fóru
Pomoc

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

Odebírat

Get notified when there's activity on this post

This question has been flagged
viewinheritancedynamicplaceholder
2 Odpovědi
13024 Zobrazení
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
Zrušit
Avatar
Temur
Nejlepší odpověď

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
Zrušit
Anton Chepurov
Autor

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
Autor

@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
Autor

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
Autor Nejlepší odpověď

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
Zrušit
Enjoying the discussion? Don't just read, join in!

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

Přihlásit se
Related Posts Odpovědi Zobrazení Aktivita
View inheritance Vyřešeno
view inheritance
Avatar
Avatar
1
bře 20
4413
How do I remove fields from a view in a custom module? Vyřešeno
view inheritance
Avatar
Avatar
Avatar
Avatar
12
pro 18
36263
Weird error "Expression cannot be located in parent view" in view inheritance Vyřešeno
view inheritance
Avatar
Avatar
1
čvc 16
7966
Two-level view inheritance, what am I missing?
view inheritance
Avatar
Avatar
2
bře 15
6903
view inheritance in openerp
view inheritance
Avatar
Avatar
1
bře 15
4380
Komunita
  • Tutoriály
  • Dokumentace
  • Fórum
Open Source
  • Stáhnout
  • Github
  • Runbot
  • Překlady
Služby
  • Odoo.sh hostování
  • Podpora
  • Upgrade
  • Nestandardní vývoj
  • Edukační program
  • Najít účetní
  • Najít partnera
  • Stát se partnerem
O nás
  • Naše společnost
  • Podklady značky
  • Kontakujte nás
  • Práce
  • Události
  • Podcast
  • Blog
  • Zákazníci
  • Právní dokumenty • Soukromí
  • Zabezpečení
الْعَرَبيّة 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 je balíček open-source aplikací, které pokrývají všechny potřeby vaší společnosti: CRM, e-shop, účetnictví, sklady, kasy, projektové řízení a další.

Unikátní nabídka od Odoo poskytuje velmi jednoduché uživatelské rozhraní a vše je integrované na jednom místě.

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