Skip to Content
Odoo Meniu
  • Autentificare
  • Try it free
  • Aplicații
    Finanțe
    • Contabilitate
    • Facturare
    • Cheltuieli
    • Spreadsheet (BI)
    • Documente
    • Semn
    Vânzări
    • CRM
    • Vânzări
    • POS Shop
    • POS Restaurant
    • Abonamente
    • Închiriere
    Site-uri web
    • Constructor de site-uri
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Lanț Aprovizionare
    • Inventar
    • Producție
    • PLM
    • Achiziție
    • Maintenance
    • Calitate
    Resurse Umane
    • Angajați
    • Recrutare
    • Time Off
    • Evaluări
    • Referințe
    • Flotă
    Marketing
    • Social Marketing
    • Marketing prin email
    • SMS Marketing
    • Evenimente
    • Automatizare marketing
    • Sondaje
    Servicii
    • Proiect
    • Foi de pontaj
    • Servicii de teren
    • Centru de asistență
    • Planificare
    • Programări
    Productivitate
    • Discuss
    • Aprobări
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    Aplicații Terțe Odoo Studio Platforma Odoo Cloud
  • Industrii
    Retail
    • Book Store
    • Magazin de îmbrăcăminte
    • Magazin de Mobilă
    • Magazin alimentar
    • Magazin de materiale de construcții
    • Magazin de jucării
    Food & Hospitality
    • Bar and Pub
    • Restaurant
    • Fast Food
    • Guest House
    • Distribuitor de băuturi
    • Hotel
    Proprietate imobiliara
    • Real Estate Agency
    • Firmă de Arhitectură
    • Construcție
    • Estate Managament
    • Grădinărit
    • Asociația Proprietarilor de Proprietăți
    Consultanta
    • Firma de Contabilitate
    • Partener Odoo
    • Agenție de marketing
    • Law firm
    • Atragere de talente
    • Audit & Certification
    Producție
    • Textil
    • Metal
    • Mobilier
    • Mâncare
    • Brewery
    • Cadouri corporate
    Health & Fitness
    • Club Sportiv
    • Magazin de ochelari
    • Centru de Fitness
    • Wellness Practitioners
    • Farmacie
    • Salon de coafură
    Trades
    • Handyman
    • IT Hardware and Support
    • Asigurare socială de stat
    • Cizmar
    • Servicii de curățenie
    • HVAC Services
    Altele
    • Organizație nonprofit
    • Agenție de Mediu
    • Închiriere panouri publicitare
    • Fotografie
    • Închiriere biciclete
    • Asigurare socială
    Browse all Industries
  • Comunitate
    Învăță
    • Tutorials
    • Documentație
    • Certificări
    • Instruire
    • Blog
    • Podcast
    Empower Education
    • Program Educațional
    • Scale Up! Business Game
    • Visit Odoo
    Obține Software-ul
    • Descărcare
    • Compară Edițiile
    • Lansări
    Colaborați
    • Github
    • Forum
    • Evenimente
    • Translations
    • Devino Partener
    • Services for Partners
    • Înregistrează-ți Firma de Contabilitate
    Obține Servicii
    • Găsește un Partener
    • Găsiți un contabil
    • Meet an advisor
    • Servicii de Implementare
    • Referințe ale clienților
    • Suport
    • Actualizări
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Obține un demo
  • Prețuri
  • Ajutor

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

  • CRM
  • e-Commerce
  • Contabilitate
  • Inventar
  • PoS
  • Proiect
  • MRP
All apps
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
All Posts Oameni Insigne
Etichete (View all)
odoo accounting v14 pos v15
Despre acest forum
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
All Posts Oameni Insigne
Etichete (View all)
odoo accounting v14 pos v15
Despre acest forum
Suport

How to call ir.actions.act_window from python to menuitem

Abonare

Primiți o notificare când există activitate la acestă postare

Această întrebare a fost marcată
actionfiltermenuitemcontextir.actions.server
4 Răspunsuri
34189 Vizualizări
Imagine profil
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
Imagine profil
Abandonează
Sehrish

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

Imagine profil
Jitendra Prajapati (jpr)
Cel mai bun răspuns

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
Imagine profil
Abandonează
Deborah Joy Adeva
Autor

It worked! Thank you so much :)

Imagine profil
Mitul Shingala
Cel mai bun răspuns

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
Imagine profil
Abandonează
Imagine profil
Mohamed Reda Mahfouz
Cel mai bun răspuns

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

0
Imagine profil
Abandonează
Imagine profil
Andres Brigard
Cel mai bun răspuns

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

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

Înscrie-te
Related Posts Răspunsuri Vizualizări Activitate
How to use the previous context in the action definition? Rezolvat
action context
Imagine profil
Imagine profil
1
apr. 25
4691
menuitem get disabled when I assign tree view action in menuitem action
action menuitem
Imagine profil
Imagine profil
1
iul. 22
2659
Passing two filters in context using the AND operator
filter context v17
Imagine profil
0
apr. 24
2472
List view doesn't appear by performing action (Odoo v16) Rezolvat
action menuitem listview
Imagine profil
Imagine profil
2
aug. 23
3498
how to add more then one default filter?
action filter odoo10
Imagine profil
Imagine profil
2
apr. 24
5783
Comunitate
  • Tutorials
  • Documentație
  • Forum
Open Source
  • Descărcare
  • Github
  • Runbot
  • Translations
Servicii
  • Hosting Odoo.sh
  • Suport
  • Actualizare
  • Custom Developments
  • Educație
  • Găsiți un contabil
  • Găsește un Partener
  • Devino Partener
Despre Noi
  • Compania noastră
  • Active de marcă
  • Contactați-ne
  • Locuri de muncă
  • Evenimente
  • Podcast
  • Blog
  • Clienți
  • Aspecte juridice • Confidențialitate
  • Securitate
الْعَرَبيّة 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 este o suită de aplicații de afaceri open source care acoperă toate nevoile companiei dvs.: CRM, comerț electronic, contabilitate, inventar, punct de vânzare, management de proiect etc.

Propunerea de valoare unică a Odoo este să fie în același timp foarte ușor de utilizat și complet integrat.

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