Custom Server side script

Hello everyone,

I have a problem that I am having difficulties to solve. The problem is as follow: as long as 'Customer Named By' is either by 'customer name' or 'naming series' (under the selling settings), I would like to change that in order to use a field, for example 'Customer Named By' customer id.


I tried the following code in the custom script for the customer form but it did not work:

       def validate_owners_id(self):

            if self.doc.owners_id:

                duplicate = webnotes.conn.sql("""select owners_id from tabCustomer where owners_di = %s""", (self.doc.owners_id)

                if duplicate:

                    msgprint("Owners ID: %s already used in Customer database" %(self.doc.owners_id, raise_exception = 1)


Can anyone give me a hint or a suggestion and/or the right procedure on how to solve this problem?

Kind regards,

Kat.







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.

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

You have to overwrite make_autoname function, to create name based on other field. To validate duplicate owner id before naming, you should call the validate function from make_autoname.
And regarding validate function you have written, it's looking ok, just check the typo for owner_id in mysql query. Also correct msgprint syntax or use webnotes.throw function.

On 19 Dec 2013 13:36, "Kat" <py...@gmail.com> wrote:
Hello everyone,

I have a problem that I am having difficulties to solve. The problem is as follow: as long as 'Customer Named By' is either by 'customer name' or 'naming series' (under the selling settings), I would like to change that in order to use a field, for example 'Customer Named By' customer id.


I tried the following code in the custom script for the customer form but it did not work:

def validate_owners_id(self):

if self.doc.owners_id:

duplicate = webnotes.conn.sql("""select owners_id from tabCustomer where owners_di = %s""", (self.doc.owners_id)

if duplicate:

msgprint("Owners ID: %s already used in Customer database" %(self.doc.owners_id, raise_exception = 1)


Can anyone give me a hint or a suggestion and/or the right procedure on how to solve this problem?

Kind regards,

Kat.







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.

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



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.

    For more options, visit https://groups.google.com/groups/opt_out.
Thank you Nabin,

I will follow your suggestions and will see what the result will be.

On Friday, December 20, 2013 6:32:48 AM UTC+2, Nabin Hait wrote:

You have to overwrite make_autoname function,  to create name based on other field. To validate duplicate owner id before naming, you should call the validate function from make_autoname.
And regarding validate function you have written, it's looking ok, just check the typo for owner_id in mysql query. Also correct msgprint syntax or use webnotes.throw function.

On 19 Dec 2013 13:36, "Kat" <py...@gmail.com> wrote:
Hello everyone,

I have a problem that I am having difficulties to solve. The problem is as follow: as long as 'Customer Named By' is either by 'customer name' or 'naming series' (under the selling settings), I would like to change that in order to use a field, for example 'Customer Named By' customer id.


I tried the following code in the custom script for the customer form but it did not work:

       def validate_owners_id(self):

            if self.doc.owners_id:

                duplicate = webnotes.conn.sql("""select owners_id from tabCustomer where owners_di = %s""", (self.doc.owners_id)

                if duplicate:

                    msgprint("Owners ID: %s already used in Customer database" %(self.doc.owners_id, raise_exception = 1)


Can anyone give me a hint or a suggestion and/or the right procedure on how to solve this problem?

Kind regards,

Kat.







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.

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



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.

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