Auto increment based on condition

Hi ,

Could anyone tell me how to increment a doctype based on the condition in a particular field ?

Actually I want to increment the item_code if the item group is a Raw Material .

If item_code is a product I would put 
field:item_code
If item_code is a Raw material then it should be 
#####

Thanks

For now it only supports that you choose either from naming series or item_code in stock settings

for a clean and less buggy solution i suggest that you should use naming series by default and create different naming series for Raw Materials and create a custom script to change naming series to RAW-#### if item group is == raw material if not then ITEM-####

Now if your really want that feature it will take a lot of testing because it could affect reports or other modules

#>NOTE:
#>This is not fully tested it is just to give you an idea
#>Test on a Different Instance
#>No Warranty

And So
1st. Go to Customize form uncheck hidden from the naming_series field

2nd Change default item naming series to RAW-#### or what is needed to raw items.

3rd. open the item.js from erpnext/stock/doctype/item
and delete this code

  if (frappe.defaults.get_default("item_naming_by")!="Naming Series") {
  	frm.toggle_display("naming_series", false);
  } else {
  	erpnext.toggle_naming_series();
  }

4th open the item.py from erpnext/stock/doctype/item and modify this code by changing frappe.db.get_default(“item_naming_by”)==“Naming Series” to something like self.item_group == “Raw Materials” so that naming series naming will activate when item_group is equal to raw materials
if not it will use the item_code for naming

def autoname(self):
	if frappe.db.get_default("item_naming_by")=="Naming Series":
		if self.variant_of:
			if not self.item_code:
				item_code_suffix = ""
				for attribute in self.attributes:
					attribute_abbr = frappe.db.get_value("Item Attribute Value",
						{"parent": attribute.attribute, "attribute_value": attribute.attribute_value}, "abbr")
					item_code_suffix += "-" + str(attribute_abbr or attribute.attribute_value)
				self.item_code = str(self.variant_of) + item_code_suffix
		else:
			from frappe.model.naming import make_autoname
			self.item_code = make_autoname(self.naming_series+'.#####')
	elif not self.item_code:
		msgprint(_("Item Code is mandatory because Item is not automatically numbered"), raise_exception=1)

	self.item_code = strip(self.item_code)
	self.name = self.item_code
2 Likes

Thank you so much for taking time to guide me . @claily You are awesome.

Thanks again.