Pawan Kumar Sharma
Pawan Kumar Sharma

Reputation: 1168

How to show action_id by do_action() java-script method in Odoo 11

When i'm calling do_action method from java-script code, i'm not getting action id. Due to this when i'm refreshing or reloading page my form is blank. I'm using Odoo 11.

action_timesheet_user: function(event) {
    var self = this;
    event.stopPropagation();
    event.preventDefault();
    alert(self.employee_data.timesheet_action);
    if (self.employee_data.uid == 1){
        this.do_action({
        name: _t("Timesheets"),
        type: 'ir.actions.act_window',
        res_model: 'account.analytic.line',
        view_mode: 'tree,form',
        view_type: 'form',
        views: [[false, 'list'],[false, 'form']],
        context: {
                //'search_default_employee_id': [self.employee_data.id],
                'search_default_month': true,
                },
        target: 'current'
        })}
    else {
        this.do_action({
        name: _t("Timesheets"),
        type: 'ir.actions.act_window',
        res_model: 'account.analytic.line',
        view_mode: 'tree,form',
        view_type: 'form',
        views: [[false, 'list'],[false, 'form']],
        context: {
                //'search_default_employee_id': [self.employee_data.uid],
                'search_default_month': true,
                },
        domain: ['|','|',['user_id', '=', self.employee_data.uid],
        ['employee_id.department_id.manager_id.user_id', '=', self.employee_data.uid],
        ['project_id.user_id','in',[self.employee_data.uid]]],
        target: 'current'
        },{on_reverse_breadcrumb: function(){ return self.reload();}})}
    },

events: _.extend({}, Widget.prototype.events, {'click .custom_helpdesk_tickets': 'action_custom_helpdesk_tickets'}),

Xml Template:

<div><a class="btn btn-primary btn-block custom_helpdesk_tickets" role="button"><strong>Helpdesk</strong></a></div>

after calling this function on template button i'm getting:

        http://localhost:8069/web?#view_type=list&model=account.analytic.line

Requirement:

        http://localhost:8069/web?debug#view_type=list&model=account.analytic.line&menu_id=458&action=487

Thanks in Advance.

Upvotes: 0

Views: 2531

Answers (2)

Keval Mehta
Keval Mehta

Reputation: 664

From do_action method you can not create a new action, you perform any created action. So in that you have to give id of action which has to be perform.

Upvotes: 0

Jainik Patel
Jainik Patel

Reputation: 2324

if above code is not works then you will try second method below is example code you will use this code

XML code:

<record id="hr_timesheets_attendance_action_kanban" model="ir.actions.act_window">
    <field name="name">Timesheets</field>
    <field name="res_model">account.analytic.line</field>
    <field name="view_mode">tree,form</field>
    <field name="help" type="html">
        <p>
            To create employees timesheet.
        </p>
    </field>
</record>

JS Code

this.do_action('module_name.hr_timesheets_attendance_action_kanban');

Thanks

Upvotes: 2

Related Questions