Naming Series Property Setter Patch
This commit is contained in:
parent
b569930b2a
commit
8b2dfcff29
@ -86,44 +86,47 @@
|
||||
"oldfieldtype": "Text",
|
||||
"permlevel": 0
|
||||
},
|
||||
{
|
||||
"fieldname": "against_voucher",
|
||||
"fieldtype": "Data",
|
||||
"in_filter": 1,
|
||||
"label": "Against Voucher",
|
||||
"oldfieldname": "against_voucher",
|
||||
"oldfieldtype": "Data",
|
||||
"permlevel": 0,
|
||||
"search_index": 0
|
||||
},
|
||||
{
|
||||
"fieldname": "against_voucher_type",
|
||||
"fieldtype": "Data",
|
||||
"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",
|
||||
"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",
|
||||
"fieldtype": "Link",
|
||||
"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",
|
||||
"options": "DocType",
|
||||
"permlevel": 0,
|
||||
"search_index": 0
|
||||
},
|
||||
{
|
||||
"fieldname": "voucher_no",
|
||||
"fieldtype": "Data",
|
||||
"fieldtype": "Dynamic Link",
|
||||
"in_filter": 1,
|
||||
"label": "Voucher No",
|
||||
"oldfieldname": "voucher_no",
|
||||
"oldfieldtype": "Data",
|
||||
"options": "voucher_type",
|
||||
"permlevel": 0,
|
||||
"search_index": 1
|
||||
},
|
||||
@ -186,7 +189,7 @@
|
||||
"icon": "icon-list",
|
||||
"idx": 1,
|
||||
"in_create": 1,
|
||||
"modified": "2014-06-19 01:51:29.340077",
|
||||
"modified": "2014-06-23 08:07:30.678730",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Accounts",
|
||||
"name": "GL Entry",
|
||||
|
@ -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",
|
||||
|
@ -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",
|
||||
|
@ -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",
|
||||
|
@ -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",
|
||||
|
@ -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",
|
||||
|
@ -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",
|
||||
|
@ -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",
|
||||
|
@ -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",
|
||||
|
@ -210,12 +210,13 @@
|
||||
},
|
||||
{
|
||||
"fieldname": "amended_from",
|
||||
"fieldtype": "Data",
|
||||
"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
|
||||
}
|
||||
@ -224,7 +225,7 @@
|
||||
"idx": 1,
|
||||
"in_create": 0,
|
||||
"is_submittable": 1,
|
||||
"modified": "2014-05-27 03:49:15.008942",
|
||||
"modified": "2014-06-23 07:55:50.092300",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Manufacturing",
|
||||
"name": "Production Order",
|
||||
|
@ -63,3 +63,4 @@ erpnext.patches.v4_0.create_price_list_if_missing
|
||||
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
|
||||
|
0
erpnext/patches/repair_tools/__init__.py
Normal file
0
erpnext/patches/repair_tools/__init__.py
Normal file
@ -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)
|
||||
|
98
erpnext/patches/v4_0/set_naming_series_property_setter.py
Normal file
98
erpnext/patches/v4_0/set_naming_series_property_setter.py
Normal file
@ -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]
|
@ -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",
|
||||
|
@ -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",
|
||||
|
@ -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",
|
||||
|
@ -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",
|
||||
|
@ -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",
|
||||
|
@ -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",
|
||||
|
@ -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",
|
||||
|
@ -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",
|
||||
|
@ -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",
|
||||
|
@ -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",
|
||||
|
Loading…
Reference in New Issue
Block a user