Skip to Content
Odoo Menu
  • Prijavi
  • Try it free
  • Aplikacije
    Finance
    • Knjigovodstvo
    • Obračun
    • Stroški
    • Spreadsheet (BI)
    • Dokumenti
    • Podpisovanje
    Prodaja
    • CRM
    • Prodaja
    • POS Shop
    • POS Restaurant
    • Naročnine
    • Najem
    Spletne strani
    • Website Builder
    • Spletna trgovina
    • Blog
    • Forum
    • Pogovor v živo
    • eUčenje
    Dobavna veriga
    • Zaloga
    • Proizvodnja
    • PLM
    • Nabava
    • Vzdrževanje
    • Kakovost
    Kadri
    • Kadri
    • Kadrovanje
    • Odsotnost
    • Ocenjevanja
    • Priporočila
    • Vozni park
    Marketing
    • Družbeno Trženje
    • Email Marketing
    • SMS Marketing
    • Dogodki
    • Avtomatizacija trženja
    • Ankete
    Storitve
    • Projekt
    • Časovnice
    • Storitve na terenu
    • Služba za pomoč
    • Načrtovanje
    • Termini
    Produktivnost
    • Razprave
    • Odobritve
    • IoT
    • Voip
    • Znanje
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Industrije
    Trgovina na drobno
    • Book Store
    • Trgovina z oblačili
    • Trgovina s pohištvom
    • Grocery Store
    • Trgovina s strojno opremo računalnikov
    • Trgovina z igračami
    Food & Hospitality
    • Bar and Pub
    • Restavracija
    • Hitra hrana
    • Guest House
    • Beverage Distributor
    • Hotel
    Nepremičnine
    • Real Estate Agency
    • Arhitekturno podjetje
    • Gradbeništvo
    • Estate Management
    • Vrtnarjenje
    • Združenje lastnikov nepremičnin
    Svetovanje
    • Računovodsko podjetje
    • Odoo Partner
    • Marketinška agencija
    • Law firm
    • Pridobivanje talentov
    • Audit & Certification
    Proizvodnja
    • Tekstil
    • Metal
    • Pohištvo
    • Hrana
    • Brewery
    • Poslovna darila
    Health & Fitness
    • Športni klub
    • Trgovina z očali
    • Fitnes center
    • Wellness Practitioners
    • Lekarna
    • Frizerski salon
    Trades
    • Handyman
    • IT Hardware & Support
    • Sistemi sončne energije
    • Izdelovalec čevljev
    • Čistilne storitve
    • HVAC Services
    Ostali
    • Neprofitna organizacija
    • Agencija za okolje
    • Najem oglasnih panojev
    • Fotografija
    • Najem koles
    • Prodajalec programske opreme
    Browse all Industries
  • Skupnost
    Learn
    • Tutorials
    • Dokumentacija
    • Certifikati
    • Šolanje
    • Blog
    • Podcast
    Empower Education
    • Education Program
    • Scale Up! Business Game
    • Visit Odoo
    Get the Software
    • Prenesi
    • Compare Editions
    • Releases
    Collaborate
    • Github
    • Forum
    • Dogodki
    • Prevodi
    • Become a Partner
    • Services for Partners
    • Register your Accounting Firm
    Get Services
    • Find a Partner
    • Find an Accountant
    • Meet an advisor
    • Implementation Services
    • Sklici kupca
    • Podpora
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Get a demo
  • Določanje cen
  • Pomoč

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

  • CRM
  • e-Commerce
  • Knjigovodstvo
  • Zaloga
  • PoS
  • Projekt
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Ključne besede (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Ključne besede (View all)
odoo accounting v14 pos v15
About this forum
Pomoč

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

Naroči se

Get notified when there's activity on this post

This question has been flagged
12 Odgovori
16118 Prikazi
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
Opusti
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
Opusti
MIADI
Avtor

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
Opusti
MIADI
Avtor

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
Avtor

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
Avtor

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
Avtor

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

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

Prijavi
Community
  • Tutorials
  • Dokumentacija
  • Forum
Open Source
  • Prenesi
  • Github
  • Runbot
  • Prevodi
Services
  • Odoo.sh Hosting
  • Podpora
  • Nadgradnja
  • Custom Developments
  • Izobraževanje
  • Find an Accountant
  • Find a Partner
  • Become a Partner
About us
  • Our company
  • Sredstva blagovne znamke
  • Kontakt
  • Zaposlitve
  • Dogodki
  • Podcast
  • Blog
  • Stranke
  • Pravno • Zasebnost
  • Varnost
الْعَرَبيّة 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 is a suite of open source business apps that cover all your company needs: CRM, eCommerce, accounting, inventory, point of sale, project management, etc.

Odoo's unique value proposition is to be at the same time very easy to use and fully integrated.

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