Naming Series Property Setter Patch
diff --git a/erpnext/accounts/doctype/gl_entry/gl_entry.json b/erpnext/accounts/doctype/gl_entry/gl_entry.json
index ce17278..07578e2 100644
--- a/erpnext/accounts/doctype/gl_entry/gl_entry.json
+++ b/erpnext/accounts/doctype/gl_entry/gl_entry.json
@@ -1,226 +1,229 @@
 {
- "autoname": "GL.#######",
- "creation": "2013-01-10 16:34:06",
- "docstatus": 0,
- "doctype": "DocType",
+ "autoname": "GL.#######", 
+ "creation": "2013-01-10 16:34:06", 
+ "docstatus": 0, 
+ "doctype": "DocType", 
  "fields": [
   {
-   "fieldname": "posting_date",
-   "fieldtype": "Date",
-   "in_filter": 1,
-   "in_list_view": 1,
-   "label": "Posting Date",
-   "oldfieldname": "posting_date",
-   "oldfieldtype": "Date",
-   "permlevel": 0,
+   "fieldname": "posting_date", 
+   "fieldtype": "Date", 
+   "in_filter": 1, 
+   "in_list_view": 1, 
+   "label": "Posting Date", 
+   "oldfieldname": "posting_date", 
+   "oldfieldtype": "Date", 
+   "permlevel": 0, 
    "search_index": 1
-  },
+  }, 
   {
-   "fieldname": "transaction_date",
-   "fieldtype": "Date",
-   "in_list_view": 1,
-   "label": "Transaction Date",
-   "oldfieldname": "transaction_date",
-   "oldfieldtype": "Date",
+   "fieldname": "transaction_date", 
+   "fieldtype": "Date", 
+   "in_list_view": 1, 
+   "label": "Transaction Date", 
+   "oldfieldname": "transaction_date", 
+   "oldfieldtype": "Date", 
    "permlevel": 0
-  },
+  }, 
   {
-   "fieldname": "aging_date",
-   "fieldtype": "Date",
-   "in_filter": 1,
-   "in_list_view": 1,
-   "label": "Aging Date",
-   "oldfieldname": "aging_date",
-   "oldfieldtype": "Date",
-   "permlevel": 0,
+   "fieldname": "aging_date", 
+   "fieldtype": "Date", 
+   "in_filter": 1, 
+   "in_list_view": 1, 
+   "label": "Aging Date", 
+   "oldfieldname": "aging_date", 
+   "oldfieldtype": "Date", 
+   "permlevel": 0, 
    "search_index": 0
-  },
+  }, 
   {
-   "fieldname": "account",
-   "fieldtype": "Link",
-   "in_filter": 1,
-   "in_list_view": 1,
-   "label": "Account",
-   "oldfieldname": "account",
-   "oldfieldtype": "Link",
-   "options": "Account",
-   "permlevel": 0,
+   "fieldname": "account", 
+   "fieldtype": "Link", 
+   "in_filter": 1, 
+   "in_list_view": 1, 
+   "label": "Account", 
+   "oldfieldname": "account", 
+   "oldfieldtype": "Link", 
+   "options": "Account", 
+   "permlevel": 0, 
    "search_index": 1
-  },
+  }, 
   {
-   "fieldname": "cost_center",
-   "fieldtype": "Link",
-   "in_filter": 1,
-   "in_list_view": 1,
-   "label": "Cost Center",
-   "oldfieldname": "cost_center",
-   "oldfieldtype": "Link",
-   "options": "Cost Center",
-   "permlevel": 0,
+   "fieldname": "cost_center", 
+   "fieldtype": "Link", 
+   "in_filter": 1, 
+   "in_list_view": 1, 
+   "label": "Cost Center", 
+   "oldfieldname": "cost_center", 
+   "oldfieldtype": "Link", 
+   "options": "Cost Center", 
+   "permlevel": 0, 
    "search_index": 0
-  },
+  }, 
   {
-   "fieldname": "debit",
-   "fieldtype": "Currency",
-   "label": "Debit Amt",
-   "oldfieldname": "debit",
-   "oldfieldtype": "Currency",
-   "options": "Company:company:default_currency",
+   "fieldname": "debit", 
+   "fieldtype": "Currency", 
+   "label": "Debit Amt", 
+   "oldfieldname": "debit", 
+   "oldfieldtype": "Currency", 
+   "options": "Company:company:default_currency", 
    "permlevel": 0
-  },
+  }, 
   {
-   "fieldname": "credit",
-   "fieldtype": "Currency",
-   "label": "Credit Amt",
-   "oldfieldname": "credit",
-   "oldfieldtype": "Currency",
-   "options": "Company:company:default_currency",
+   "fieldname": "credit", 
+   "fieldtype": "Currency", 
+   "label": "Credit Amt", 
+   "oldfieldname": "credit", 
+   "oldfieldtype": "Currency", 
+   "options": "Company:company:default_currency", 
    "permlevel": 0
-  },
+  }, 
   {
-   "fieldname": "against",
-   "fieldtype": "Text",
-   "in_filter": 1,
-   "label": "Against",
-   "oldfieldname": "against",
-   "oldfieldtype": "Text",
+   "fieldname": "against", 
+   "fieldtype": "Text", 
+   "in_filter": 1, 
+   "label": "Against", 
+   "oldfieldname": "against", 
+   "oldfieldtype": "Text", 
    "permlevel": 0
-  },
+  }, 
   {
-   "fieldname": "against_voucher",
-   "fieldtype": "Data",
-   "in_filter": 1,
-   "label": "Against Voucher",
-   "oldfieldname": "against_voucher",
-   "oldfieldtype": "Data",
-   "permlevel": 0,
+   "fieldname": "against_voucher_type", 
+   "fieldtype": "Link", 
+   "in_filter": 0, 
+   "label": "Against Voucher Type", 
+   "oldfieldname": "against_voucher_type", 
+   "oldfieldtype": "Data", 
+   "options": "DocType", 
+   "permlevel": 0, 
    "search_index": 0
-  },
+  }, 
   {
-   "fieldname": "against_voucher_type",
-   "fieldtype": "Data",
-   "in_filter": 0,
-   "label": "Against Voucher Type",
-   "oldfieldname": "against_voucher_type",
-   "oldfieldtype": "Data",
-   "permlevel": 0,
+   "fieldname": "against_voucher", 
+   "fieldtype": "Dynamic Link", 
+   "in_filter": 1, 
+   "label": "Against Voucher", 
+   "oldfieldname": "against_voucher", 
+   "oldfieldtype": "Data", 
+   "options": "against_voucher_type", 
+   "permlevel": 0, 
    "search_index": 0
-  },
+  }, 
   {
-   "fieldname": "voucher_type",
-   "fieldtype": "Select",
-   "in_filter": 1,
-   "label": "Voucher Type",
-   "oldfieldname": "voucher_type",
-   "oldfieldtype": "Select",
-   "options": "Journal Voucher\nSales Invoice\nPurchase Invoice\nPeriod Closing Voucher\nPurchase Receipt\nDelivery Note\nStock Entry\nStock Reconciliation",
-   "permlevel": 0,
+   "fieldname": "voucher_type", 
+   "fieldtype": "Link", 
+   "in_filter": 1, 
+   "label": "Voucher Type", 
+   "oldfieldname": "voucher_type", 
+   "oldfieldtype": "Select", 
+   "options": "DocType", 
+   "permlevel": 0, 
    "search_index": 0
-  },
+  }, 
   {
-   "fieldname": "voucher_no",
-   "fieldtype": "Data",
-   "in_filter": 1,
-   "label": "Voucher No",
-   "oldfieldname": "voucher_no",
-   "oldfieldtype": "Data",
-   "permlevel": 0,
+   "fieldname": "voucher_no", 
+   "fieldtype": "Dynamic Link", 
+   "in_filter": 1, 
+   "label": "Voucher No", 
+   "oldfieldname": "voucher_no", 
+   "oldfieldtype": "Data", 
+   "options": "voucher_type", 
+   "permlevel": 0, 
    "search_index": 1
-  },
+  }, 
   {
-   "fieldname": "remarks",
-   "fieldtype": "Text",
-   "in_filter": 1,
-   "label": "Remarks",
-   "no_copy": 1,
-   "oldfieldname": "remarks",
-   "oldfieldtype": "Text",
-   "permlevel": 0,
+   "fieldname": "remarks", 
+   "fieldtype": "Text", 
+   "in_filter": 1, 
+   "label": "Remarks", 
+   "no_copy": 1, 
+   "oldfieldname": "remarks", 
+   "oldfieldtype": "Text", 
+   "permlevel": 0, 
    "search_index": 0
-  },
+  }, 
   {
-   "fieldname": "is_opening",
-   "fieldtype": "Select",
-   "in_filter": 1,
-   "label": "Is Opening",
-   "oldfieldname": "is_opening",
-   "oldfieldtype": "Select",
-   "options": "No\nYes",
-   "permlevel": 0,
+   "fieldname": "is_opening", 
+   "fieldtype": "Select", 
+   "in_filter": 1, 
+   "label": "Is Opening", 
+   "oldfieldname": "is_opening", 
+   "oldfieldtype": "Select", 
+   "options": "No\nYes", 
+   "permlevel": 0, 
    "search_index": 0
-  },
+  }, 
   {
-   "fieldname": "is_advance",
-   "fieldtype": "Select",
-   "in_filter": 0,
-   "label": "Is Advance",
-   "oldfieldname": "is_advance",
-   "oldfieldtype": "Select",
-   "options": "No\nYes",
-   "permlevel": 0,
+   "fieldname": "is_advance", 
+   "fieldtype": "Select", 
+   "in_filter": 0, 
+   "label": "Is Advance", 
+   "oldfieldname": "is_advance", 
+   "oldfieldtype": "Select", 
+   "options": "No\nYes", 
+   "permlevel": 0, 
    "search_index": 0
-  },
+  }, 
   {
-   "fieldname": "fiscal_year",
-   "fieldtype": "Link",
-   "in_filter": 1,
-   "label": "Fiscal Year",
-   "oldfieldname": "fiscal_year",
-   "oldfieldtype": "Select",
-   "options": "Fiscal Year",
-   "permlevel": 0,
+   "fieldname": "fiscal_year", 
+   "fieldtype": "Link", 
+   "in_filter": 1, 
+   "label": "Fiscal Year", 
+   "oldfieldname": "fiscal_year", 
+   "oldfieldtype": "Select", 
+   "options": "Fiscal Year", 
+   "permlevel": 0, 
    "search_index": 0
-  },
+  }, 
   {
-   "fieldname": "company",
-   "fieldtype": "Link",
-   "in_filter": 1,
-   "label": "Company",
-   "oldfieldname": "company",
-   "oldfieldtype": "Link",
-   "options": "Company",
-   "permlevel": 0,
+   "fieldname": "company", 
+   "fieldtype": "Link", 
+   "in_filter": 1, 
+   "label": "Company", 
+   "oldfieldname": "company", 
+   "oldfieldtype": "Link", 
+   "options": "Company", 
+   "permlevel": 0, 
    "search_index": 0
   }
- ],
- "icon": "icon-list",
- "idx": 1,
- "in_create": 1,
- "modified": "2014-06-19 01:51:29.340077",
- "modified_by": "Administrator",
- "module": "Accounts",
- "name": "GL Entry",
- "owner": "Administrator",
+ ], 
+ "icon": "icon-list", 
+ "idx": 1, 
+ "in_create": 1, 
+ "modified": "2014-06-23 08:07:30.678730", 
+ "modified_by": "Administrator", 
+ "module": "Accounts", 
+ "name": "GL Entry", 
+ "owner": "Administrator", 
  "permissions": [
   {
-   "amend": 0,
-   "apply_user_permissions": 1,
-   "create": 0,
-   "email": 1,
-   "export": 1,
-   "permlevel": 0,
-   "print": 1,
-   "read": 1,
-   "report": 1,
-   "role": "Accounts User",
-   "submit": 0,
+   "amend": 0, 
+   "apply_user_permissions": 1, 
+   "create": 0, 
+   "email": 1, 
+   "export": 1, 
+   "permlevel": 0, 
+   "print": 1, 
+   "read": 1, 
+   "report": 1, 
+   "role": "Accounts User", 
+   "submit": 0, 
    "write": 0
-  },
+  }, 
   {
-   "amend": 0,
-   "create": 0,
-   "email": 1,
-   "export": 1,
-   "permlevel": 0,
-   "print": 1,
-   "read": 1,
-   "report": 1,
-   "role": "Accounts Manager",
-   "submit": 0,
+   "amend": 0, 
+   "create": 0, 
+   "email": 1, 
+   "export": 1, 
+   "permlevel": 0, 
+   "print": 1, 
+   "read": 1, 
+   "report": 1, 
+   "role": "Accounts Manager", 
+   "submit": 0, 
    "write": 0
   }
- ],
- "search_fields": "voucher_no,account,posting_date,against_voucher",
- "sort_field": "modified",
+ ], 
+ "search_fields": "voucher_no,account,posting_date,against_voucher", 
+ "sort_field": "modified", 
  "sort_order": "DESC"
-}
+}
\ No newline at end of file
diff --git a/erpnext/accounts/doctype/period_closing_voucher/period_closing_voucher.json b/erpnext/accounts/doctype/period_closing_voucher/period_closing_voucher.json
index e1aa66f..c9e7dc2 100644
--- a/erpnext/accounts/doctype/period_closing_voucher/period_closing_voucher.json
+++ b/erpnext/accounts/doctype/period_closing_voucher/period_closing_voucher.json
@@ -43,13 +43,14 @@
   }, 
   {
    "fieldname": "amended_from", 
-   "fieldtype": "Data", 
+   "fieldtype": "Link", 
    "ignore_user_permissions": 1, 
    "in_list_view": 1, 
    "label": "Amended From", 
    "no_copy": 1, 
    "oldfieldname": "amended_from", 
    "oldfieldtype": "Data", 
+   "options": "Period Closing Voucher", 
    "permlevel": 0, 
    "read_only": 1
   }, 
@@ -101,7 +102,7 @@
  "icon": "icon-file-text", 
  "idx": 1, 
  "is_submittable": 1, 
- "modified": "2014-05-26 03:05:50.722547", 
+ "modified": "2014-06-23 07:55:49.946225", 
  "modified_by": "Administrator", 
  "module": "Accounts", 
  "name": "Period Closing Voucher", 
diff --git a/erpnext/buying/doctype/purchase_order/purchase_order.json b/erpnext/buying/doctype/purchase_order/purchase_order.json
index 794c041..14693c4 100644
--- a/erpnext/buying/doctype/purchase_order/purchase_order.json
+++ b/erpnext/buying/doctype/purchase_order/purchase_order.json
@@ -104,13 +104,14 @@
   }, 
   {
    "fieldname": "amended_from", 
-   "fieldtype": "Data", 
+   "fieldtype": "Link", 
    "hidden": 0, 
    "ignore_user_permissions": 1, 
    "label": "Amended From", 
    "no_copy": 1, 
    "oldfieldname": "amended_from", 
    "oldfieldtype": "Data", 
+   "options": "Purchase Order", 
    "permlevel": 0, 
    "print_hide": 1, 
    "read_only": 1, 
@@ -644,7 +645,7 @@
  "icon": "icon-file-text", 
  "idx": 1, 
  "is_submittable": 1, 
- "modified": "2014-06-19 15:58:06.375217", 
+ "modified": "2014-06-23 07:55:50.372486", 
  "modified_by": "Administrator", 
  "module": "Buying", 
  "name": "Purchase Order", 
diff --git a/erpnext/buying/doctype/quality_inspection/quality_inspection.json b/erpnext/buying/doctype/quality_inspection/quality_inspection.json
index 4da6e63..3e05b31 100644
--- a/erpnext/buying/doctype/quality_inspection/quality_inspection.json
+++ b/erpnext/buying/doctype/quality_inspection/quality_inspection.json
@@ -168,12 +168,13 @@
   }, 
   {
    "fieldname": "amended_from", 
-   "fieldtype": "Data", 
+   "fieldtype": "Link", 
    "ignore_user_permissions": 1, 
    "label": "Amended From", 
    "no_copy": 1, 
    "oldfieldname": "amended_from", 
    "oldfieldtype": "Data", 
+   "options": "Quality Inspection", 
    "permlevel": 0, 
    "print_hide": 1, 
    "read_only": 1
@@ -206,7 +207,7 @@
  "icon": "icon-search", 
  "idx": 1, 
  "is_submittable": 1, 
- "modified": "2014-05-26 03:05:52.140251", 
+ "modified": "2014-06-23 07:55:51.183113", 
  "modified_by": "Administrator", 
  "module": "Buying", 
  "name": "Quality Inspection", 
diff --git a/erpnext/buying/doctype/supplier_quotation/supplier_quotation.json b/erpnext/buying/doctype/supplier_quotation/supplier_quotation.json
index c3c5bf4..955aa68 100644
--- a/erpnext/buying/doctype/supplier_quotation/supplier_quotation.json
+++ b/erpnext/buying/doctype/supplier_quotation/supplier_quotation.json
@@ -104,13 +104,14 @@
   }, 
   {
    "fieldname": "amended_from", 
-   "fieldtype": "Data", 
+   "fieldtype": "Link", 
    "hidden": 1, 
    "ignore_user_permissions": 1, 
    "label": "Amended From", 
    "no_copy": 1, 
    "oldfieldname": "amended_from", 
    "oldfieldtype": "Data", 
+   "options": "Supplier Quotation", 
    "permlevel": 0, 
    "print_hide": 1, 
    "read_only": 1, 
@@ -570,7 +571,7 @@
  "icon": "icon-shopping-cart", 
  "idx": 1, 
  "is_submittable": 1, 
- "modified": "2014-06-19 15:54:27.919675", 
+ "modified": "2014-06-23 07:55:52.993616", 
  "modified_by": "Administrator", 
  "module": "Buying", 
  "name": "Supplier Quotation", 
diff --git a/erpnext/hr/doctype/appraisal/appraisal.json b/erpnext/hr/doctype/appraisal/appraisal.json
index 2fec94f..beddeef 100644
--- a/erpnext/hr/doctype/appraisal/appraisal.json
+++ b/erpnext/hr/doctype/appraisal/appraisal.json
@@ -179,13 +179,14 @@
   }, 
   {
    "fieldname": "amended_from", 
-   "fieldtype": "Data", 
+   "fieldtype": "Link", 
    "hidden": 1, 
    "ignore_user_permissions": 1, 
    "label": "Amended From", 
    "no_copy": 1, 
    "oldfieldname": "amended_from", 
    "oldfieldtype": "Data", 
+   "options": "Appraisal", 
    "permlevel": 0, 
    "print_hide": 1, 
    "read_only": 1, 
@@ -196,7 +197,7 @@
  "icon": "icon-thumbs-up", 
  "idx": 1, 
  "is_submittable": 1, 
- "modified": "2014-05-27 03:49:07.393120", 
+ "modified": "2014-06-23 07:55:40.801381", 
  "modified_by": "Administrator", 
  "module": "HR", 
  "name": "Appraisal", 
diff --git a/erpnext/hr/doctype/expense_claim/expense_claim.json b/erpnext/hr/doctype/expense_claim/expense_claim.json
index 4ebc30f..c13710a 100644
--- a/erpnext/hr/doctype/expense_claim/expense_claim.json
+++ b/erpnext/hr/doctype/expense_claim/expense_claim.json
@@ -171,12 +171,13 @@
   }, 
   {
    "fieldname": "amended_from", 
-   "fieldtype": "Data", 
+   "fieldtype": "Link", 
    "ignore_user_permissions": 1, 
    "label": "Amended From", 
    "no_copy": 1, 
    "oldfieldname": "amended_from", 
    "oldfieldtype": "Data", 
+   "options": "Expense Claim", 
    "permlevel": 0, 
    "print_hide": 1, 
    "read_only": 1, 
@@ -187,7 +188,7 @@
  "icon": "icon-money", 
  "idx": 1, 
  "is_submittable": 1, 
- "modified": "2014-05-27 03:49:10.736177", 
+ "modified": "2014-06-23 07:55:48.580747", 
  "modified_by": "Administrator", 
  "module": "HR", 
  "name": "Expense Claim", 
diff --git a/erpnext/hr/doctype/leave_allocation/leave_allocation.json b/erpnext/hr/doctype/leave_allocation/leave_allocation.json
index ca583a1..ede86f3 100644
--- a/erpnext/hr/doctype/leave_allocation/leave_allocation.json
+++ b/erpnext/hr/doctype/leave_allocation/leave_allocation.json
@@ -121,13 +121,14 @@
   }, 
   {
    "fieldname": "amended_from", 
-   "fieldtype": "Data", 
+   "fieldtype": "Link", 
    "hidden": 0, 
    "ignore_user_permissions": 1, 
    "label": "Amended From", 
    "no_copy": 1, 
    "oldfieldname": "amended_from", 
    "oldfieldtype": "Data", 
+   "options": "Leave Allocation", 
    "permlevel": 0, 
    "print_hide": 1, 
    "read_only": 1
@@ -136,7 +137,7 @@
  "icon": "icon-ok", 
  "idx": 1, 
  "is_submittable": 1, 
- "modified": "2014-05-27 03:49:12.744348", 
+ "modified": "2014-06-23 07:55:48.989894", 
  "modified_by": "Administrator", 
  "module": "HR", 
  "name": "Leave Allocation", 
diff --git a/erpnext/hr/doctype/salary_slip/salary_slip.json b/erpnext/hr/doctype/salary_slip/salary_slip.json
index 374d11e..5d2f028 100644
--- a/erpnext/hr/doctype/salary_slip/salary_slip.json
+++ b/erpnext/hr/doctype/salary_slip/salary_slip.json
@@ -180,13 +180,14 @@
   }, 
   {
    "fieldname": "amended_from", 
-   "fieldtype": "Data", 
+   "fieldtype": "Link", 
    "hidden": 0, 
    "ignore_user_permissions": 1, 
    "label": "Amended From", 
    "no_copy": 1, 
    "oldfieldname": "amended_from", 
    "oldfieldtype": "Data", 
+   "options": "Salary Slip", 
    "permlevel": 0, 
    "print_hide": 1, 
    "report_hide": 0
@@ -325,7 +326,7 @@
  "icon": "icon-file-text", 
  "idx": 1, 
  "is_submittable": 1, 
- "modified": "2014-05-27 03:49:17.213045", 
+ "modified": "2014-06-23 07:55:52.259962", 
  "modified_by": "Administrator", 
  "module": "HR", 
  "name": "Salary Slip", 
diff --git a/erpnext/manufacturing/doctype/production_order/production_order.json b/erpnext/manufacturing/doctype/production_order/production_order.json
index 7e068cf..f5e43b0 100644
--- a/erpnext/manufacturing/doctype/production_order/production_order.json
+++ b/erpnext/manufacturing/doctype/production_order/production_order.json
@@ -1,256 +1,257 @@
 {
- "allow_import": 1,
- "autoname": "naming_series:",
- "creation": "2013-01-10 16:34:16",
- "docstatus": 0,
- "doctype": "DocType",
+ "allow_import": 1, 
+ "autoname": "naming_series:", 
+ "creation": "2013-01-10 16:34:16", 
+ "docstatus": 0, 
+ "doctype": "DocType", 
  "fields": [
   {
-   "fieldname": "item",
-   "fieldtype": "Section Break",
-   "label": "Item",
-   "options": "icon-gift",
+   "fieldname": "item", 
+   "fieldtype": "Section Break", 
+   "label": "Item", 
+   "options": "icon-gift", 
    "permlevel": 0
-  },
+  }, 
   {
-   "default": "PRO-",
-   "fieldname": "naming_series",
-   "fieldtype": "Select",
-   "label": "Series",
-   "options": "PRO-",
-   "permlevel": 0,
+   "default": "PRO-", 
+   "fieldname": "naming_series", 
+   "fieldtype": "Select", 
+   "label": "Series", 
+   "options": "PRO-", 
+   "permlevel": 0, 
    "reqd": 1
-  },
+  }, 
   {
-   "depends_on": "eval:!doc.__islocal",
-   "fieldname": "status",
-   "fieldtype": "Select",
-   "in_filter": 1,
-   "in_list_view": 1,
-   "label": "Status",
-   "no_copy": 1,
-   "oldfieldname": "status",
-   "oldfieldtype": "Select",
-   "options": "\nDraft\nSubmitted\nStopped\nIn Process\nCompleted\nCancelled",
-   "permlevel": 0,
-   "read_only": 1,
-   "reqd": 1,
+   "depends_on": "eval:!doc.__islocal", 
+   "fieldname": "status", 
+   "fieldtype": "Select", 
+   "in_filter": 1, 
+   "in_list_view": 1, 
+   "label": "Status", 
+   "no_copy": 1, 
+   "oldfieldname": "status", 
+   "oldfieldtype": "Select", 
+   "options": "\nDraft\nSubmitted\nStopped\nIn Process\nCompleted\nCancelled", 
+   "permlevel": 0, 
+   "read_only": 1, 
+   "reqd": 1, 
    "search_index": 1
-  },
+  }, 
   {
-   "fieldname": "production_item",
-   "fieldtype": "Link",
-   "in_filter": 1,
-   "in_list_view": 1,
-   "label": "Item To Manufacture",
-   "oldfieldname": "production_item",
-   "oldfieldtype": "Link",
-   "options": "Item",
-   "permlevel": 0,
-   "read_only": 0,
+   "fieldname": "production_item", 
+   "fieldtype": "Link", 
+   "in_filter": 1, 
+   "in_list_view": 1, 
+   "label": "Item To Manufacture", 
+   "oldfieldname": "production_item", 
+   "oldfieldtype": "Link", 
+   "options": "Item", 
+   "permlevel": 0, 
+   "read_only": 0, 
    "reqd": 1
-  },
+  }, 
   {
-   "depends_on": "production_item",
-   "description": "Bill of Material to be considered for manufacturing",
-   "fieldname": "bom_no",
-   "fieldtype": "Link",
-   "in_list_view": 1,
-   "label": "BOM No",
-   "oldfieldname": "bom_no",
-   "oldfieldtype": "Link",
-   "options": "BOM",
-   "permlevel": 0,
-   "read_only": 0,
+   "depends_on": "production_item", 
+   "description": "Bill of Material to be considered for manufacturing", 
+   "fieldname": "bom_no", 
+   "fieldtype": "Link", 
+   "in_list_view": 1, 
+   "label": "BOM No", 
+   "oldfieldname": "bom_no", 
+   "oldfieldtype": "Link", 
+   "options": "BOM", 
+   "permlevel": 0, 
+   "read_only": 0, 
    "reqd": 1
-  },
+  }, 
   {
-   "default": "1",
-   "description": "If checked, BOM for sub-assembly items will be considered for getting raw materials. Otherwise, all sub-assembly items will be treated as a raw material.",
-   "fieldname": "use_multi_level_bom",
-   "fieldtype": "Check",
-   "label": "Use Multi-Level BOM",
+   "default": "1", 
+   "description": "If checked, BOM for sub-assembly items will be considered for getting raw materials. Otherwise, all sub-assembly items will be treated as a raw material.", 
+   "fieldname": "use_multi_level_bom", 
+   "fieldtype": "Check", 
+   "label": "Use Multi-Level BOM", 
    "permlevel": 0
-  },
+  }, 
   {
-   "fieldname": "column_break1",
-   "fieldtype": "Column Break",
-   "oldfieldtype": "Column Break",
-   "permlevel": 0,
-   "read_only": 0,
+   "fieldname": "column_break1", 
+   "fieldtype": "Column Break", 
+   "oldfieldtype": "Column Break", 
+   "permlevel": 0, 
+   "read_only": 0, 
    "width": "50%"
-  },
+  }, 
   {
-   "description": "Manufacture against Sales Order",
-   "fieldname": "sales_order",
-   "fieldtype": "Link",
-   "label": "Sales Order",
-   "options": "Sales Order",
-   "permlevel": 0,
+   "description": "Manufacture against Sales Order", 
+   "fieldname": "sales_order", 
+   "fieldtype": "Link", 
+   "label": "Sales Order", 
+   "options": "Sales Order", 
+   "permlevel": 0, 
    "read_only": 0
-  },
+  }, 
   {
-   "depends_on": "production_item",
-   "fieldname": "qty",
-   "fieldtype": "Float",
-   "in_list_view": 1,
-   "label": "Qty To Manufacture",
-   "oldfieldname": "qty",
-   "oldfieldtype": "Currency",
-   "permlevel": 0,
-   "read_only": 0,
+   "depends_on": "production_item", 
+   "fieldname": "qty", 
+   "fieldtype": "Float", 
+   "in_list_view": 1, 
+   "label": "Qty To Manufacture", 
+   "oldfieldname": "qty", 
+   "oldfieldtype": "Currency", 
+   "permlevel": 0, 
+   "read_only": 0, 
    "reqd": 1
-  },
+  }, 
   {
-   "depends_on": "eval:doc.docstatus==1",
-   "description": "Automatically updated via Stock Entry of type Manufacture/Repack",
-   "fieldname": "produced_qty",
-   "fieldtype": "Float",
-   "label": "Manufactured Qty",
-   "no_copy": 1,
-   "oldfieldname": "produced_qty",
-   "oldfieldtype": "Currency",
-   "permlevel": 0,
+   "depends_on": "eval:doc.docstatus==1", 
+   "description": "Automatically updated via Stock Entry of type Manufacture/Repack", 
+   "fieldname": "produced_qty", 
+   "fieldtype": "Float", 
+   "label": "Manufactured Qty", 
+   "no_copy": 1, 
+   "oldfieldname": "produced_qty", 
+   "oldfieldtype": "Currency", 
+   "permlevel": 0, 
    "read_only": 1
-  },
+  }, 
   {
-   "depends_on": "sales_order",
-   "fieldname": "expected_delivery_date",
-   "fieldtype": "Date",
-   "label": "Expected Delivery Date",
-   "permlevel": 0,
+   "depends_on": "sales_order", 
+   "fieldname": "expected_delivery_date", 
+   "fieldtype": "Date", 
+   "label": "Expected Delivery Date", 
+   "permlevel": 0, 
    "read_only": 1
-  },
+  }, 
   {
-   "fieldname": "warehouses",
-   "fieldtype": "Section Break",
-   "label": "Warehouses",
-   "options": "icon-building",
+   "fieldname": "warehouses", 
+   "fieldtype": "Section Break", 
+   "label": "Warehouses", 
+   "options": "icon-building", 
    "permlevel": 0
-  },
+  }, 
   {
-   "depends_on": "production_item",
-   "description": "Manufactured quantity will be updated in this warehouse",
-   "fieldname": "fg_warehouse",
-   "fieldtype": "Link",
-   "in_list_view": 0,
-   "label": "For Warehouse",
-   "options": "Warehouse",
-   "permlevel": 0,
-   "read_only": 0,
+   "depends_on": "production_item", 
+   "description": "Manufactured quantity will be updated in this warehouse", 
+   "fieldname": "fg_warehouse", 
+   "fieldtype": "Link", 
+   "in_list_view": 0, 
+   "label": "For Warehouse", 
+   "options": "Warehouse", 
+   "permlevel": 0, 
+   "read_only": 0, 
    "reqd": 0
-  },
+  }, 
   {
-   "fieldname": "column_break_12",
-   "fieldtype": "Column Break",
+   "fieldname": "column_break_12", 
+   "fieldtype": "Column Break", 
    "permlevel": 0
-  },
+  }, 
   {
-   "fieldname": "wip_warehouse",
-   "fieldtype": "Link",
-   "label": "Work-in-Progress Warehouse",
-   "options": "Warehouse",
-   "permlevel": 0,
+   "fieldname": "wip_warehouse", 
+   "fieldtype": "Link", 
+   "label": "Work-in-Progress Warehouse", 
+   "options": "Warehouse", 
+   "permlevel": 0, 
    "reqd": 0
-  },
+  }, 
   {
-   "fieldname": "more_info",
-   "fieldtype": "Section Break",
-   "label": "More Info",
-   "options": "icon-file-text",
-   "permlevel": 0,
+   "fieldname": "more_info", 
+   "fieldtype": "Section Break", 
+   "label": "More Info", 
+   "options": "icon-file-text", 
+   "permlevel": 0, 
    "read_only": 0
-  },
+  }, 
   {
-   "fieldname": "description",
-   "fieldtype": "Small Text",
-   "label": "Item Description",
-   "permlevel": 0,
+   "fieldname": "description", 
+   "fieldtype": "Small Text", 
+   "label": "Item Description", 
+   "permlevel": 0, 
    "read_only": 1
-  },
+  }, 
   {
-   "fieldname": "project_name",
-   "fieldtype": "Link",
-   "in_filter": 1,
-   "label": "Project Name",
-   "oldfieldname": "project_name",
-   "oldfieldtype": "Link",
-   "options": "Project",
-   "permlevel": 0,
+   "fieldname": "project_name", 
+   "fieldtype": "Link", 
+   "in_filter": 1, 
+   "label": "Project Name", 
+   "oldfieldname": "project_name", 
+   "oldfieldtype": "Link", 
+   "options": "Project", 
+   "permlevel": 0, 
    "read_only": 0
-  },
+  }, 
   {
-   "fieldname": "column_break2",
-   "fieldtype": "Column Break",
-   "permlevel": 0,
-   "read_only": 0,
+   "fieldname": "column_break2", 
+   "fieldtype": "Column Break", 
+   "permlevel": 0, 
+   "read_only": 0, 
    "width": "50%"
-  },
+  }, 
   {
-   "depends_on": "production_item",
-   "fieldname": "stock_uom",
-   "fieldtype": "Link",
-   "label": "Stock UOM",
-   "oldfieldname": "stock_uom",
-   "oldfieldtype": "Data",
-   "options": "UOM",
-   "permlevel": 0,
+   "depends_on": "production_item", 
+   "fieldname": "stock_uom", 
+   "fieldtype": "Link", 
+   "label": "Stock UOM", 
+   "oldfieldname": "stock_uom", 
+   "oldfieldtype": "Data", 
+   "options": "UOM", 
+   "permlevel": 0, 
    "read_only": 1
-  },
+  }, 
   {
-   "fieldname": "company",
-   "fieldtype": "Link",
-   "label": "Company",
-   "oldfieldname": "company",
-   "oldfieldtype": "Link",
-   "options": "Company",
-   "permlevel": 0,
-   "read_only": 0,
+   "fieldname": "company", 
+   "fieldtype": "Link", 
+   "label": "Company", 
+   "oldfieldname": "company", 
+   "oldfieldtype": "Link", 
+   "options": "Company", 
+   "permlevel": 0, 
+   "read_only": 0, 
    "reqd": 1
-  },
+  }, 
   {
-   "fieldname": "amended_from",
-   "fieldtype": "Data",
-   "ignore_user_permissions": 1,
-   "label": "Amended From",
-   "no_copy": 1,
-   "oldfieldname": "amended_from",
-   "oldfieldtype": "Data",
-   "permlevel": 0,
+   "fieldname": "amended_from", 
+   "fieldtype": "Link", 
+   "ignore_user_permissions": 1, 
+   "label": "Amended From", 
+   "no_copy": 1, 
+   "oldfieldname": "amended_from", 
+   "oldfieldtype": "Data", 
+   "options": "Production Order", 
+   "permlevel": 0, 
    "read_only": 1
   }
- ],
- "icon": "icon-cogs",
- "idx": 1,
- "in_create": 0,
- "is_submittable": 1,
- "modified": "2014-05-27 03:49:15.008942",
- "modified_by": "Administrator",
- "module": "Manufacturing",
- "name": "Production Order",
- "owner": "Administrator",
+ ], 
+ "icon": "icon-cogs", 
+ "idx": 1, 
+ "in_create": 0, 
+ "is_submittable": 1, 
+ "modified": "2014-06-23 07:55:50.092300", 
+ "modified_by": "Administrator", 
+ "module": "Manufacturing", 
+ "name": "Production Order", 
+ "owner": "Administrator", 
  "permissions": [
   {
-   "amend": 1,
-   "apply_user_permissions": 1,
-   "cancel": 1,
-   "create": 1,
-   "delete": 1,
-   "email": 1,
-   "permlevel": 0,
-   "print": 1,
-   "read": 1,
-   "report": 1,
-   "role": "Manufacturing User",
-   "submit": 1,
+   "amend": 1, 
+   "apply_user_permissions": 1, 
+   "cancel": 1, 
+   "create": 1, 
+   "delete": 1, 
+   "email": 1, 
+   "permlevel": 0, 
+   "print": 1, 
+   "read": 1, 
+   "report": 1, 
+   "role": "Manufacturing User", 
+   "submit": 1, 
    "write": 1
-  },
+  }, 
   {
-   "apply_user_permissions": 1,
-   "permlevel": 0,
-   "read": 1,
-   "report": 1,
+   "apply_user_permissions": 1, 
+   "permlevel": 0, 
+   "read": 1, 
+   "report": 1, 
    "role": "Material User"
   }
  ]
-}
+}
\ No newline at end of file
diff --git a/erpnext/patches.txt b/erpnext/patches.txt
index 041bbd3..d94dd53 100644
--- a/erpnext/patches.txt
+++ b/erpnext/patches.txt
@@ -63,3 +63,4 @@
 execute:frappe.db.sql("update `tabItem` set end_of_life=null where end_of_life='0000-00-00'") #2014-06-16
 erpnext.patches.v4_0.update_users_report_view_settings
 erpnext.patches.v4_0.set_pricing_rule_for_buying_or_selling
+erpnext.patches.v4_0.set_naming_series_property_setter
diff --git a/erpnext/patches/repair_tools/__init__.py b/erpnext/patches/repair_tools/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/erpnext/patches/repair_tools/__init__.py
diff --git a/erpnext/patches/repair_tools/fix_naming_series_records_lost_by_reload.py b/erpnext/patches/repair_tools/fix_naming_series_records_lost_by_reload.py
new file mode 100644
index 0000000..7fb54b3
--- /dev/null
+++ b/erpnext/patches/repair_tools/fix_naming_series_records_lost_by_reload.py
@@ -0,0 +1,204 @@
+# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
+# License: GNU General Public License v3. See license.txt
+
+from __future__ import unicode_literals
+import frappe
+import json
+from frappe.model.naming import make_autoname
+from frappe.utils import cint
+from frappe.utils.email_lib import sendmail_to_system_managers
+
+doctype_series_map = {
+	'Attendance': 'ATT-',
+	'C-Form': 'C-FORM-',
+	'Customer': 'CUST-',
+	'Customer Issue': 'CI-',
+	'Delivery Note': 'DN-',
+	'Installation Note': 'IN-',
+	'Item': 'ITEM-',
+	'Journal Voucher': 'JV-',
+	'Lead': 'LEAD-',
+	'Opportunity': 'OPTY-',
+	'Packing Slip': 'PS-',
+	'Production Order': 'PRO-',
+	'Purchase Invoice': 'PINV-',
+	'Purchase Order': 'PO-',
+	'Purchase Receipt': 'PREC-',
+	'Quality Inspection': 'QI-',
+	'Quotation': 'QTN-',
+	'Sales Invoice': 'SINV-',
+	'Sales Order': 'SO-',
+	'Stock Entry': 'STE-',
+	'Supplier': 'SUPP-',
+	'Supplier Quotation': 'SQTN-',
+	'Support Ticket': 'SUP-'
+}
+
+def check_docs_to_rename():
+	if "erpnext" not in frappe.get_installed_apps():
+		return
+
+	docs_to_rename = get_docs_to_rename()
+	if docs_to_rename:
+		print "To Rename"
+		print json.dumps(docs_to_rename, indent=1, sort_keys=True)
+
+	frappe.db.rollback()
+
+def check_gl_sl_entries_to_fix():
+	if "erpnext" not in frappe.get_installed_apps():
+		return
+
+	gl_entries_to_fix = get_gl_entries_to_fix()
+	if gl_entries_to_fix:
+		print "General Ledger Entries to Fix"
+		print json.dumps(gl_entries_to_fix, indent=1, sort_keys=True)
+
+	sl_entries_to_fix = get_sl_entries_to_fix()
+	if sl_entries_to_fix:
+		print "Stock Ledger Entries to Fix"
+		print json.dumps(sl_entries_to_fix, indent=1, sort_keys=True)
+
+	frappe.db.rollback()
+
+def guess_reference_date():
+	return (frappe.db.get_value("Patch Log", {"patch": "erpnext.patches.v4_0.validate_v3_patch"}, "creation")
+		or "2014-05-06")
+
+def get_docs_to_rename():
+	reference_date = guess_reference_date()
+
+	docs_to_rename = {}
+	for doctype, new_series in doctype_series_map.items():
+		if doctype in ("Item", "Customer", "Lead", "Supplier"):
+			if not frappe.db.sql("""select name from `tab{doctype}`
+				where ifnull(naming_series, '')!=''
+				and name like concat(naming_series, '%%') limit 1""".format(doctype=doctype)):
+				continue
+
+		# fix newly formed records using old series!
+		records_with_new_series = frappe.db.sql_list("""select name from `tab{doctype}`
+			where date(creation) >= date(%s) and naming_series=%s
+			and exists (select name from `tab{doctype}` where ifnull(naming_series, '') not in ('', %s) limit 1)
+			order by name asc""".format(doctype=doctype), (reference_date, new_series, new_series))
+
+		if records_with_new_series:
+			docs_to_rename[doctype] = records_with_new_series
+
+	return docs_to_rename
+
+def get_gl_entries_to_fix():
+	bad_gl_entries = {}
+
+	for dt in frappe.db.sql_list("""select distinct voucher_type from `tabGL Entry`
+		where ifnull(voucher_type, '')!=''"""):
+
+		if dt not in doctype_series_map:
+			continue
+
+		out = frappe.db.sql("""select gl.name, gl.voucher_no from `tabGL Entry` gl
+			where ifnull(voucher_type, '')=%s and voucher_no like %s and
+			not exists (select name from `tab{voucher_type}` vt where vt.name=gl.voucher_no)""".format(voucher_type=dt),
+			(dt, doctype_series_map[dt] + "%%"), as_dict=True)
+
+		if out:
+			bad_gl_entries.setdefault(dt, []).extend(out)
+
+	for dt in frappe.db.sql_list("""select distinct against_voucher_type
+		from `tabGL Entry` where ifnull(against_voucher_type, '')!=''"""):
+
+		if dt not in doctype_series_map:
+			continue
+
+		out = frappe.db.sql("""select gl.name, gl.against_voucher from `tabGL Entry` gl
+			where ifnull(against_voucher_type, '')=%s and against_voucher like %s and
+			not exists (select name from `tab{against_voucher_type}` vt
+				where vt.name=gl.against_voucher)""".format(against_voucher_type=dt),
+			(dt, doctype_series_map[dt] + "%%"), as_dict=True)
+
+		if out:
+			bad_gl_entries.setdefault(dt, []).extend(out)
+
+	return bad_gl_entries
+
+def get_sl_entries_to_fix():
+	bad_sl_entries = {}
+
+	for dt in frappe.db.sql_list("""select distinct voucher_type from `tabStock Ledger Entry`
+		where ifnull(voucher_type, '')!=''"""):
+
+		if dt not in doctype_series_map:
+			continue
+
+		out = frappe.db.sql("""select sl.name, sl.voucher_no from `tabStock Ledger Entry` sl
+			where voucher_type=%s and voucher_no like %s and
+			not exists (select name from `tab{voucher_type}` vt where vt.name=sl.voucher_no)""".format(voucher_type=dt),
+			(dt, doctype_series_map[dt] + "%%"), as_dict=True)
+		if out:
+			bad_sl_entries.setdefault(dt, []).extend(out)
+
+	return bad_sl_entries
+
+def add_comment(doctype, old_name, new_name):
+	frappe.get_doc({
+		"doctype":"Comment",
+		"comment_by": frappe.session.user,
+		"comment_doctype": doctype,
+		"comment_docname": new_name,
+		"comment": """Renamed from **{old_name}** to {new_name}""".format(old_name=old_name, new_name=new_name)
+	}).insert(ignore_permissions=True)
+
+def _rename_doc(doctype, name, naming_series):
+	if frappe.get_meta(doctype).get_field("amended_from"):
+		amended_from = frappe.db.get_value(doctype, name, "amended_from")
+	else:
+		amended_from = None
+
+	if amended_from:
+		am_id = 1
+		am_prefix = amended_from
+		if frappe.db.get_value(doctype, amended_from, "amended_from"):
+			am_id = cint(amended_from.split('-')[-1]) + 1
+			am_prefix = '-'.join(amended_from.split('-')[:-1]) # except the last hyphen
+
+		fixed_name = am_prefix + '-' + str(am_id)
+	else:
+		fixed_name = make_autoname(naming_series+'.#####')
+
+	frappe.db.set_value(doctype, name, "naming_series", naming_series)
+	frappe.rename_doc(doctype, name, fixed_name, force=True)
+	add_comment(doctype, name, fixed_name)
+
+	return fixed_name
+
+def rename_docs():
+	_log = []
+	def log(msg):
+		_log.append(msg)
+		print msg
+
+	commit = False
+	docs_to_rename = get_docs_to_rename()
+	for doctype, list_of_names in docs_to_rename.items():
+		naming_series_field = frappe.get_meta(doctype).get_field("naming_series")
+		default_series = naming_series_field.default or filter(None, (naming_series_field.options or "").split("\n"))[0]
+
+		print
+		print "Rename", doctype, list_of_names, "using series", default_series
+		confirm = raw_input("do it? (yes / anything else): ")
+
+		if confirm == "yes":
+			commit = True
+			for name in list_of_names:
+				fixed_name = _rename_doc(doctype, name, default_series)
+				log("Renamed {doctype} {name} --> {fixed_name}".format(doctype=doctype, name=name, fixed_name=fixed_name))
+
+	if commit:
+		content = """These documents have been renamed in your ERPNext instance: {site}\n\n{_log}""".format(site=frappe.local.site, _log="\n".join(_log))
+
+		print content
+
+		frappe.db.commit()
+
+		sendmail_to_system_managers("[Important] [ERPNext] Renamed Documents via Patch", content)
+
diff --git a/erpnext/patches/v4_0/set_naming_series_property_setter.py b/erpnext/patches/v4_0/set_naming_series_property_setter.py
new file mode 100644
index 0000000..7161492
--- /dev/null
+++ b/erpnext/patches/v4_0/set_naming_series_property_setter.py
@@ -0,0 +1,98 @@
+# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
+# License: GNU General Public License v3. See license.txt
+
+from __future__ import unicode_literals
+
+import frappe
+from frappe.core.doctype.property_setter.property_setter import make_property_setter
+
+doctype_series_map = {
+	'Attendance': 'ATT-',
+	'C-Form': 'C-FORM-',
+	'Customer': 'CUST-',
+	'Customer Issue': 'CI-',
+	'Delivery Note': 'DN-',
+	'Installation Note': 'IN-',
+	'Item': 'ITEM-',
+	'Journal Voucher': 'JV-',
+	'Lead': 'LEAD-',
+	'Opportunity': 'OPTY-',
+	'Packing Slip': 'PS-',
+	'Production Order': 'PRO-',
+	'Purchase Invoice': 'PINV-',
+	'Purchase Order': 'PO-',
+	'Purchase Receipt': 'PREC-',
+	'Quality Inspection': 'QI-',
+	'Quotation': 'QTN-',
+	'Sales Invoice': 'SINV-',
+	'Sales Order': 'SO-',
+	'Stock Entry': 'STE-',
+	'Supplier': 'SUPP-',
+	'Supplier Quotation': 'SQTN-',
+	'Support Ticket': 'SUP-'
+}
+
+def execute():
+	series_to_set = get_series_to_set()
+	for doctype, opts in series_to_set.items():
+		print "Setting naming series", doctype, opts
+		set_series(doctype, opts["options"], opts["default"])
+
+def set_series(doctype, options, default):
+	make_property_setter(doctype, "naming_series", "options", options, "Text")
+	make_property_setter(doctype, "naming_series", "default", default, "Text")
+
+def get_series_to_set():
+	series_to_set = {}
+
+	for doctype, new_series in doctype_series_map.items():
+		# you can't fix what does not exist :)
+		if not frappe.db.a_row_exists(doctype):
+			continue
+
+		series_to_preserve = get_series_to_preserve(doctype, new_series)
+
+		if not series_to_preserve:
+			continue
+
+		default_series = get_default_series(doctype, new_series)
+		if not default_series:
+			continue
+
+		existing_series = (frappe.get_meta(doctype).get_field("naming_series").options or "").split("\n")
+		existing_series = filter(None, [d.strip() for d in existing_series])
+
+		if (not (set(existing_series).difference(series_to_preserve) or set(series_to_preserve).difference(existing_series))
+			and len(series_to_preserve)==len(existing_series)):
+			# print "No change for", doctype, ":", existing_series, "=", series_to_preserve
+			continue
+
+		# set naming series property setter
+		series_to_preserve = list(set(series_to_preserve + existing_series))
+		if new_series in series_to_preserve:
+			series_to_preserve.remove(new_series)
+
+		if series_to_preserve:
+			series_to_set[doctype] = {"options": "\n".join(series_to_preserve), "default": default_series}
+
+	return series_to_set
+
+def get_series_to_preserve(doctype, new_series):
+	series_to_preserve = frappe.db.sql_list("""select distinct naming_series from `tab{doctype}`
+		where ifnull(naming_series, '') not in ('', %s)""".format(doctype=doctype), new_series)
+
+	series_to_preserve.sort()
+
+	return series_to_preserve
+
+def get_default_series(doctype, new_series):
+	default_series = frappe.db.sql("""select naming_series from `tab{doctype}` where ifnull(naming_series, '') not in ('', %s)
+		and creation=(select max(creation) from `tab{doctype}`
+			where ifnull(naming_series, '') not in ('', %s)) order by creation desc limit 1""".format(doctype=doctype),
+		(new_series, new_series))
+
+	if not (default_series and default_series[0][0]):
+		print "[Skipping] Cannot guess which naming series to use for", doctype
+		return
+
+	return default_series[0][0]
diff --git a/erpnext/selling/doctype/installation_note/installation_note.json b/erpnext/selling/doctype/installation_note/installation_note.json
index 859ff5f..56df061 100644
--- a/erpnext/selling/doctype/installation_note/installation_note.json
+++ b/erpnext/selling/doctype/installation_note/installation_note.json
@@ -195,12 +195,13 @@
   }, 
   {
    "fieldname": "amended_from", 
-   "fieldtype": "Data", 
+   "fieldtype": "Link", 
    "ignore_user_permissions": 1, 
    "label": "Amended From", 
    "no_copy": 1, 
    "oldfieldname": "amended_from", 
    "oldfieldtype": "Data", 
+   "options": "Installation Note", 
    "permlevel": 0, 
    "print_hide": 1, 
    "read_only": 1
@@ -235,7 +236,7 @@
  "icon": "icon-wrench", 
  "idx": 1, 
  "is_submittable": 1, 
- "modified": "2014-05-27 03:49:11.449598", 
+ "modified": "2014-06-23 07:55:48.805241", 
  "modified_by": "Administrator", 
  "module": "Selling", 
  "name": "Installation Note", 
diff --git a/erpnext/selling/doctype/opportunity/opportunity.json b/erpnext/selling/doctype/opportunity/opportunity.json
index 249a0ff..be5f52b 100644
--- a/erpnext/selling/doctype/opportunity/opportunity.json
+++ b/erpnext/selling/doctype/opportunity/opportunity.json
@@ -385,12 +385,13 @@
   }, 
   {
    "fieldname": "amended_from", 
-   "fieldtype": "Data", 
+   "fieldtype": "Link", 
    "ignore_user_permissions": 1, 
    "label": "Amended From", 
    "no_copy": 1, 
    "oldfieldname": "amended_from", 
    "oldfieldtype": "Data", 
+   "options": "Opportunity", 
    "permlevel": 0, 
    "print_hide": 1, 
    "read_only": 1, 
@@ -409,7 +410,7 @@
  "icon": "icon-info-sign", 
  "idx": 1, 
  "is_submittable": 1, 
- "modified": "2014-05-27 03:49:14.057062", 
+ "modified": "2014-06-23 07:55:49.718301", 
  "modified_by": "Administrator", 
  "module": "Selling", 
  "name": "Opportunity", 
diff --git a/erpnext/selling/doctype/quotation/quotation.json b/erpnext/selling/doctype/quotation/quotation.json
index 1ae0adb..bdd27c4 100644
--- a/erpnext/selling/doctype/quotation/quotation.json
+++ b/erpnext/selling/doctype/quotation/quotation.json
@@ -139,12 +139,13 @@
   }, 
   {
    "fieldname": "amended_from", 
-   "fieldtype": "Data", 
+   "fieldtype": "Link", 
    "ignore_user_permissions": 1, 
    "label": "Amended From", 
    "no_copy": 1, 
    "oldfieldname": "amended_from", 
    "oldfieldtype": "Data", 
+   "options": "Quotation", 
    "permlevel": 0, 
    "print_hide": 1, 
    "read_only": 1, 
@@ -826,7 +827,7 @@
  "idx": 1, 
  "is_submittable": 1, 
  "max_attachments": 1, 
- "modified": "2014-06-19 15:59:30.019826", 
+ "modified": "2014-06-23 07:55:51.859025", 
  "modified_by": "Administrator", 
  "module": "Selling", 
  "name": "Quotation", 
diff --git a/erpnext/selling/doctype/sales_order/sales_order.json b/erpnext/selling/doctype/sales_order/sales_order.json
index a036370..6c330e6 100644
--- a/erpnext/selling/doctype/sales_order/sales_order.json
+++ b/erpnext/selling/doctype/sales_order/sales_order.json
@@ -112,13 +112,14 @@
   }, 
   {
    "fieldname": "amended_from", 
-   "fieldtype": "Data", 
+   "fieldtype": "Link", 
    "hidden": 1, 
    "ignore_user_permissions": 1, 
    "label": "Amended From", 
    "no_copy": 1, 
    "oldfieldname": "amended_from", 
    "oldfieldtype": "Data", 
+   "options": "Sales Order", 
    "permlevel": 0, 
    "print_hide": 1, 
    "read_only": 1, 
@@ -882,7 +883,7 @@
  "idx": 1, 
  "is_submittable": 1, 
  "issingle": 0, 
- "modified": "2014-06-19 16:00:06.626037", 
+ "modified": "2014-06-23 07:55:52.555192", 
  "modified_by": "Administrator", 
  "module": "Selling", 
  "name": "Sales Order", 
diff --git a/erpnext/stock/doctype/delivery_note/delivery_note.json b/erpnext/stock/doctype/delivery_note/delivery_note.json
index 690fd05..f1dc5a3 100644
--- a/erpnext/stock/doctype/delivery_note/delivery_note.json
+++ b/erpnext/stock/doctype/delivery_note/delivery_note.json
@@ -129,12 +129,13 @@
   {
    "allow_on_submit": 0, 
    "fieldname": "amended_from", 
-   "fieldtype": "Data", 
+   "fieldtype": "Link", 
    "ignore_user_permissions": 1, 
    "label": "Amended From", 
    "no_copy": 1, 
    "oldfieldname": "amended_from", 
    "oldfieldtype": "Data", 
+   "options": "Delivery Note", 
    "permlevel": 0, 
    "print_hide": 1, 
    "print_width": "150px", 
@@ -1007,7 +1008,7 @@
  "idx": 1, 
  "in_create": 0, 
  "is_submittable": 1, 
- "modified": "2014-06-19 16:00:47.326127", 
+ "modified": "2014-06-23 07:55:47.859869", 
  "modified_by": "Administrator", 
  "module": "Stock", 
  "name": "Delivery Note", 
diff --git a/erpnext/stock/doctype/material_request/material_request.json b/erpnext/stock/doctype/material_request/material_request.json
index 8e8f756..0f066da 100644
--- a/erpnext/stock/doctype/material_request/material_request.json
+++ b/erpnext/stock/doctype/material_request/material_request.json
@@ -41,12 +41,13 @@
   }, 
   {
    "fieldname": "amended_from", 
-   "fieldtype": "Data", 
+   "fieldtype": "Link", 
    "ignore_user_permissions": 1, 
    "label": "Amended From", 
    "no_copy": 1, 
    "oldfieldname": "amended_from", 
    "oldfieldtype": "Data", 
+   "options": "Material Request", 
    "permlevel": 0, 
    "print_hide": 1, 
    "print_width": "150px", 
@@ -229,7 +230,7 @@
  "icon": "icon-ticket", 
  "idx": 1, 
  "is_submittable": 1, 
- "modified": "2014-05-27 03:49:13.642995", 
+ "modified": "2014-06-23 07:55:49.393708", 
  "modified_by": "Administrator", 
  "module": "Stock", 
  "name": "Material Request", 
diff --git a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.json b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.json
index ae748ce..4ea3864 100755
--- a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.json
+++ b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.json
@@ -524,7 +524,7 @@
   }, 
   {
    "fieldname": "amended_from", 
-   "fieldtype": "Data", 
+   "fieldtype": "Link", 
    "hidden": 1, 
    "ignore_user_permissions": 1, 
    "label": "Amended From", 
@@ -762,7 +762,7 @@
  "icon": "icon-truck", 
  "idx": 1, 
  "is_submittable": 1, 
- "modified": "2014-06-19 15:58:37.932064", 
+ "modified": "2014-06-23 07:55:50.761516", 
  "modified_by": "Administrator", 
  "module": "Stock", 
  "name": "Purchase Receipt", 
diff --git a/erpnext/stock/doctype/stock_ledger_entry/stock_ledger_entry.json b/erpnext/stock/doctype/stock_ledger_entry/stock_ledger_entry.json
index cdddabe..f6bd010 100644
--- a/erpnext/stock/doctype/stock_ledger_entry/stock_ledger_entry.json
+++ b/erpnext/stock/doctype/stock_ledger_entry/stock_ledger_entry.json
@@ -91,11 +91,12 @@
   }, 
   {
    "fieldname": "voucher_type", 
-   "fieldtype": "Data", 
+   "fieldtype": "Link", 
    "in_filter": 1, 
    "label": "Voucher Type", 
    "oldfieldname": "voucher_type", 
    "oldfieldtype": "Data", 
+   "options": "DocType", 
    "permlevel": 0, 
    "print_width": "150px", 
    "read_only": 1, 
@@ -104,11 +105,12 @@
   }, 
   {
    "fieldname": "voucher_no", 
-   "fieldtype": "Data", 
+   "fieldtype": "Dynamic Link", 
    "in_filter": 1, 
    "label": "Voucher No", 
    "oldfieldname": "voucher_no", 
    "oldfieldtype": "Data", 
+   "options": "voucher_type", 
    "permlevel": 0, 
    "print_width": "150px", 
    "read_only": 1, 
@@ -264,7 +266,7 @@
  "icon": "icon-list", 
  "idx": 1, 
  "in_create": 1, 
- "modified": "2014-06-09 01:51:44.014466", 
+ "modified": "2014-06-23 08:07:56.370276", 
  "modified_by": "Administrator", 
  "module": "Stock", 
  "name": "Stock Ledger Entry", 
diff --git a/erpnext/support/doctype/customer_issue/customer_issue.json b/erpnext/support/doctype/customer_issue/customer_issue.json
index 8230f9c..b755135 100644
--- a/erpnext/support/doctype/customer_issue/customer_issue.json
+++ b/erpnext/support/doctype/customer_issue/customer_issue.json
@@ -379,13 +379,14 @@
   }, 
   {
    "fieldname": "amended_from", 
-   "fieldtype": "Data", 
+   "fieldtype": "Link", 
    "hidden": 1, 
    "ignore_user_permissions": 1, 
    "label": "Amended From", 
    "no_copy": 1, 
    "oldfieldname": "amended_from", 
    "oldfieldtype": "Data", 
+   "options": "Customer Issue", 
    "permlevel": 0, 
    "print_hide": 1, 
    "width": "150px"
@@ -394,7 +395,7 @@
  "icon": "icon-bug", 
  "idx": 1, 
  "is_submittable": 0, 
- "modified": "2014-05-27 03:49:09.483145", 
+ "modified": "2014-06-23 07:55:47.488335", 
  "modified_by": "Administrator", 
  "module": "Support", 
  "name": "Customer Issue", 
diff --git a/erpnext/support/doctype/maintenance_visit/maintenance_visit.json b/erpnext/support/doctype/maintenance_visit/maintenance_visit.json
index 4a13e40..743d210 100644
--- a/erpnext/support/doctype/maintenance_visit/maintenance_visit.json
+++ b/erpnext/support/doctype/maintenance_visit/maintenance_visit.json
@@ -190,12 +190,13 @@
   }, 
   {
    "fieldname": "amended_from", 
-   "fieldtype": "Data", 
+   "fieldtype": "Link", 
    "ignore_user_permissions": 1, 
    "label": "Amended From", 
    "no_copy": 1, 
    "oldfieldname": "amended_from", 
    "oldfieldtype": "Data", 
+   "options": "Maintenance Visit", 
    "permlevel": 0, 
    "print_hide": 1, 
    "read_only": 1, 
@@ -278,7 +279,7 @@
  "icon": "icon-file-text", 
  "idx": 1, 
  "is_submittable": 1, 
- "modified": "2014-05-27 03:49:13.466221", 
+ "modified": "2014-06-23 07:55:49.200714", 
  "modified_by": "Administrator", 
  "module": "Support", 
  "name": "Maintenance Visit",