|
|
@ -15,13 +15,21 @@ form_grid_templates = { |
|
|
|
|
|
|
|
class BOM(Document): |
|
|
|
def autoname(self): |
|
|
|
last_name = frappe.db.sql("""select max(name) from `tabBOM` |
|
|
|
where name like "BOM/{0}/%%" and item=%s |
|
|
|
""".format(frappe.db.escape(self.item, percent=False)), self.item) |
|
|
|
if last_name: |
|
|
|
idx = cint(cstr(last_name[0][0]).split('/')[-1].split('-')[0]) + 1 |
|
|
|
names = frappe.db.sql_list("""select name from `tabBOM` where item=%s""", self.item) |
|
|
|
|
|
|
|
if names: |
|
|
|
# name can be BOM/ITEM/001, BOM/ITEM/001-1, BOM-ITEM-001, BOM-ITEM-001-1 |
|
|
|
|
|
|
|
# split by item |
|
|
|
names = [name.split(self.item)[-1][1:] for name in names] |
|
|
|
|
|
|
|
# split by (-) if cancelled |
|
|
|
names = [cint(name.split('-')[-1]) for name in names] |
|
|
|
|
|
|
|
idx = max(names) + 1 |
|
|
|
else: |
|
|
|
idx = 1 |
|
|
|
|
|
|
|
self.name = 'BOM/' + self.item + ('/%.3i' % idx) |
|
|
|
|
|
|
|
def validate(self): |
|
|
|