Se rendre au contenu
Odoo Menu
  • Se connecter
  • Essai gratuit
  • Applications
    Finance
    • Comptabilité
    • Facturation
    • Notes de frais
    • Feuilles de calcul (BI)
    • Documents
    • Signature
    Ventes
    • CRM
    • Ventes
    • PdV Boutique
    • PdV Restaurant
    • Abonnements
    • Location
    Sites web
    • Site Web
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Chaîne d'approvisionnement
    • Inventaire
    • Fabrication
    • PLM
    • Achats
    • Maintenance
    • Qualité
    Ressources Humaines
    • Employés
    • Recrutement
    • Congés
    • Évaluations
    • Recommandations
    • Parc automobile
    Marketing
    • Marketing Social
    • E-mail Marketing
    • SMS Marketing
    • Événements
    • Marketing Automation
    • Sondages
    Services
    • Projet
    • Feuilles de temps
    • Services sur Site
    • Assistance
    • Planification
    • Rendez-vous
    Productivité
    • Discussion
    • Validations
    • Internet des Objets
    • VoIP
    • Connaissances
    • WhatsApp
    Applications tierces Odoo Studio Plateforme Cloud d'Odoo
  • Industries
    Commerce de détail
    • Librairie
    • Magasin de vêtements
    • Magasin de meubles
    • Épicerie
    • Quincaillerie
    • Magasin de jouets
    Food & Hospitality
    • Bar et Pub
    • Restaurant
    • Fast-food
    • Maison d’hôtes
    • Distributeur de boissons
    • Hôtel
    Immobilier
    • Agence immobilière
    • Cabinet d'architecture
    • Construction
    • Gestion immobilière
    • Jardinage
    • Association de copropriétaires
    Consultance
    • Cabinet d'expertise comptable
    • Partenaire Odoo
    • Agence Marketing
    • Cabinet d'avocats
    • Aquisition de talents
    • Audit & Certification
    Fabrication
    • Textile
    • Métal
    • Meubles
    • Alimentation
    • Brewery
    • Cadeaux d'entreprise
    Santé & Fitness
    • Club de sports
    • Opticien
    • Salle de fitness
    • Praticiens bien-être
    • Pharmacie
    • Salon de coiffure
    Trades
    • Bricoleur
    • Matériel informatique et support
    • Systèmes photovoltaïques
    • Cordonnier
    • Services de nettoyage
    • Services CVC
    Autres
    • Organisation à but non lucratif
    • Agence environnementale
    • Location de panneaux d'affichage
    • Photographie
    • Leasing de vélos
    • Revendeur de logiciel
    Browse all Industries
  • Communauté
    Apprenez
    • Tutoriels
    • Documentation
    • Certifications
    • Formation
    • Blog
    • Podcast
    Renforcer l'éducation
    • Programme éducatif
    • Business Game Scale-Up!
    • Rendez-nous visite
    Obtenir le logiciel
    • Téléchargement
    • Comparez les éditions
    • Versions
    Collaborer
    • Github
    • Forum
    • Événements
    • Traductions
    • Devenez partenaire
    • Services for Partners
    • Enregistrer votre cabinet comptable
    Nos Services
    • Trouver un partenaire
    • Trouver un comptable
    • Rencontrer un conseiller
    • Services de mise en œuvre
    • Références clients
    • Assistance
    • Mises à niveau
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Obtenir une démonstration
  • Tarification
  • Aide

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

  • CRM
  • e-Commerce
  • Comptabilité
  • Inventaire
  • PoS
  • Projet
  • MRP
All apps
Vous devez être inscrit pour interagir avec la communauté.
Toutes les publications Personnes Badges
Étiquettes (Voir toutl)
odoo accounting v14 pos v15
À propos de ce forum
Vous devez être inscrit pour interagir avec la communauté.
Toutes les publications Personnes Badges
Étiquettes (Voir toutl)
odoo accounting v14 pos v15
À propos de ce forum
Aide

How to open a form with ir.action.server which executes python code

S'inscrire

Recevez une notification lorsqu'il y a de l'activité sur ce poste

Cette question a été signalée
pythonxmlformformview
2 Réponses
49705 Vues
Avatar
Eric

Hello, 

  I have a custom module that has a new item in the "More" contextual dropdown menu.  When the item is clicked, it calls an action saved to the ir.action.server.  The action executes python code like it's supposed to.  The python code creates a new record on the sale.order table and is supposed to open the sale.order form with the newly created record.  I have a return statement at the end of the python code which is supposed to open the sale.order form, but for some reason it isn't.  I don't understand why, because the same return statement works on other function calls except this one.  Can anyone help me open the sale.order form after my function has created a new record on the sale.order model?

Here is the code that adds the line to the "More" contextual dropdown:

<record model="ir.values" id="test_more_item">
            <field name="name">New More Item</field>
            <field name="model" eval="'sale.licenses'" />
            <field name="key" >action</field>
            <field name="key2">client_action_multi</field>
            <field name="value" eval="'ir.actions.server,%d'%sale_license_more_item_action" />
            <field name="object" eval="True" />
        </record>

 

This is the action the the "More" item calls.  its from the ir.action.server

<record id="sale_license_more_item_action" model="ir.actions.server">
            <field name="name">Renew Licenses</field>
            <field name="type">ir.actions.server</field>
            <field name="res_model">sale.order</field>
            <field name="model_id" >283</field>
            <field name="view_type">form</field>
            <field name="view_mode">form</field>
            <field name="state">code</field>
            <field name="code">self.renew_license(cr, uid, context.get('active_ids', []), context=context)</field>
        </record>

 

This is the function that is called from the server action

def renew_license(self, cr, uid, ids, context=None):

     ...(code that creates new sale.order record)

     return {
            'name': 'Sale Order Form',
            'view_type': 'form',
            'view_mode': 'form',
            'view_id': self.pool.get('ir.ui.view').search(cr, uid, [('name','=','sale.order.form')])[0],
            'res_model': 'sale.order',
            'res_id': new_order_id,
            'type': 'ir.actions.act_window',
        }

Normally the return statement would open the sale.order form, but in this case it isn't.  Does anyone know what I am doing wrong with this?

4
Avatar
Ignorer
Avatar
Eric
Auteur Meilleure réponse

I finally got the answer right.  Thanks to Maniganda's answer found on this link: 

https://www.odoo.com/forum/help-1/question/call-function-from-the-more-dropdown-list-61330

 

All I needed to do was change this line:

<field name="code">self.renew_license(cr, uid, context.get('active_ids', []), context=context)</field>

 

To this:

<field name="code">action = self.renew_license(cr, uid, context.get('active_ids', []), context=context)</field>

 

Thank you Maniganda!

9
Avatar
Ignorer
Ubaid ur Rehman

Thanks @Eric and @Maniganda your answer save my time.

Avatar
Ben Bernard
Meilleure réponse

This is my guessing (I never do this). I think the problem is that new sale order, new_order_id, record hasn't been commited. As far as I know odoo commit transaction at the end of request. So when the method return an action, odoo makes the action void because new_order_id is not available yet.

0
Avatar
Ignorer
Eric
Auteur

Hello Ben, I tried testing this by using an ID of another sale order, but it still didn't open the form view. Thanks for your reply

Sehrish

Server Action in Odoo: http://learnopenerp.blogspot.com/2020/01/odoo-server-action.html

Vous appréciez la discussion ? Ne vous contentez pas de lire, rejoignez-nous !

Créez un compte dès aujourd'hui pour profiter de fonctionnalités exclusives et échanger avec notre formidable communauté !

S'inscrire
Publications associées Réponses Vues Activité
Dynamic form depending of values in a one2many
python xml form v14
Avatar
0
juin 21
3697
Embedding youtube video in form view
xml form view video formview
Avatar
Avatar
1
oct. 24
2527
How to edit sign up form for new customers on your website Résolu
python xml web form website
Avatar
Avatar
2
mai 24
9724
How to hide view.xml fields group in Account module with attr
python xml
Avatar
Avatar
Avatar
2
déc. 23
13955
how to remove first empty element from fields.selection Résolu
python xml
Avatar
Avatar
Avatar
3
juil. 22
24374
Communauté
  • Tutoriels
  • Documentation
  • Forum
Open Source
  • Téléchargement
  • Github
  • Runbot
  • Traductions
Services
  • Hébergement Odoo.sh
  • Assistance
  • Migration
  • Développements personnalisés
  • Éducation
  • Trouver un comptable
  • Trouver un partenaire
  • Devenez partenaire
À propos
  • Notre société
  • Actifs de la marque
  • Contactez-nous
  • Emplois
  • Événements
  • Podcast
  • Blog
  • Clients
  • Informations légales • Confidentialité
  • Sécurité.
الْعَرَبيّة 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 est une suite d'applications open source couvrant tous les besoins de votre entreprise : CRM, eCommerce, Comptabilité, Inventaire, Point de Vente, Gestion de Projet, etc.

Le positionnement unique d'Odoo est d'être à la fois très facile à utiliser et totalement intégré.

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