3

I'm trying to register an act_window within the setup method using the useService Hook, but it doesn't work.

This is my component.

    /** @odoo-module **/
    // const { useState, useRef } = owl.hooks;
    import { useEffect, useService } from "@web/core/utils/hooks";
    import AbstractField from 'web.AbstractFieldOwl'
    import { _lt } from 'web.translation';
    
    class ReferenceButtonWidget extends AbstractField {
    
      setup() {
        // super.setup(...arguments);
        this.actionService = useService('action')  // <----------------- ERROR
      }
    
      onClick() {
        console.log(this.value);
      }
    }
    
    ReferenceButtonWidget.description = _lt("Reference");
    ReferenceButtonWidget.supportedFieldTypes = ['reference'];
    ReferenceButtonWidget.template = 'iqba_document.reference_button_widget';
    
    
    const registry = require('web.field_registry_owl');
    
    registry.add('reference_button_widget', ReferenceButtonWidget)

If I comment the this.actionService = useService('action') line, my component renders ok.

If I pause the execution at that point, only these services are available:

browser debug console

What am I doing wrong? Thanks

For now I'm using this to call an action:

    this.__owl__.parent.parentWidget.do_action({
            type: 'ir.actions.act_window',
            res_model: this.value.model,
            res_id: this.value.res_id,
            views: [[false, 'form']],
            target: 'new'
          })

EDIT: I ended up using a workaround:


    this.__owl__.parent.parentWidget.do_action({
            type: 'ir.actions.act_window',
            res_model: this.props.value.model,
            res_id: this.props.value.res_id,
            views: [[false, 'form']],
            target: 'current'
          })

0 Answers0