Перейти к содержимому
Меню
Чтобы взаимодействовать с сообществом, необходимо зарегистрироваться.
Этот вопрос был отмечен
2 Ответы
22410 Представления

My problem is that javascript does not find my templates.

The templates are in static/src/xml/status_templates.xml.

I added them to my manifest file with the full path name and *.  ('qweb': ['static/src/xml/*.xml'],)

The templates are:

<?xml version="1.0" encoding="UTF-8"?>
<templates xml:space="preserve">
    <t t-name="tabla_stock_notification.subscription_form">
        <div class="tabla_stock_notifications">
            <form method="post" id="tabla_stock_subscription" enctype="multipart/form-data">
                <div class="input-group">
                    <input type="email" class="form-control" required="required" aria-describedby="tabla-stock-subscription"/>
                    <div class="input-group-append">
                        <button class="btn btn-warning" id="subscribe_stock" type="submit"><i class="fa fa-envelope-o" role="img" aria-label="Subscribe"/></button>
                    </div>
                    <span class="stock_procurement_date"/>
                </div>
            </form>
        </div>
    </t>

The JS

odoo.define('tabla_stock_notification.stock_notification', function(require) {
    'use strict';

var core = require('web.core');
var config = require('web.config');
var publicWidget = require('web.public.widget');
var ajax = require('web.ajax');

var QWeb = core.qweb;

publicWidget.registry.StockNotifications = publicWidget.Widget.extend({
    selector: '#product_details',
    events: {
        'click #subscribe_stock': '_onGetCheckData',
    },

    init: function() {
        console.log('Konstruktor');
        var product_id = $('.product_id').val();
        var stockDiv = $('.tabla_stock_placeholder')
        console.log('Konstruktor, product ID ' + product_id);
        if (product_id != '') {
            ajax.jsonRpc('/stock-status', 'call', {'product_id': parseInt(product_id)}).then(function (data) {
                console.log('Calling stock status and gotten data: ' + data);
                let stock_data = JSON.parse(data);
                if (stock_data.hasOwnProperty('show')) {
                    if (stock_data['show'] == 'form') {
                        stockDiv = $(QWeb.render('tabla_stock_notification.subscription_form', {}));
                    } else if (stock_data['show'] == 'confirm') {
                        stockDiv = $(QWeb.render('tabla_stock_notification.confirm_subscription'));
                    } else if (stock_data['show'] == 'message') {
                        stockDiv = $(QWeb.render('tabla_stock_notification.stock_notification'));
                    };
                };



            });
        };
    },

I'm new to JS widgets. I've tried all that I could find and it never worked. I looked at other modules and I cannot figure out why mine does not work.

I'm just getting error:

Error: QWeb2: Template 'tabla_stock_notification.subscription_form' not found




Аватар
Отменить
Автор Лучший ответ

I had to add:

xmlDependencies: ['/tabla_stock_notification/static/src/xml/status_templates.xml'],

after the selector and it worked.


Аватар
Отменить

I had the same problem, it worked using your advice on Odoo12

Thank you very much

Автор

no problem, glad it helped you!

It's working fine for me (odoov14)

Лучший ответ

for odoo 15 please use downbelow snipt in your manifest.py file
'assets': {
'web.assets_backend': [
'module_name/static/src/js/your_js.js',
],
'web.assets_qweb': [
'module_name/static/src/xml/your_xml.xml',
],
},

please upvote the answer if is helps you Thanks.
Аватар
Отменить

It worked for me, thanks!

Related Posts Ответы Просмотры Активность
0
янв. 22
223
0
мая 23
3236
1
янв. 23
8031
1
дек. 20
7574
1
июн. 24
3470