Odoo Help

0

Why should I use a for statement in this javascript?

By
Pascal Tremblay
on 1/29/16, 11:16 AM 562 views

Hello guys,

I really don't understand this new problem in Javascript.

I'm in the javascript function update_payment_summary in the point of sale.


This one works well :

var currentOrder = this.pos.get('selectedOrder');
var plines = currentOrder.get('paymentLines').models;

for (var i = 0; i < plines.length; i++) {
    var message = plines[i].get_type();
    console.log('payment_method ' + message +' et le i est : ' + i);
}

The log displays :  "payment_method cash et le i est : 0"


This one doesn't work ??????? :

var currentOrder = this.pos.get('selectedOrder');
var plines = currentOrder.get('paymentLines').models;

var i = 0;
var message = plines[i].get_type();
console.log('payment_method ' + message +' et le i est : ' + i); }

I get this error :  TypeError: plines[i] is undefined



I'm crazy or what?

Thanks to help

0

Pascal Tremblay

--Pascal Tremblay--
1512
| 5 2 7
Alma, Canada
--Pascal Tremblay--


Pascal Tremblay
On 1/29/16, 8:05 PM

I have found my error.

When the point of sale load at the beginning, the function update_payment_summary is called.

This first time that the function is called, there is no paymentlines.

So my plines variable is undefined.

The using of the for statement is not the problem.

This one works :

                if (plines.length > 0) {
                           var i = 0;  
                      var mes = plines[i].get_type();
                       console.log('payment_method' + mes +'et le i est : ' + i);
                }


About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

Register

Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)

Stats

Asked: 1/29/16, 11:16 AM
Seen: 562 times
Last updated: 1/29/16, 8:05 PM