Last active
February 18, 2020 13:41
-
-
Save nabinhait/5294657 to your computer and use it in GitHub Desktop.
set item code based on incremental alphanumeric number
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def custom_validate(self): | |
# serial_no is a custom field in item group which can be any alphanumeric number | |
serial_no = webnotes.conn.get_value("Item Group", self.doc.item_group, "serial_no") | |
#increment serial_no value and assign to item_code | |
next_serial_no = self.next_string(serial_no) | |
self.doc.item_code = next_serial_no | |
# update incremented serial_no in item group | |
webnotes.conn.set_value("Item Group", self.doc.item_group, "serial_no", next_serial_no) | |
def next_string(self, s): | |
strip_zs = s.rstrip('z') | |
if strip_zs: | |
return strip_zs[:-1] + chr(ord(strip_zs[-1]) + 1) + 'a' * (len(s) - len(strip_zs)) | |
else: | |
return 'a' * (len(s) + 1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment