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
    Restauration & Hôtellerie
    • 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
    • Brasserie
    • Cadeaux d'entreprise
    Santé & Fitness
    • Club de sports
    • Opticien
    • Salle de fitness
    • Praticiens bien-être
    • Pharmacie
    • Salon de coiffure
    Commerce
    • Bricoleur
    • Matériel informatique & 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
    Parcourir toutes les 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 pour partenaires
    • 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 call ir.actions.act_window from python to menuitem

S'inscrire

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

Cette question a été signalée
actionfiltermenuitemcontextir.actions.server
4 Réponses
34135 Vues
Avatar
Deborah Joy Adeva

Please help me, I need to filter leave requests by department depending on the department of the user logged in.

I tried simple Print inside the method it is working but it doesn't open the action window

Please tell me what's wrong or if there's easier way to do it. Thank you so much in advance.

Here's my code: 

Py:

    @api.multi

    def leave_filter_act(self):

        hr_emp = self.env['hr.employee'].search([('user_id', '=', self.env.user.id)])

       print hr_emp.department_id.id  #this is working

        return {

                'name': _("Leave Approvals"),

                'type': 'ir.actions.act_window',

                'res_model': 'hr.holidays',

                'view_mode': 'tree,form',

                'view_type': 'form',

                'views': [[False, 'tree'],[False, 'form'],],

                'context': {'search_default_department_id': [hr_emp.department_id.id]},

                'target': 'current',

            }

XML:

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

          <field name="name">Leave Filter</field>

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

          <field name="code">env.get('hr.holidays').leave_filter_act()</field>

 </record>


 <menuitem

            id="menu_open_department_leave_approve_offcr"

            name="My Department"

            parent="hr_holidays.menu_hr_holidays_approvals"

            action="action_server_leave_filter"/>


0
Avatar
Ignorer
Sehrish

Show records on TreeView that are related to Active User: https://goo.gl/hv4WAi

Avatar
Jitendra Prajapati (jpr)
Meilleure réponse

Hello  Deb Joy

replace your 'action_server_leave_filter' record with this one

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

          <field name="name">Leave Filter</field>

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

          <field name="state">code</field>

          <field name="code">action =  env.get('hr.holidays').leave_filter_act()</field>

 </record>


I hope it's work fine in your case.

6
Avatar
Ignorer
Deborah Joy Adeva
Auteur

It worked! Thank you so much :)

Avatar
Mitul Shingala
Meilleure réponse

hello into python you can do like

def leave_filter_act(self):
    action = self.env.ref('module_name.action_server_leave_filter').read()[0]   
 return action
7
Avatar
Ignorer
Avatar
Mohamed Reda Mahfouz
Meilleure réponse

if you used the ir.actions.server if the user press back then forward from the browser the filter will be removed

0
Avatar
Ignorer
Avatar
Andres Brigard
Meilleure réponse

Hi, I have slightly similar case. I am trying to call a method that calls a google maps report produced in python because with qweb was too difficult. 

<record id="action_map_report" model="ir.actions.server">
<field name="name">Reporte Google Maps</field>
    <field name="condition">True</field>
    <field name="type">ir.actions.server</field>
 <field name="model_id" ref="model_operaciones_servicios"/>
    <field name="state">code</field>
    <field name="code">action=self.generar_reporte_gmaps_servicios(cr,uid,context.get('active_ids'), context=context)</field>
</record>
<record model="ir.values" id="ir_operaciones_servicios_map_report">
    <field name="key2">client_action_multi</field>
    <field name="name">Analisis Recorrido en Google Maps</field>
    <field name="value" eval="'ir.actions.act_window,' + str(ref('operaciones.action_map_report'))" />
    <field name="key">action</field>
    <field name="model">operaciones.servicios</field>
 </record>

Here is the method that I am calling that is in the operaciones.servicios class:

@api.model
def generar_reporte_gmaps_servicios(self):
    fecha1 = self.fecha_reporte[:8] + '01'
    return {
        "type": "ir.actions.act_url",
        "url": "/web/operaciones/gmaps/servicios?ids=%s" % (self.ids),
        "target": "self",
        }

When a load the operaciones.servicios form returns this error:

Traceback (most recent call last):
  File "/home/odoo/odoo8/openerp/http.py", line 518, in _handle_exception
    return super(JsonRequest, self)._handle_exception(exception)
  File "/home/odoo/odoo8/openerp/http.py", line 539, in dispatch
    result = self._call_function(**self.params)
  File "/home/odoo/odoo8/openerp/http.py", line 295, in _call_function
    return checked_call(self.db, *args, **kwargs)
  File "/home/odoo/odoo8/openerp/service/model.py", line 113, in wrapper
    return f(dbname, *args, **kwargs)
  File "/home/odoo/odoo8/openerp/http.py", line 292, in checked_call
    return self.endpoint(*a, **kw)
  File "/home/odoo/odoo8/openerp/http.py", line 755, in __call__
    return self.method(*args, **kw)
  File "/home/odoo/odoo8/openerp/http.py", line 388, in response_wrap
    response = f(*args, **kw)
  File "/home/odoo/odoo8/openerp/addons/web/controllers/main.py", line 949, in call_kw
    return self._call_kw(model, method, args, kwargs)
  File "/home/odoo/odoo8/openerp/addons/web/controllers/main.py", line 941, in _call_kw
    return getattr(request.registry.get(model), method)(request.cr, request.uid, *args, **kwargs)
  File "/home/odoo/odoo8/openerp/api.py", line 238, in wrapper
    return old_api(self, *args, **kwargs)
  File "/home/odoo/odoo8/openerp/addons/mail/mail_thread.py", line 344, in fields_view_get
    res = super(mail_thread, self).fields_view_get(cr, uid, view_id=view_id, view_type=view_type, context=context, toolbar=toolbar, submenu=submenu)
  File "/home/odoo/odoo8/openerp/api.py", line 238, in wrapper
    return old_api(self, *args, **kwargs)
  File "/home/odoo/odoo8/openerp/models.py", line 1570, in fields_view_get
    resaction = ir_values_obj.get(cr, uid, 'action', 'client_action_multi', [(self._name, False)], False, context)
  File "/home/odoo/odoo8/openerp/api.py", line 238, in wrapper
    return old_api(self, *args, **kwargs)
  File "/home/odoo/odoo8/openerp/addons/calendar/calendar.py", line 620, in get
    meta, context, res_id_req, without_user, key2_req)
  File "/home/odoo/odoo8/openerp/api.py", line 238, in wrapper
    return old_api(self, *args, **kwargs)
  File "/home/odoo/odoo8/openerp/addons/base/ir/ir_values.py", line 501, in get
 return self._map_legacy_model_list(models, do_get, merge_results=True)
  File "/home/odoo/odoo8/openerp/addons/base/ir/ir_values.py", line 458, in _map_legacy_model_list
    result = map_fn(model, res_id)
  File "/home/odoo/odoo8/openerp/addons/base/ir/ir_values.py", line 500, in do_get
    return self.get_actions(cr, uid, action_slot=key2, model=model, res_id=res_id, context=context)
  File "/home/odoo/odoo8/openerp/api.py", line 238, in wrapper
    return old_api(self, *args, **kwargs)
  File "/home/odoo/odoo8/openerp/addons/base/ir/ir_values.py", line 429, in get_actions
    action_def = action_model.read(cr, uid, int(action_id), fields, context)
  File "/home/odoo/odoo8/openerp/api.py", line 238, in wrapper
    return old_api(self, *args, **kwargs)
  File "/home/odoo/odoo8/openerp/addons/base/ir/ir_actions.py", line 349, in read
    return results[0]
IndexError: list index out of range

When I delete the actions the form loads OK. What is wrong please?

0
Avatar
Ignorer
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é
How to use the previous context in the action definition? Résolu
action context
Avatar
Avatar
1
avr. 25
4677
menuitem get disabled when I assign tree view action in menuitem action
action menuitem
Avatar
Avatar
1
juil. 22
2652
Passing two filters in context using the AND operator
filter context v17
Avatar
0
avr. 24
2463
List view doesn't appear by performing action (Odoo v16) Résolu
action menuitem listview
Avatar
Avatar
2
août 23
3486
how to add more then one default filter?
action filter odoo10
Avatar
Avatar
2
avr. 24
5777
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