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

I'm just starting with odoo v11 and I can't add javascript code to my new custom module, when adding the template with the following code it throws me an error loading the module:

                                        error: Some modules could not be started 

                                        Failed modules: ["timers.countdown_timer"]

here is my javascript code:

odoo.define('timers.countdown_timer', function(require) {
'use strict';

alert('Alert');
var timers = new instance.web.Model('timers.timer');
});

(the alert is showed but when closed it throws the error)


here is my code to add the template:

<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data>
<template id="timers_backend" name="rental_timer_backend" inherit_id="web.assets_backend">
<xpath expr="." position="inside">
<script type="text/javascript" src="/timers/static/src/js/countdown_timer.js"></script>
</xpath>
</template>
</data>
</odoo>
Avatar
Discard
Best Answer

Hi, problem is here

var timers = new instance.web.Model('timers.timer');

because Model as in version 9 is not, now to take the data from the model you can use rpc, for example:

var rpc = require('web.rpc');

       rpc.query({                   // your model such as 'timers.timer'
                  model: activeModel,                   //read data or another function
                  method: 'read',                   //args, first id of record, and array another args
                  args: [[activeRecordId], [activeField,]],
                 })
                 .then(function(result){                     //your code when data read
                   imageWidget._setValue(result[0][imageWidget.attrs.name]);
                  });
           

Avatar
Discard
Author

Thank you so much! it works!

Iam also working in odoo 11 JS could you please send me the working code of custom module which show js alert on button click

do search code on my

github.com/shurshilov