Skip to Content
Menu
This question has been flagged
1 Reply
1213 Views

I'm extending gantt view to add new button. The button is working. The problem is when i try to use RPC or ORM, I got this error

`Uncaught Promise > Cannot read properties of null (reading 'component')` 

I think GanttController is extending AbstractController



Here is the javascript 


/** @odoo-module */

import { _t } from 'web.core';
import { useService } from "@web/core/utils/hooks";

export const ControllerMixin = {
    async _onMovePlanClick(ev) {
        // const rpc = useService('rpc');
        ev.preventDefault();
        $.exposed = {
            this:this,
            useService:useService
        };
        console.log(
            'ControllerMixin._onMovePlanClick'
        );
        const orm = useService("orm");
        const project_id = await orm.call('project.task', 'get_project_id', [this.context.active_id])
        this.do_action({
            name: _t('Move Plan'),
            type: 'ir.actions.act_window',
            res_model: 'project.task.move.plan.wizard',
            views: [[false, 'form']],
            target: 'new',
            context: {'default_project_id': project_id},
        })
       
    },

};

This is the python



class Task(models.Model):
    _inherit = "project.task"

    def get_project_id(self):
        return self.project_id.id



I test it without calling const orm = useService("orm");​. It's working fine. So the problem is when defining orm or rpc variable


In other case, I'm extending CharField and ORM is working fine



Avatar
Discard
Author Best Answer

I see some code in the odoo base and it use this._rpc​. Anyway if anyone curious on how to use it

    this._rpc({
      model: "project.project",
      method: "get_project_id",
      args: [this.context.active_id],
    }).then((res) => {
// res is the return value from the model
    });




Avatar
Discard
Related Posts Replies Views Activity
0
Aug 24
729
0
Nov 23
1716
1
Jul 24
1458
1
Mar 22
4187
1
Jun 21
2708