Odooers论坛

欢迎!

该社区面向专业人士和我们产品和服务的爱好者。
分享和讨论最好的内容和新的营销理念,建立您的专业形象,一起成为更好的营销人员。


0

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

1 备注
形象
丢弃
形象
odoo
-

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

3 答案
0
形象
odoo
最佳答案

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.

1 备注
形象
丢弃
形象
odoo
-

It worked! Thank you so much :)

0
形象
odoo
最佳答案

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
形象
丢弃
0
形象
odoo
最佳答案

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?

形象
丢弃