How to make Update Stock as mandatory in sales invoices if there is NO DN made for a Sales Invoice?

Hi,

The POS invoice is a great thing since it lets people do 3 things with a single voucher like make an invoice, make a stock entry and also receive payments.

Now the problem is that the though there is a check in the system where the Sales invoices does not make a stock entry when a DN has already been made but there is a problem when we are directly making a sales invoice then there is no check to see if the update stock check is checked or not.

The problem is that many a times it has happened that people make sales invoices but forget or somehow uncheck the Update stock button and hence there is a difference in the stock. I was planning to get the system to check if the update stock is unchecked then the system should check all the rows and if there is a single row without DN then the system would not allow the SI to be submitted.

For this I have made the code file for custom server script but it does not seem to be working, can some one help me figure out a way to make the system check for this criteria.


The file I am using is here.

–

Note:

 

If you are posting an issue,

  1. 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.
  2. Paste your code at http://pastebin.com or http://gist.github.com and send only the URL via email
  3. 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.

    To unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer-forum+un…@googlegroups.com.

    To view this discussion on the web visit https://groups.google.com/d/msgid/erpnext-developer-forum/c2e56c78-3a9f-4205-8741-a050186cd0f8%40googlegroups.com.

    For more options, visit https://groups.google.com/d/optout.

Aditya, in line https://github.com/adityaduggal/custom_erpnext/blob/master/plugins/accounts/doctype/sales_invoice/sales_invoice.py#L38

You check if the value are None, but in same cases that the field are a boolean option (like Check), you can use if d.delivery_note

Because for Python None, False, "", '', 0, [], {} returns false in a boolean comparison.

Another tip:

In line https://github.com/adityaduggal/custom_erpnext/blob/master/plugins/accounts/doctype/sales_invoice/sales_invoice.py#L37 give preference to use getlist method e.g.

getlist(self.doclist, {"parentfield": "entries"})



2014-04-01 9:25 GMT-03:00 Aditya Duggal <ad...@gmail.com>:
Hi,

The POS invoice is a great thing since it lets people do 3 things with a single voucher like make an invoice, make a stock entry and also receive payments.

Now the problem is that the though there is a check in the system where the Sales invoices does not make a stock entry when a DN has already been made but there is a problem when we are directly making a sales invoice then there is no check to see if the update stock check is checked or not.

The problem is that many a times it has happened that people make sales invoices but forget or somehow uncheck the Update stock button and hence there is a difference in the stock. I was planning to get the system to check if the update stock is unchecked then the system should check all the rows and if there is a single row without DN then the system would not allow the SI to be submitted.

For this I have made the code file for custom server script but it does not seem to be working, can some one help me figure out a way to make the system check for this criteria.


The file I am using is here.

–

Note:



If you are posting an issue,

  1. 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.
  2. Paste your code at http://pastebin.com or http://gist.github.com and send only the URL via email
  3. 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.

    To unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer-forum+un…@googlegroups.com.

To view this discussion on the web visit https://groups.google.com/d/msgid/erpnext-developer-forum/c2e56c78-3a9f-4205-8741-a050186cd0f8%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.




--

Best Regards.

Maxwell Morais
Python Developer powered by Webnotes framework <3
+55 11 954329659


–

Note:

 

If you are posting an issue,

  1. 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.
  2. Paste your code at http://pastebin.com or http://gist.github.com and send only the URL via email
  3. 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.

    To unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer-forum+un…@googlegroups.com.

    To view this discussion on the web visit https://groups.google.com/d/msgid/erpnext-developer-forum/CABK1YkNUMSzzcvM_znHWS_pch5G7As4%3DNmVNXiQ0U3CGUQcP1g%40mail.gmail.com.

    For more options, visit https://groups.google.com/d/optout.

Alias use if not d.delivery_note for line 38



2014-04-01 9:41 GMT-03:00 Maxwell Morais <ma...@gmail.com>:

Aditya, in line https://github.com/adityaduggal/custom_erpnext/blob/master/plugins/accounts/doctype/sales_invoice/sales_invoice.py#L38

You check if the value are None, but in same cases that the field are a boolean option (like Check), you can use if d.delivery_note

Because for Python None, False, "", '', 0, [], {} returns false in a boolean comparison.

Another tip:

In line https://github.com/adityaduggal/custom_erpnext/blob/master/plugins/accounts/doctype/sales_invoice/sales_invoice.py#L37 give preference to use getlist method e.g.

getlist(self.doclist, {"parentfield": "entries"})



2014-04-01 9:25 GMT-03:00 Aditya Duggal <ad...@gmail.com>:

Hi,

The POS invoice is a great thing since it lets people do 3 things with a single voucher like make an invoice, make a stock entry and also receive payments.

Now the problem is that the though there is a check in the system where the Sales invoices does not make a stock entry when a DN has already been made but there is a problem when we are directly making a sales invoice then there is no check to see if the update stock check is checked or not.

The problem is that many a times it has happened that people make sales invoices but forget or somehow uncheck the Update stock button and hence there is a difference in the stock. I was planning to get the system to check if the update stock is unchecked then the system should check all the rows and if there is a single row without DN then the system would not allow the SI to be submitted.

For this I have made the code file for custom server script but it does not seem to be working, can some one help me figure out a way to make the system check for this criteria.


The file I am using is here.

–

Note:



If you are posting an issue,

  1. 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.
  2. Paste your code at http://pastebin.com or http://gist.github.com and send only the URL via email
  3. 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.

    To unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer-forum+un…@googlegroups.com.

To view this discussion on the web visit https://groups.google.com/d/msgid/erpnext-developer-forum/c2e56c78-3a9f-4205-8741-a050186cd0f8%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.




--

Best Regards.

Maxwell Morais
Python Developer powered by Webnotes framework <3




--

Best Regards.

Maxwell Morais
Python Developer powered by Webnotes framework <3
+55 11 954329659


–

Note:

 

If you are posting an issue,

  1. 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.
  2. Paste your code at http://pastebin.com or http://gist.github.com and send only the URL via email
  3. 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.

    To unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer-forum+un…@googlegroups.com.

    To view this discussion on the web visit https://groups.google.com/d/msgid/erpnext-developer-forum/CABK1YkOrG7cKd5Y2sz36TY6%3DHGsUwYTW-_tBqw6GBLMMhA6udg%40mail.gmail.com.

    For more options, visit https://groups.google.com/d/optout.
HI Maxwell,

I have tried the suggested changes but still I am able to submit Sales Invoices where there are no DN and update stock is unchecked. It seems that the validation is not happening at all.

On Tuesday, April 1, 2014 6:12:37 PM UTC+5:30, Maxwell wrote:

Alias use if not d.delivery_note for line 38



2014-04-01 9:41 GMT-03:00 Maxwell Morais <ma...@gmail.com>:

Aditya, in line https://github.com/adityaduggal/custom_erpnext/blob/master/plugins/accounts/doctype/sales_invoice/sales_invoice.py#L38

You check if the value are None, but in same cases that the field are a boolean option (like Check), you can use if d.delivery_note

Because for Python None, False, "", '', 0, [], {} returns false in a boolean comparison.

Another tip:

In line https://github.com/adityaduggal/custom_erpnext/blob/master/plugins/accounts/doctype/sales_invoice/sales_invoice.py#L37 give preference to use getlist method e.g.

getlist(self.doclist, {"parentfield": "entries"})



2014-04-01 9:25 GMT-03:00 Aditya Duggal <ad...@gmail.com>:

Hi,

The POS invoice is a great thing since it lets people do 3 things with a single voucher like make an invoice, make a stock entry and also receive payments.

Now the problem is that the though there is a check in the system where the Sales invoices does not make a stock entry when a DN has already been made but there is a problem when we are directly making a sales invoice then there is no check to see if the update stock check is checked or not.

The problem is that many a times it has happened that people make sales invoices but forget or somehow uncheck the Update stock button and hence there is a difference in the stock. I was planning to get the system to check if the update stock is unchecked then the system should check all the rows and if there is a single row without DN then the system would not allow the SI to be submitted.

For this I have made the code file for custom server script but it does not seem to be working, can some one help me figure out a way to make the system check for this criteria.


The file I am using is here.

–

Note:

 

If you are posting an issue,

  1. 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.
  2. Paste your code at http://pastebin.com or http://gist.github.com and send only the URL via email
  3. 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.

    To unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer-forum+un…@googlegroups.com.

To view this discussion on the web visit https://groups.google.com/d/msgid/erpnext-developer-forum/c2e56c78-3a9f-4205-8741-a050186cd0f8%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.




--

Best Regards.

Maxwell Morais
Python Developer powered by Webnotes framework <3




--

Best Regards.

Maxwell Morais
Python Developer powered by Webnotes framework <3
+55 11 954329659


–

Note:

 

If you are posting an issue,

  1. 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.
  2. Paste your code at http://pastebin.com or http://gist.github.com and send only the URL via email
  3. 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.

    To unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer-forum+un…@googlegroups.com.

    To view this discussion on the web visit https://groups.google.com/d/msgid/erpnext-developer-forum/4d7e0d4b-8cd6-4fa3-b64d-e55debdfb44d%40googlegroups.com.

    For more options, visit https://groups.google.com/d/optout.
Alternative is to create a custom client-side script. I did the following to ensure a particular user (or user role) must have the the update stock ticked:

//fix the "update inventory" field value based on user
    if(user=="na...@domain.com"){
    doc.update_stock = 1;
    }

}

I also hid the field update_stock so that users cannot check or uncheck it. And lock the user to a particular warehouse.

You could alternatively also script it so that it just checks if the update_stock is ticked or not based on whatever condition fits your needs (user, user roles, if line items have no DN value, etc.) 

Hope that helps.


On Tuesday, April 1, 2014 9:22:49 PM UTC+8, Aditya Duggal wrote:
HI Maxwell,

I have tried the suggested changes but still I am able to submit Sales Invoices where there are no DN and update stock is unchecked. It seems that the validation is not happening at all.

On Tuesday, April 1, 2014 6:12:37 PM UTC+5:30, Maxwell wrote:

Alias use if not d.delivery_note for line 38



2014-04-01 9:41 GMT-03:00 Maxwell Morais <ma...@gmail.com>:

Aditya, in line https://github.com/adityaduggal/custom_erpnext/blob/master/plugins/accounts/doctype/sales_invoice/sales_invoice.py#L38

You check if the value are None, but in same cases that the field are a boolean option (like Check), you can use if d.delivery_note

Because for Python None, False, "", '', 0, [], {} returns false in a boolean comparison.

Another tip:

In line https://github.com/adityaduggal/custom_erpnext/blob/master/plugins/accounts/doctype/sales_invoice/sales_invoice.py#L37 give preference to use getlist method e.g.

getlist(self.doclist, {"parentfield": "entries"})



2014-04-01 9:25 GMT-03:00 Aditya Duggal <ad...@gmail.com>:

Hi,

The POS invoice is a great thing since it lets people do 3 things with a single voucher like make an invoice, make a stock entry and also receive payments.

Now the problem is that the though there is a check in the system where the Sales invoices does not make a stock entry when a DN has already been made but there is a problem when we are directly making a sales invoice then there is no check to see if the update stock check is checked or not.

The problem is that many a times it has happened that people make sales invoices but forget or somehow uncheck the Update stock button and hence there is a difference in the stock. I was planning to get the system to check if the update stock is unchecked then the system should check all the rows and if there is a single row without DN then the system would not allow the SI to be submitted.

For this I have made the code file for custom server script but it does not seem to be working, can some one help me figure out a way to make the system check for this criteria.


The file I am using is here.

–

Note:

 

If you are posting an issue,

  1. 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.
  2. Paste your code at http://pastebin.com or http://gist.github.com and send only the URL via email
  3. 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.

    To unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer-forum+un…@googlegroups.com.

To view this discussion on the web visit https://groups.google.com/d/msgid/erpnext-developer-forum/c2e56c78-3a9f-4205-8741-a050186cd0f8%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.




--

Best Regards.

Maxwell Morais
Python Developer powered by Webnotes framework <3




--

Best Regards.

Maxwell Morais
Python Developer powered by Webnotes framework <3
+55 11 954329659


–

Note:

 

If you are posting an issue,

  1. 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.
  2. Paste your code at http://pastebin.com or http://gist.github.com and send only the URL via email
  3. 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.

    To unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer-forum+un…@googlegroups.com.

    To view this discussion on the web visit https://groups.google.com/d/msgid/erpnext-developer-forum/ef9a4ca0-1dee-47a7-9c26-cde76d1465df%40googlegroups.com.

    For more options, visit https://groups.google.com/d/optout.
Thanks you very much for the help @lxnow and maxwell

I have kind of quit making the custom script (client and server) for this issue and have tried to implement the same by using the existing structure.

What I have done is this:
  1. I have hidden the check box for Stock Update
  2. Now when we click on the New Sales Invoice by default the POS settings punch in where they mark the Stock Update button by default and since this field is hidden it remains marked.
  3. For normal invoices made from DN the POS settings would not be called and hence the stock update box would remain unchecked.
The only downside to this simple solution is that when people would click on new invoice and then try to pull Delivery notes then they would not be able to make the invoices since the update stock box would be checked and the system would not let them submit the Invoice.

I hope this is a good solution to follow and I hope this is fool proof atleast with regards to the case when people used to forget to check the update stock button.

If anyone can find a problem with this solution then do let me know about the same.

On Thursday, April 3, 2014 8:11:10 PM UTC+5:30, lxnow wrote:
Alternative is to create a custom client-side script. I did the following to ensure a particular user (or user role) must have the the update stock ticked:

//fix the "update inventory" field value based on user
    if(user=="na...@domain.com"){
    doc.update_stock = 1;
    }

}

I also hid the field update_stock so that users cannot check or uncheck it. And lock the user to a particular warehouse.

You could alternatively also script it so that it just checks if the update_stock is ticked or not based on whatever condition fits your needs (user, user roles, if line items have no DN value, etc.) 

Hope that helps.


On Tuesday, April 1, 2014 9:22:49 PM UTC+8, Aditya Duggal wrote:
HI Maxwell,

I have tried the suggested changes but still I am able to submit Sales Invoices where there are no DN and update stock is unchecked. It seems that the validation is not happening at all.

On Tuesday, April 1, 2014 6:12:37 PM UTC+5:30, Maxwell wrote:

Alias use if not d.delivery_note for line 38



2014-04-01 9:41 GMT-03:00 Maxwell Morais <ma...@gmail.com>:

Aditya, in line https://github.com/adityaduggal/custom_erpnext/blob/master/plugins/accounts/doctype/sales_invoice/sales_invoice.py#L38

You check if the value are None, but in same cases that the field are a boolean option (like Check), you can use if d.delivery_note

Because for Python None, False, "", '', 0, [], {} returns false in a boolean comparison.

Another tip:

In line https://github.com/adityaduggal/custom_erpnext/blob/master/plugins/accounts/doctype/sales_invoice/sales_invoice.py#L37 give preference to use getlist method e.g.

getlist(self.doclist, {"parentfield": "entries"})



2014-04-01 9:25 GMT-03:00 Aditya Duggal <ad...@gmail.com>:

Hi,

The POS invoice is a great thing since it lets people do 3 things with a single voucher like make an invoice, make a stock entry and also receive payments.

Now the problem is that the though there is a check in the system where the Sales invoices does not make a stock entry when a DN has already been made but there is a problem when we are directly making a sales invoice then there is no check to see if the update stock check is checked or not.

The problem is that many a times it has happened that people make sales invoices but forget or somehow uncheck the Update stock button and hence there is a difference in the stock. I was planning to get the system to check if the update stock is unchecked then the system should check all the rows and if there is a single row without DN then the system would not allow the SI to be submitted.

For this I have made the code file for custom server script but it does not seem to be working, can some one help me figure out a way to make the system check for this criteria.


The file I am using is here.

–

Note:

 

If you are posting an issue,

  1. 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.
  2. Paste your code at http://pastebin.com or http://gist.github.com and send only the URL via email
  3. 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.

    To unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer-forum+un…@googlegroups.com.

To view this discussion on the web visit https://groups.google.com/d/msgid/erpnext-developer-forum/c2e56c78-3a9f-4205-8741-a050186cd0f8%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.




--

Best Regards.

Maxwell Morais
Python Developer powered by Webnotes framework <3




--

Best Regards.

Maxwell Morais
Python Developer powered by Webnotes framework <3
+55 11 954329659


–

Note:

 

If you are posting an issue,

  1. 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.
  2. Paste your code at http://pastebin.com or http://gist.github.com and send only the URL via email
  3. 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.

    To unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer-forum+un…@googlegroups.com.

    To view this discussion on the web visit https://groups.google.com/d/msgid/erpnext-developer-forum/bc7fef94-ceba-4c9c-9529-9a6b1996e5c0%40googlegroups.com.

    For more options, visit https://groups.google.com/d/optout.
1 Like