This question has been flagged

 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>

Avatar
Discard
Best Answer

Hi,

Hope you are doing well.

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

var Partners = new Model('res.partner')

/*render template passing partner values*/

    render: function(){

    var self = this;

    var partners = Partners.query(['name', 'image'])

    .filter([['active', '=', true]])

    .all().then(function(result) {

    self.$el.append(QWeb.render("PartnerTemplate", {partners: result}));

    });

    },


Template

<t t-name="PartnerTemplate">

<tr t-foreach="partners" t-as="partner">

<t t-esc="partner.name"></t>

</tr>

</t>


let me know if you need custom module which i done.

you can share you mail , if you need custom module. which is in version 10.

Regards,

Silvestar


Avatar
Discard
Author

Hello my friend. This isn't for report it's for a custom interface.

Hi sandro,

I have updated my answer. let me know if it helps.

Author

Thank you Silverstar, i will try your code and for sure no worries to share my contact. Add at skype PROJETATY.SCA

Author

Thank you Silverstar.. thank you so much! Your hint and code solve my problem. My best regards,

Nice to hear sandro.