Skip to Content
Odoo Menu
  • Prihlásiť sa
  • Vyskúšajte zadarmo
  • Aplikácie
    Financie
    • Účtovníctvo
    • Fakturácia
    • Výdavky
    • Tabuľka (BI)
    • Dokumenty
    • Podpis
    Predaj
    • CRM
    • Predaj
    • POS Shop
    • POS Restaurant
    • Manažment odberu
    • Požičovňa
    Webstránky
    • Tvorca webstránok
    • eShop
    • Blog
    • Fórum
    • Živý chat
    • eLearning
    Supply Chain
    • Sklad
    • Výroba
    • Správa životného cyklu produktu
    • Nákup
    • Údržba
    • Manažment kvality
    Ľudské zdroje
    • Zamestnanci
    • Nábor zamestnancov
    • Voľné dni
    • Hodnotenia
    • Odporúčania
    • Vozový park
    Marketing
    • Marketing sociálnych sietí
    • Email marketing
    • SMS marketing
    • Eventy
    • Marketingová automatizácia
    • Prieskumy
    Služby
    • Projektové riadenie
    • Pracovné výkazy
    • Práca v teréne
    • Helpdesk
    • Plánovanie
    • Schôdzky
    Produktivita
    • Tímová komunikácia
    • Schvalovania
    • IoT
    • VoIP
    • Znalosti
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Priemyselné odvetvia
    Retail
    • Book Store
    • Clothing Store
    • Furniture Store
    • Grocery Store
    • Hardware Store
    • Toy Store
    Food & Hospitality
    • Bar and Pub
    • Reštaurácia
    • Fast Food
    • Guest House
    • Beverage distributor
    • Hotel
    Reality
    • Real Estate Agency
    • Architecture Firm
    • Konštrukcia
    • Estate Managament
    • Gardening
    • Property Owner Association
    Poradenstvo
    • Accounting Firm
    • Odoo Partner
    • Marketing Agency
    • Law firm
    • Talent Acquisition
    • Audit & Certification
    Výroba
    • Textile
    • Metal
    • Furnitures
    • Jedlo
    • Brewery
    • Corporate Gifts
    Health & Fitness
    • Sports Club
    • Eyewear Store
    • Fitness Center
    • Wellness Practitioners
    • Pharmacy
    • Hair Salon
    Trades
    • Handyman
    • IT Hardware and Support
    • Solar Energy Systems
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Iní
    • Nonprofit Organization
    • Environmental Agency
    • Billboard Rental
    • Photography
    • Bike Leasing
    • Software Reseller
    Browse all Industries
  • Komunita
    Vzdelávanie
    • Tutoriály
    • Dokumentácia
    • Certifikácie
    • Školenie
    • Blog
    • Podcast
    Empower Education
    • Vzdelávací program
    • Scale Up! Business Game
    • Visit Odoo
    Softvér
    • Stiahnuť
    • Porovnanie Community a Enterprise vierzie
    • Releases
    Spolupráca
    • Github
    • Fórum
    • Eventy
    • Preklady
    • Staň sa partnerom
    • Services for Partners
    • Register your Accounting Firm
    Služby
    • Nájdite partnera
    • Nájdite účtovníka
    • Meet an advisor
    • Implementation Services
    • Zákaznícke referencie
    • Podpora
    • Upgrades
    ​Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Získajte demo
  • Cenník
  • Pomoc

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

  • CRM
  • e-Commerce
  • Účtovníctvo
  • Sklady
  • PoS
  • Projektové riadenie
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Tagy (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Tagy (View all)
odoo accounting v14 pos v15
About this forum
Pomoc

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

Odoberať

Get notified when there's activity on this post

This question has been flagged
actionfiltermenuitemcontextir.actions.server
4 Replies
34152 Zobrazenia
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
Zrušiť
Sehrish

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

Avatar
Jitendra Prajapati (jpr)
Best Answer

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
Zrušiť
Deborah Joy Adeva
Autor

It worked! Thank you so much :)

Avatar
Mitul Shingala
Best Answer

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
Zrušiť
Avatar
Mohamed Reda Mahfouz
Best Answer

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

0
Avatar
Zrušiť
Avatar
Andres Brigard
Best Answer

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

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

Registrácia
Related Posts Replies Zobrazenia Aktivita
How to use the previous context in the action definition? Solved
action context
Avatar
Avatar
1
apr 25
4682
menuitem get disabled when I assign tree view action in menuitem action
action menuitem
Avatar
Avatar
1
júl 22
2656
Passing two filters in context using the AND operator
filter context v17
Avatar
0
apr 24
2464
List view doesn't appear by performing action (Odoo v16) Solved
action menuitem listview
Avatar
Avatar
2
aug 23
3489
how to add more then one default filter?
action filter odoo10
Avatar
Avatar
2
apr 24
5778
Komunita
  • Tutoriály
  • Dokumentácia
  • Fórum
Open Source
  • Stiahnuť
  • Github
  • Runbot
  • Preklady
Služby
  • Odoo.sh hosting
  • Podpora
  • Vyššia verzia
  • Custom Developments
  • Vzdelávanie
  • Nájdite účtovníka
  • Nájdite partnera
  • Staň sa partnerom
O nás
  • Naša spoločnosť
  • Majetok značky
  • Kontaktujte nás
  • Pracovné ponuky
  • Eventy
  • Podcast
  • Blog
  • Zákazníci
  • Právne dokumenty • Súkromie
  • Bezpečnosť
الْعَرَبيّة 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 je sada podnikových aplikácií s otvoreným zdrojovým kódom, ktoré pokrývajú všetky potreby vašej spoločnosti: CRM, e-shop, účtovníctvo, skladové hospodárstvo, miesto predaja, projektový manažment atď.

Odoo prináša vysokú pridanú hodnotu v jednoduchom použití a súčasne plne integrovanými biznis aplikáciami.

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