تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
1 الرد
2598 أدوات العرض

Hello everyone,

I am currently working on an Odoo 16 project and I am facing some difficulties integrating custom JavaScript code into my Odoo module.

Here's what I've tried so far:

  1. Declared my JavaScript file in the manifest file under the 'assets' key.
jsonCopy code'assets': {
    'web.assets_frontend': [
        'my_module/static/src/js/my_script.js',
    ],
}
  1. Created a JavaScript file with Odoo's module system.
javascriptCopy codeodoo.define("my_module.my_script", function (require) {
    "use strict";
    // My JavaScript logic here
});
  1. Attempted to include the script directly into my XML view, which gave me an error.
xmlCopy code
  

The above approach resulted in a "UncaughtPromiseError > InvalidButtonParamsError" error.

Questions:

  1. What is the correct way to include and execute custom JavaScript code in Odoo 16?
  2. How can I ensure that my JavaScript code is loaded and executed only on the specific view where I need it?
  3. Are there any examples or documentation I should be aware of?

Thank you for your time and assistance.


الصورة الرمزية
إهمال
أفضل إجابة

Hi,
Refer to this Odoo Javascript documentation it will help you to integrate Javascript in odoo16
https://www.odoo.com/documentation/16.0/developer/reference/frontend/javascript_reference.html

Hope it helps

الصورة الرمزية
إهمال
المنشورات ذات الصلة الردود أدوات العرض النشاط
1
أبريل 24
1617
0
يناير 24
1317
2
أبريل 23
4687
2
يناير 23
7203
get the model in js تم الحل
3
مارس 25
3112