Odoo Help

Welcome!

This community 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.

0

Why should I use a for statement in this javascript?

By
Pascal Tremblay
on 1/29/16, 11:16 AM 472 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--
1312
| 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);
                }


Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

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