So i am using the custom script to add some client functionality to Sales Invoice.
And there are some behaviour i really don't understand. Here is the code:
cur_frm.cscript.custom_refresh = function(doc, dt, dn) { // Loop through Item var sales_invoice = locals[dt][dn]; var total_com = 0; var sales_person = wn.model.get("Sales Invoice"); cur_frm.set_value('sales_commission_value', -2); // This code works, it set the 'sales_commission_value' field to -2 wn.call({ method: "accounts.doctype.sales_invoice.sales_invoice.get_sale_commission", args: {}, callback: function(r) { console.log("Received value ", r); // Received r = {message:'1'} cur_frm.set_value('sales_commission_value', r.message); // This doesn't work, however, it does not set value of the field to 1 } }); }
As I printed out the two 'cur_frm' seems to be the same var, but one's value can be set (outside of wn.call) and one cannot ?
This happens to New Sale Invoice, initiated from an existing Delivery Note.
Does anyone have the explanation for this ? Thank you!
–
Note:
If you are posting an issue,
We should be able to replicate it at our end. So please give us as much information as you can. Please see it from the point of view of the person receiving the communication.
For sending images, use http://imgur.com or other similar services. Do not send images as attachments. Links are good. Same goes for any file you are going to send.
End of Note
—
You received this message because you are subscribed to the Google Groups "ERPNext Developer Forum" group.
When you loop, the calls get fired immediately (they are asynchronous, i.e. get fired on different threads), so the callbacks are all seeing different versions of cur_frm object and overwriting it.
If you have variable commission per item, you will have to write a server side functions to return all the commissions in one call, then set them all together.
On 25-May-2014, at 8:40 pm, Nguyen Do Le Bao <na...@gmail.com> wrote:
Hi,
So i am using the custom script to add some client functionality to Sales Invoice.
And there are some behaviour i really don't understand. Here is the code:
cur_frm.cscript.custom_refresh = function(doc, dt, dn) { // Loop through Item var sales_invoice = locals[dt][dn]; var total_com = 0; var sales_person = wn.model.get("Sales Invoice"); cur_frm.set_value('sales_commission_value', -2); // This code works, it set the 'sales_commission_value' field to -2 wn.call({ method: "accounts.doctype.sales_invoice.sales_invoice.get_sale_commission", args: {}, callback: function(r) { console.log("Received value ", r); // Received r = {message:'1'} cur_frm.set_value('sales_commission_value', r.message); // This doesn't work, however, it does not set value of the field to 1 } }); }
As I printed out the two 'cur_frm' seems to be the same var, but one's value can be set (outside of wn.call) and one cannot ?
This happens to New Sale Invoice, initiated from an existing Delivery Note.
Does anyone have the explanation for this ? Thank you!
–
Note:
If you are posting an issue,
We should be able to replicate it at our end. So please give us as much information as you can. Please see it from the point of view of the person receiving the communication.
For sending images, use http://imgur.com or other similar services. Do not send images as attachments. Links are good. Same goes for any file you are going to send.
End of Note
—
You received this message because you are subscribed to the Google Groups “ERPNext Developer Forum” group.
We should be able to replicate it at our end. So please give us as much information as you can. Please see it from the point of view of the person receiving the communication.
For sending images, use http://imgur.com or other similar services. Do not send images as attachments. Links are good. Same goes for any file you are going to send.
End of Note
—
You received this message because you are subscribed to the Google Groups "ERPNext Developer Forum" group.
I am really sorry the comment // Loop through item confused you. It should have been removed.
As you can see in the code, there are no loop involve. I am just simply use wn.call to call a function on Sales Invoice and set the value of cur_frm in the callback method.
But i will definitely take note what you said abt. looping the items, I need that as well.
Thank you!
On Monday, May 26, 2014 11:21:29 AM UTC+8, rushabh wrote:
When you loop, the calls get fired immediately (they are asynchronous, i.e. get fired on different threads), so the callbacks are all seeing different versions of cur_frm object and overwriting it.
If you have variable commission per item, you will have to write a server side functions to return all the commissions in one call, then set them all together.
On 25-May-2014, at 8:40 pm, Nguyen Do Le Bao <na...@gmail.com> wrote:
Hi,
So i am using the custom script to add some client functionality to Sales Invoice.
And there are some behaviour i really don't understand. Here is the code:
cur_frm.cscript.custom_refresh = function(doc, dt, dn) { // Loop through Item var sales_invoice = locals[dt][dn]; var total_com = 0; var sales_person = wn.model.get("Sales Invoice"); cur_frm.set_value('sales_commission_value', -2); // This code works, it set the 'sales_commission_value' field to -2 wn.call({ method: "accounts.doctype.sales_invoice.sales_invoice.get_sale_commission", args: {}, callback: function(r) { console.log("Received value ", r); // Received r = {message:'1'} cur_frm.set_value('sales_commission_value', r.message); // This doesn't work, however, it does not set value of the field to 1 } }); }
As I printed out the two 'cur_frm' seems to be the same var, but one's value can be set (outside of wn.call) and one cannot ?
This happens to New Sale Invoice, initiated from an existing Delivery Note.
Does anyone have the explanation for this ? Thank you!
–
Note:
If you are posting an issue,
We should be able to replicate it at our end. So please give us as much information as you can. Please see it from the point of view of the person receiving the communication.
For sending images, use http://imgur.com or other similar services. Do not send images as attachments. Links are good. Same goes for any file you are going to send.
End of Note
—
You received this message because you are subscribed to the Google Groups “ERPNext Developer Forum” group.
We should be able to replicate it at our end. So please give us as much information as you can. Please see it from the point of view of the person receiving the communication.
For sending images, use http://imgur.com or other similar services. Do not send images as attachments. Links are good. Same goes for any file you are going to send.
End of Note
—
You received this message because you are subscribed to the Google Groups "ERPNext Developer Forum" group.
On 26-May-2014, at 9:35 am, Nguyen Do Le Bao <na...@gmail.com> wrote:
I am really sorry the comment // Loop through item confused you. It should have been removed.
As you can see in the code, there are no loop involve. I am just simply use wn.call to call a function on Sales Invoice and set the value of cur_frm in the callback method.
But i will definitely take note what you said abt. looping the items, I need that as well.
Thank you!
On Monday, May 26, 2014 11:21:29 AM UTC+8, rushabh wrote:
When you loop, the calls get fired immediately (they are asynchronous, i.e. get fired on different threads), so the callbacks are all seeing different versions of cur_frm object and overwriting it.
If you have variable commission per item, you will have to write a server side functions to return all the commissions in one call, then set them all together.
On 25-May-2014, at 8:40 pm, Nguyen Do Le Bao <na...@gmail.com> wrote:
Hi,
So i am using the custom script to add some client functionality to Sales Invoice.
And there are some behaviour i really don't understand. Here is the code:
cur_frm.cscript.custom_refresh = function(doc, dt, dn) { // Loop through Item var sales_invoice = locals[dt][dn]; var total_com = 0; var sales_person = wn.model.get("Sales Invoice"); cur_frm.set_value('sales_commission_value', -2); // This code works, it set the 'sales_commission_value' field to -2 wn.call({ method: "accounts.doctype.sales_invoice.sales_invoice.get_sale_commission", args: {}, callback: function(r) { console.log("Received value ", r); // Received r = {message:'1'} cur_frm.set_value('sales_commission_value', r.message); // This doesn't work, however, it does not set value of the field to 1 } }); }
As I printed out the two 'cur_frm' seems to be the same var, but one's value can be set (outside of wn.call) and one cannot ?
This happens to New Sale Invoice, initiated from an existing Delivery Note.
Does anyone have the explanation for this ? Thank you!
–
Note:
If you are posting an issue,
We should be able to replicate it at our end. So please give us as much information as you can. Please see it from the point of view of the person receiving the communication.
For sending images, use http://imgur.com or other similar services. Do not send images as attachments. Links are good. Same goes for any file you are going to send.
End of Note
—
You received this message because you are subscribed to the Google Groups “ERPNext Developer Forum” group.
We should be able to replicate it at our end. So please give us as much information as you can. Please see it from the point of view of the person receiving the communication.
For sending images, use http://imgur.com or other similar services. Do not send images as attachments. Links are good. Same goes for any file you are going to send.
End of Note
—
You received this message because you are subscribed to the Google Groups “ERPNext Developer Forum” group.
We should be able to replicate it at our end. So please give us as much information as you can. Please see it from the point of view of the person receiving the communication.
For sending images, use http://imgur.com or other similar services. Do not send images as attachments. Links are good. Same goes for any file you are going to send.
End of Note
—
You received this message because you are subscribed to the Google Groups "ERPNext Developer Forum" group.
On 26-May-2014, at 9:35 am, Nguyen Do Le Bao <na...@gmail.com> wrote:
I am really sorry the comment // Loop through item confused you. It should have been removed.
As you can see in the code, there are no loop involve. I am just simply use wn.call to call a function on Sales Invoice and set the value of cur_frm in the callback method.
But i will definitely take note what you said abt. looping the items, I need that as well.
Thank you!
On Monday, May 26, 2014 11:21:29 AM UTC+8, rushabh wrote:
When you loop, the calls get fired immediately (they are asynchronous, i.e. get fired on different threads), so the callbacks are all seeing different versions of cur_frm object and overwriting it.
If you have variable commission per item, you will have to write a server side functions to return all the commissions in one call, then set them all together.
On 25-May-2014, at 8:40 pm, Nguyen Do Le Bao <na...@gmail.com> wrote:
Hi,
So i am using the custom script to add some client functionality to Sales Invoice.
And there are some behaviour i really don't understand. Here is the code:
cur_frm.cscript.custom_refresh = function(doc, dt, dn) { // Loop through Item var sales_invoice = locals[dt][dn]; var total_com = 0; var sales_person = wn.model.get("Sales Invoice"); cur_frm.set_value('sales_commission_value', -2); // This code works, it set the 'sales_commission_value' field to -2 wn.call({ method: "accounts.doctype.sales_invoice.sales_invoice.get_sale_commission", args: {}, callback: function(r) { console.log("Received value ", r); // Received r = {message:'1'} cur_frm.set_value('sales_commission_value', r.message); // This doesn't work, however, it does not set value of the field to 1 } }); }
As I printed out the two 'cur_frm' seems to be the same var, but one's value can be set (outside of wn.call) and one cannot ?
This happens to New Sale Invoice, initiated from an existing Delivery Note.
Does anyone have the explanation for this ? Thank you!
–
Note:
If you are posting an issue,
We should be able to replicate it at our end. So please give us as much information as you can. Please see it from the point of view of the person receiving the communication.
For sending images, use http://imgur.com or other similar services. Do not send images as attachments. Links are good. Same goes for any file you are going to send.
End of Note
—
You received this message because you are subscribed to the Google Groups “ERPNext Developer Forum” group.
We should be able to replicate it at our end. So please give us as much information as you can. Please see it from the point of view of the person receiving the communication.
For sending images, use http://imgur.com or other similar services. Do not send images as attachments. Links are good. Same goes for any file you are going to send.
End of Note
—
You received this message because you are subscribed to the Google Groups “ERPNext Developer Forum” group.
We should be able to replicate it at our end. So please give us as much information as you can. Please see it from the point of view of the person receiving the communication.
For sending images, use http://imgur.com or other similar services. Do not send images as attachments. Links are good. Same goes for any file you are going to send.
End of Note
—
You received this message because you are subscribed to the Google Groups "ERPNext Developer Forum" group.
On 26-May-2014, at 9:35 am, Nguyen Do Le Bao <na...@gmail.com> wrote:
I am really sorry the comment // Loop through item confused you. It should have been removed.
As you can see in the code, there are no loop involve. I am just simply use wn.call to call a function on Sales Invoice and set the value of cur_frm in the callback method.
But i will definitely take note what you said abt. looping the items, I need that as well.
Thank you!
On Monday, May 26, 2014 11:21:29 AM UTC+8, rushabh wrote:
When you loop, the calls get fired immediately (they are asynchronous, i.e. get fired on different threads), so the callbacks are all seeing different versions of cur_frm object and overwriting it.
If you have variable commission per item, you will have to write a server side functions to return all the commissions in one call, then set them all together.
On 25-May-2014, at 8:40 pm, Nguyen Do Le Bao <na...@gmail.com> wrote:
Hi,
So i am using the custom script to add some client functionality to Sales Invoice.
And there are some behaviour i really don't understand. Here is the code:
cur_frm.cscript.custom_refresh = function(doc, dt, dn) { // Loop through Item var sales_invoice = locals[dt][dn]; var total_com = 0; var sales_person = wn.model.get("Sales Invoice"); cur_frm.set_value('sales_commission_value', -2); // This code works, it set the 'sales_commission_value' field to -2 wn.call({ method: "accounts.doctype.sales_invoice.sales_invoice.get_sale_commission", args: {}, callback: function(r) { console.log("Received value ", r); // Received r = {message:'1'} cur_frm.set_value('sales_commission_value', r.message); // This doesn't work, however, it does not set value of the field to 1 } }); }
As I printed out the two 'cur_frm' seems to be the same var, but one's value can be set (outside of wn.call) and one cannot ?
This happens to New Sale Invoice, initiated from an existing Delivery Note.
Does anyone have the explanation for this ? Thank you!
–
Note:
If you are posting an issue,
We should be able to replicate it at our end. So please give us as much information as you can. Please see it from the point of view of the person receiving the communication.
For sending images, use http://imgur.com or other similar services. Do not send images as attachments. Links are good. Same goes for any file you are going to send.
End of Note
—
You received this message because you are subscribed to the Google Groups “ERPNext Developer Forum” group.
We should be able to replicate it at our end. So please give us as much information as you can. Please see it from the point of view of the person receiving the communication.
For sending images, use http://imgur.com or other similar services. Do not send images as attachments. Links are good. Same goes for any file you are going to send.
End of Note
—
You received this message because you are subscribed to the Google Groups “ERPNext Developer Forum” group.
We should be able to replicate it at our end. So please give us as much information as you can. Please see it from the point of view of the person receiving the communication.
For sending images, use http://imgur.com or other similar services. Do not send images as attachments. Links are good. Same goes for any file you are going to send.
End of Note
—
You received this message because you are subscribed to the Google Groups “ERPNext Developer Forum” group.
We should be able to replicate it at our end. So please give us as much information as you can. Please see it from the point of view of the person receiving the communication.
For sending images, use http://imgur.com or other similar services. Do not send images as attachments. Links are good. Same goes for any file you are going to send.
End of Note
—
You received this message because you are subscribed to the Google Groups "ERPNext Developer Forum" group.
Okay for testing purpose I removed that line as well, it is still not working.
The main wn.call to get_sale_commission is also ajax right ? Will the cur_frm variable inside the callback refer to the current form ?
I just wonder why it works when the Sale Invoice saved, only not working when make a new one…
–
Note:
If you are posting an issue,
We should be able to replicate it at our end. So please give us as much information as you can. Please see it from the point of view of the person receiving the communication.
For sending images, use http://imgur.com or other similar services. Do not send images as attachments. Links are good. Same goes for any file you are going to send.
On 27-May-2014, at 4:06 pm, Nguyen Do Le Bao na...@gmail.com wrote:
Okay for testing purpose I removed that line as well, it is still not working.
The main wn.call to get_sale_commission is also ajax right ? Will the cur_frm variable inside the callback refer to the current form ?
cur_frm is the same.
I just wonder why it works when the Sale Invoice saved, only not working when make a new one…
Thanks for this information. It would help if you give all the details upfront. I don’t think that should makes a difference though - there could be something else that is interfering.
–
Note:
If you are posting an issue,
We should be able to replicate it at our end. So please give us as much information as you can. Please see it from the point of view of the person receiving the communication.
For sending images, use http://imgur.com or other similar services. Do not send images as attachments. Links are good. Same goes for any file you are going to send.
We should be able to replicate it at our end. So please give us as much information as you can. Please see it from the point of view of the person receiving the communication.
For sending images, use http://imgur.com or other similar services. Do not send images as attachments. Links are good. Same goes for any file you are going to send.