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
    Immobiliari
    • Agència immobiliària
    • Estudi d'arquitectura
    • Construcció
    • Gestió immobiliària
    • Jardineria
    • Associació de propietaris de béns immobles
    Consultoria
    • Empresa comptable
    • Partner d'Odoo
    • Agència de màrqueting
    • Bufet d'advocats
    • Captació de talent
    • Auditoria i certificació
    Fabricació
    • Textile
    • Metal
    • Mobles
    • Menjar
    • 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
    • Sistemes d'energia solar
    • Shoe Maker
    • Serveis de neteja
    • Instal·lacions HVAC
    Altres
    • 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

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

Subscriure's

Get notified when there's activity on this post

This question has been flagged
12 Respostes
16107 Vistes
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
Descartar
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
Descartar
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
Descartar
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
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
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