Skip to Content
Odoo Menu
  • Prihlásiť sa
  • Vyskúšajte zadarmo
  • Aplikácie
    Financie
    • Účtovníctvo
    • Fakturácia
    • Výdavky
    • Tabuľka (BI)
    • Dokumenty
    • Podpis
    Predaj
    • CRM
    • Predaj
    • POS Shop
    • POS Restaurant
    • Manažment odberu
    • Požičovňa
    Webstránky
    • Tvorca webstránok
    • eShop
    • Blog
    • Fórum
    • Živý chat
    • eLearning
    Supply Chain
    • Sklad
    • Výroba
    • Správa životného cyklu produktu
    • Nákup
    • Údržba
    • Manažment kvality
    Ľudské zdroje
    • Zamestnanci
    • Nábor zamestnancov
    • Voľné dni
    • Hodnotenia
    • Odporúčania
    • Vozový park
    Marketing
    • Marketing sociálnych sietí
    • Email marketing
    • SMS marketing
    • Eventy
    • Marketingová automatizácia
    • Prieskumy
    Služby
    • Projektové riadenie
    • Pracovné výkazy
    • Práca v teréne
    • Helpdesk
    • Plánovanie
    • Schôdzky
    Produktivita
    • Tímová komunikácia
    • Schvalovania
    • IoT
    • VoIP
    • Znalosti
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Priemyselné odvetvia
    Retail
    • Book Store
    • Clothing Store
    • Furniture Store
    • Grocery Store
    • Hardware Store
    • Toy Store
    Food & Hospitality
    • Bar and Pub
    • Reštaurácia
    • Fast Food
    • Guest House
    • Beverage distributor
    • Hotel
    Reality
    • Real Estate Agency
    • Architecture Firm
    • Konštrukcia
    • Estate Managament
    • Gardening
    • Property Owner Association
    Poradenstvo
    • Accounting Firm
    • Odoo Partner
    • Marketing Agency
    • Law firm
    • Talent Acquisition
    • Audit & Certification
    Výroba
    • Textile
    • Metal
    • Furnitures
    • Jedlo
    • Brewery
    • Corporate Gifts
    Health & Fitness
    • Sports Club
    • Eyewear Store
    • Fitness Center
    • Wellness Practitioners
    • Pharmacy
    • Hair Salon
    Trades
    • Handyman
    • IT Hardware and Support
    • Solar Energy Systems
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Iní
    • Nonprofit Organization
    • Environmental Agency
    • Billboard Rental
    • Photography
    • Bike Leasing
    • Software Reseller
    Browse all Industries
  • Komunita
    Vzdelávanie
    • Tutoriály
    • Dokumentácia
    • Certifikácie
    • Školenie
    • Blog
    • Podcast
    Empower Education
    • Vzdelávací program
    • Scale Up! Business Game
    • Visit Odoo
    Softvér
    • Stiahnuť
    • Porovnanie Community a Enterprise vierzie
    • Releases
    Spolupráca
    • Github
    • Fórum
    • Eventy
    • Preklady
    • Staň sa partnerom
    • Services for Partners
    • Register your Accounting Firm
    Služby
    • Nájdite partnera
    • Nájdite účtovníka
    • Meet an advisor
    • Implementation Services
    • Zákaznícke referencie
    • Podpora
    • Upgrades
    ​Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Získajte demo
  • Cenník
  • Pomoc

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

  • CRM
  • e-Commerce
  • Účtovníctvo
  • Sklady
  • PoS
  • Projektové riadenie
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Tagy (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Tagy (View all)
odoo accounting v14 pos v15
About this forum
Pomoc

How to edit a record directly in a treeview (which is returned by a python function) ?

Odoberať

Get notified when there's activity on this post

This question has been flagged
12 Replies
16113 Zobrazenia
Avatar
MIADI

Hello,

In a module that I've created, when I click on a menuitem (Weight/number ratio), I execute a python function that returns a treeview. I want to be able to edit a record directly in this treeview.

Python function :

@api.multi

@api.model

def chargement_ratio(self):

        productRatio = self.env['miadi.poidsconditionnement']

        conditionnements = self._cr.execute("SELECT id FROM miadi_packaging")

        query_cond = self.env.cr.dictfetchall()

        produits = self._cr.execute("SELECT id FROM product_product")

        query_prod = self.env.cr.dictfetchall()

        for conditionnements in query_cond:

                nom_conditionnement = conditionnements['id']

                for produits in query_prod:

                        product = produits['id']

                        if_exist = self._cr.execute("SELECT * FROM miadi_poidsConditionnement WHERE conditionnement_id=%s AND produit_id=%s", (nom_conditionnement, product))

                        exist = self.env.cr.dictfetchall()

                        if not exist:

                                Ratio = productRatio.create({'conditionnement_id': nom_conditionnement, 'produit_id': product})

        return {'name': _('Weight/number Ratio'), 'view_type': 'tree', 'view_mode': 'tree', 'view_id': self.env.ref('miadi_packaging.miadi_poidsConditionnement_tree').id, 'res_model': 'miadi.poidsconditionnement', 'type': 'ir.actions.act_window', 'target': 'current',}


XML code :

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

        <field name="name">miadi.poidsconditionnement.tree</field>

        <field name="model">miadi.poidsconditionnement</field>

        <field name="arch" type="xml">

                <tree string="Weight/number ratio" editable="bottom">

                        <field name="produit_id" ref="product.product.attribute_value_ids" />

                        <field name="conditionnement_id" ref="miadi.packaging.conditionnement_id" />

                        <field name="nb_articles" />

                        <field name="poids" />

                </tree>

        </field>

</record>

<record model="ir.actions.act_window" id="action_miadi_poidsConditionnement">

        <field name="name">Weight/number ratio</field>

        <field name="type">ir.actions.act_window</field>

        <field name="res_model">miadi.poidsconditionnement</field>

        <field name="view_type">form</field>

        <field name="view_mode">tree,form</field>

        <field name="view_id" ref="miadi_poidsConditionnement_tree"/>

        <field name="help" type="html">

                <p class="oe_view_nocontent_create">Click here to create a weight/number ratio.</p>

        </field>

</record>

<record id="action_chargement_ratio" model="ir.actions.server">

        <field name="name">Chargement Ratio</field>

        <field name="type">ir.actions.server</field>

        <field name="model_id" ref="model_miadi_poidsconditionnement"/>

        <field name="code">action = env['miadi.poidsconditionnement'].chargement_ratio()</field>

</record>

<menuitem name="Weight/number ratio" id="menu_miadi_poidsConditionnement" parent="menu_miadi_packaging" sequence="15" action="action_chargement_ratio" />


Pictures for help :

The treeview returned by the function : https://www.hostingpics.net/viewer.php?id=651454Capturetreeview3.png
What I want to be able to do : https://www.hostingpics.net/viewer.php?id=575162Capturesaisie.png


PS : I'm on Odoo 10


Thanks for answer

0
Avatar
Zrušiť
Avatar
ayman mohammed adam
Best Answer

Dear Miadi,

Try to change view_type: form  instead of tree

return {'name': _('Weight/number Ratio'), 'view_type': 'form', 'view_mode': 'tree', 'view_id': self.env.ref('miadi_packaging.miadi_poidsConditionnement_tree').id, 'res_model': 'miadi.poidsconditionnement', 'type': 'ir.actions.act_window', 'target': 'current',}




I hope I helped you...
2
Avatar
Zrušiť
MIADI
Autor

Thank you very much it works !

Avatar
Niyas Raphy (Walnut Software Solutions)
Best Answer

Hi Miadi,

You can make a tree view editable by adding "editable="top" " in the tree view.

I will attach a sample code where you can edit the tree view.

<tree string="Student" editable="top">

Thank You


<record id="view_admission_student_tree" model="ir.ui.view">
<field name="name">admission.student.tree</field>
<field name="model">course.admission</field>
<field name="priority" eval="8" />
<field name="arch" type="xml">
<tree string="Student" editable="top">
<field name="name" />
<field name="middle_name" />
<field name="last_name" />
</tree>
</field>
</record>
4
Avatar
Zrušiť
MIADI
Autor

Hi Niyas,

If you look my XML code, you can see I've put : <tree editable="bottom"> but it doesn't work.

First, if you look my pictures (on links), you can see I've not a normal treeview, I can't create or select records

Niyas Raphy (Walnut Software Solutions)

Hi miadi,

You are getting such a tree view because you are returning a tree view from the python as view mode, it would be better if you can add a form view and return view mode as the form view. Then you will get the normal tree view

MIADI
Autor

Hi Niyas, can you give an example please ?

Thanks

Niyas Raphy (Walnut Software Solutions)

Hi, i will add the code in the python, you also have to add a from view in the xml.

list_view_id = imd.xmlid_to_res_id('account.invoice_tree')

form_view_id = imd.xmlid_to_res_id('account.invoice_form')

result = {

'name': action.name,

'help': action.help,

'type': action.type,

'views': [[list_view_id, 'tree'], [form_view_id, 'form'], [False, 'graph'], [False, 'kanban'], [False, 'calendar'], [False, 'pivot']],

'target': action.target,

'context': action.context,

'res_model': action.res_model,

}

MIADI
Autor

and if I already a form view in my xml ?

Here :

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

<field name="name">miadi.poidsconditionnement.form</field>

<field name="model">miadi.poidsconditionnement</field>

<field name="arch" type="xml">

<form string="Weight/number ratio">

<group col="4">

<field name="produit_id" />

<field name="conditionnement_id" />

<field name="nb_articles" />

<field name="poids" />

</group>

</form>

</field>

</record>

Niyas Raphy (Walnut Software Solutions)

in the python, make view_type as from

MIADI
Autor

Thank you very much it works !

Mitesh Dhaduk

How to make only one field editable in the tree view. And on other field click action open tree view.

Avatar
yasir iqbal
Best Answer

how to create the record in tree please as soon as possible i am new 

0
Avatar
Zrušiť
Enjoying the discussion? Don't just read, join in!

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

Registrácia
Komunita
  • Tutoriály
  • Dokumentácia
  • Fórum
Open Source
  • Stiahnuť
  • Github
  • Runbot
  • Preklady
Služby
  • Odoo.sh hosting
  • Podpora
  • Vyššia verzia
  • Custom Developments
  • Vzdelávanie
  • Nájdite účtovníka
  • Nájdite partnera
  • Staň sa partnerom
O nás
  • Naša spoločnosť
  • Majetok značky
  • Kontaktujte nás
  • Pracovné ponuky
  • Eventy
  • Podcast
  • Blog
  • Zákazníci
  • Právne dokumenty • Súkromie
  • Bezpečnosť
الْعَرَبيّة 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 sada podnikových aplikácií s otvoreným zdrojovým kódom, ktoré pokrývajú všetky potreby vašej spoločnosti: CRM, e-shop, účtovníctvo, skladové hospodárstvo, miesto predaja, projektový manažment atď.

Odoo prináša vysokú pridanú hodnotu v jednoduchom použití a súčasne plne integrovanými biznis aplikáciami.

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