Skip to content

Commit

Permalink
Merge pull request #49 from Alchez/fix-bom-autoname
Browse files Browse the repository at this point in the history
  • Loading branch information
vjFaLk authored Feb 15, 2022
2 parents 51a8589 + 62f4028 commit 410cb31
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion erpnext/manufacturing/doctype/bom/bom.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,20 @@ def autoname(self):
else:
idx = 1

self.name = 'BOM-' + self.item + ('-%.3i' % idx)
prefix = self.doctype
suffix = "%.3i" % idx # convert index to string (1 -> "001")
bom_name = f"{prefix}-{self.item}-{suffix}"

if len(bom_name) <= 140:
self.name = bom_name
else:
# since max characters for name is 140, remove enough characters from the
# item name to fit the prefix, suffix and the separators
truncated_length = 140 - (len(prefix) + len(suffix) + 2)
truncated_item_name = self.item[:truncated_length]
# if a partial word is found after truncate, remove the extra characters
truncated_item_name = truncated_item_name.rsplit(" ", 1)[0]
self.name = f"{prefix}-{truncated_item_name}-{suffix}"

def validate(self):
self.route = frappe.scrub(self.name).replace('_', '-')
Expand Down

0 comments on commit 410cb31

Please sign in to comment.