Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[17.0] Uncaught TypeError: odoo.define is not a function when load Owl Component #166313

Closed
1 of 4 tasks
chaule97 opened this issue May 22, 2024 · 2 comments
Closed
1 of 4 tasks

Comments

@chaule97
Copy link

Odoo Version

  • 15.0
  • 16.0
  • 17.0
  • Other (specify)

Steps to Reproduce

Steps to reproduce:
Fresh install. Install postgresql and do initdb.
Install Odoo 17, create new module, developed model and view, components

Current behavior: my Owl Framework can't run, it's my code

manifest.py

{
    'name': "student",

    'summary': "learn",


    'author': "Chau",
    'website': "https://www.yourcompany.com",

    # Categories can be used to filter modules in modules listing
    # Check https://github.com/odoo/odoo/blob/15.0/odoo/addons/base/data/ir_module_category_data.xml
    # for the full list
    'category': 'Uncategorized',
    'version': '0.1',

    # any module necessary for this one to work correctly
    'depends': ['base'],
    'data': [
        'security/ir.model.access.csv',
        'data/student_data.xml',
        'views/student_student_view.xml',
        'views/student_student_menu.xml',
    ],
    'sequence': -1,
    'installable': True,
    'application': True,
    'assets': {
        'web.assets_backend': [
            'student/static/src/components/*/*.js',
            'student/static/src/components/*/*.scss',
            'student/static/src/components/*/*.xml',
        ],
    },
}

static/src/component/student_list/student_list.js

/** @odoo-module **/
import { Component, useState } from "@odoo/owl";
import { registry } from "@web/core/registry";

export class OwlStudentList extends Component {
    setup() {
        this.state = useState({value: 1});
    }
}

OwlStudentList.template = 'student.StudentList'

registry.category('actions').add('owl.action_student_list_js', OwlStudentList);
<?xml version="1.0" encoding="UTF-8"?>
<templates xml:space="preserve">
    <t t-name="student.StudentList" owl="1">
        <div class="student-list-container">
            <div class="container-fluid mt-2">
                <div class="row">
                    <div class="col-lg-6">
                        <button class="btn btn-primary">New</button>
                    </div>

                    <div class="col-lg-6">
                        <div class="input-group">
                            <input type="text" class="form-control" placeholder="Search here..."/>
                            <button class="btn btn-outline-primary">Search</button>
                        </div>
                    </div>
                </div>
            </div>

            <div class="row mt-2">
                <div class="col">
                    <table class="table table-striped table-hover border">
                        <thead>
                            <tr>
                                <th scope="col">Name</th>
                                <th scope="col">Student ID</th>
                                <th scope="col">Class</th>
                                <th scope="col">Current GPA</th>
                                <th scope="col">Current Classification</th>
                                <th scope="col"></th>
                            </tr>
                        </thead>

                        <tbody>
                            <tr>
                                <td scope="col">Nguyen Van A</td>
                                <td scope="col">ABCDEF</td>
                                <td scope="col">Odoo Dev Basic 01</td>
                                <td scope="col">7.00</td>
                                <td scope="col">Good</td>
                                <td>
                                    <button class="btn btn-success me-2">Edit</button>
                                    <button class="btn btn-danger">Delete</button>
                                </td>
                            </tr>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </t>
</templates>

student_student_menu.xml

<?xml version="1.0" encoding="utf-8"?>
<odoo>
    <record model="ir.actions.act_window" id="action_student_student">
        <field name="name">Students</field>
        <field name="res_model">student.student</field>
        <field name="view_mode">tree,form</field>
    </record>

    <record model="ir.actions.client" id="action_student_owl_student">
        <field name="name">Owl Students</field>
        <field name="tag">owl.action_student_list_js</field>
    </record>

    <menuitem
        id="menu_student"
        name="Student"
    />

    <menuitem
        id="menu_student_student"
        parent="menu_student"
        name="Student"
        action="action_student_student"
    />

    <menuitem
        id="menu_student_owl_student"
        parent="menu_student"
        name="OWL Student"
        action="action_student_owl_student"
    />
</odoo>

and this is my error:

Uncaught TypeError: odoo.define is not a function
    <anonymous> http://localhost:8069/web/assets/debug/web.assets_web.js:6
/**************************************************************************
*  Filepath: /student/static/src/components/student_list/student_list.js  *
*  Lines: 20                                                              *
**************************************************************************/
odoo.define('@student/components/student_list/student_list', ['@odoo/owl', '@web/core/registry'], function (require) {
'use strict';
let __exports = {};
/** @odoo-module **/
const { Component, useState } = require("@odoo/owl");
const { registry } = require("@web/core/registry");

// import { OwlStudentAdd } from "../student_add/student_add";

const OwlStudentList = __exports.OwlStudentList = class OwlStudentList extends Component {
    setup() {
        this.state = useState({value: 1});
    }
}

OwlStudentList.template = 'student.StudentList'

registry.category('actions').add('owl.action_student_list_js', OwlStudentList);
return __exports;
});
;

/***********************************************
*  Filepath: /web/static/src/module_loader.js  *
*  Lines: 226                               

I think component is loaded before odoo module is initializederror

Expected behavior: how fix this error

Log Output

No response

Support Ticket

No response

@arv-aravind
Copy link

arv-aravind commented Jun 15, 2024

How did you resolve the issue bro?

@chaule97
Copy link
Author

How did you resolve the issue bro?

in manifest.py, append 'base_setup' into depends

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants