Hello, my friends, how you all doing? Hope everybody doing good!
Fellows, I am in deep trouble may somebody can save my skin (at the truth). The issue follows below:
My problem is to set the returning value from python method to js and create the object to be rendered in template QWeb.
My js file is not processing the query in the right step to populate the object and pass the value for <t for-each>.
There are 3 steps being executed to render the interface:
1) Read the js class;
2) Read the vars and load its values. In case of array prepare the number of rows to be rendered;
3) Render the data to the interface;
My js code is just populating the values in the last step and sure throws the error There is no value to for each.
My sample coding goes below:
odoo.define('my_module_name.model_name', function(require) {
"use strict";
var Class = require('web.Class');
var Widget = require('web.Widget');
var session = require('web.session');
var Model = require('web.Model');
var core = require('web.core');
var utils = require('web.utils');
var data = require('web.data');
var _t = core._t;
var _lt = core._lt;
var QWeb = core.qweb;
var invs;
var ClassB = ClassC.extend({
template:"ClassB",
init: function(parent, invoices) {
this._super(parent);
this.invoices = invoices;
},
});
var ClassA = Widget.extend({
template:"ClassA",
start: function() {
var model = new Model("nfses.capinha");
model.call("getInvoices", {context: new data.CompoundContext()}).then(function(result){
invs = result;
console.log(invs);//print values just on last step of processing, it means after trhows the error.
});
var invoices = new ClassB(this, invs);
invoices.appendTo(this.$el);
//for test proposal this works fine because are being loaded in the second step as said before:
//invs = [{'id':1,'number':1000,'customer_id':23,'value':10000.00}]
//But to retrieve from model.call nope
},
});
core.action_registry.add("invoices", ClassB);
});
===========================================================================
<t t-name="ClassB">
<div class="i-am-b">
<t t-foreach="widget.invoices" t-as="invoice">
<span class="row">
<!-- simple call to retrive some value -->
Value: <t t-esc="invoice.value"/>
</span>
<br/>
</t>
</div>
</t>