Ir al contenido
Menú
Se marcó esta pregunta
1 Responder
1367 Vistas

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
Descartar
Autor Mejor respuesta

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
Descartar
Publicaciones relacionadas Respuestas Vistas Actividad
0
ago 24
899
0
nov 23
1851
1
jul 24
1686
1
mar 22
4426
1
jun 21
2889