From d532d2f64fd3f54d8d8a2f39a544203d6c2ceb29 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Mon, 9 Jun 2014 15:59:04 +0530 Subject: [PATCH] create custom fields for india specific fields --- erpnext/patches.txt | 2 +- ...custom_fields_for_india_specific_fields.py | 63 +++++++++++++++++++ .../v4_0/remove_india_specific_fields.py | 30 --------- 3 files changed, 64 insertions(+), 31 deletions(-) create mode 100644 erpnext/patches/v4_0/create_custom_fields_for_india_specific_fields.py delete mode 100644 erpnext/patches/v4_0/remove_india_specific_fields.py diff --git a/erpnext/patches.txt b/erpnext/patches.txt index fba05546a5..4d69a0fd4f 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -39,7 +39,6 @@ execute:frappe.delete_doc("Page", "Financial Statements") execute:frappe.delete_doc("DocType", "Stock Ledger") execute:frappe.db.sql("update `tabJournal Voucher` set voucher_type='Journal Entry' where ifnull(voucher_type, '')=''") execute:frappe.delete_doc("DocType", "Grade") -erpnext.patches.v4_0.remove_india_specific_fields execute:frappe.db.sql("delete from `tabWebsite Item Group` where ifnull(item_group, '')=''") execute:frappe.delete_doc("Print Format", "SalesInvoice") execute:import frappe.defaults;frappe.defaults.clear_default("price_list_currency") @@ -56,3 +55,4 @@ erpnext.patches.v4_0.reset_permissions_for_masters erpnext.patches.v4_0.update_tax_amount_after_discount execute:frappe.reset_perms("GL Entry") #2014-06-09 execute:frappe.reset_perms("Stock Ledger Entry") #2014-06-09 +erpnext.patches.v4_0.create_custom_fields_for_india_specific_fields diff --git a/erpnext/patches/v4_0/create_custom_fields_for_india_specific_fields.py b/erpnext/patches/v4_0/create_custom_fields_for_india_specific_fields.py new file mode 100644 index 0000000000..eeb0f5b904 --- /dev/null +++ b/erpnext/patches/v4_0/create_custom_fields_for_india_specific_fields.py @@ -0,0 +1,63 @@ +# 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.custom_field.custom_field import create_custom_field_if_values_exist + +def execute(): + frappe.reload_doc("stock", "doctype", "purchase_receipt") + frappe.reload_doc("hr", "doctype", "employee") + frappe.reload_doc("hr", "doctype", "salary_slip") + + india_specific_fields = { + "Purchase Receipt": [{ + "label": "Supplier Shipment No", + "fieldname": "challan_no", + "fieldtype": "Data", + "insert_after": "is_subcontracted" + }, { + "label": "Supplier Shipment Date", + "fieldname": "challan_date", + "fieldtype": "Date", + "insert_after": "challan_no" + }], + "Employee": [{ + "label": "PAN Number", + "fieldname": "pan_number", + "fieldtype": "Data", + "insert_after": "company_email" + }, { + "label": "Gratuity LIC Id", + "fieldname": "gratuity_lic_id", + "fieldtype": "Data", + "insert_after": "pan_number" + }, { + "label": "Esic Card No", + "fieldname": "esic_card_no", + "fieldtype": "Data", + "insert_after": "bank_ac_no" + }, { + "label": "PF Number", + "fieldname": "pf_number", + "fieldtype": "Data", + "insert_after": "esic_card_no" + }], + "Salary Slip": [{ + "label": "Esic No", + "fieldname": "esic_no", + "fieldtype": "Data", + "insert_after": "letter_head", + "permlevel": 1 + }, { + "label": "PF Number", + "fieldname": "pf_no", + "fieldtype": "Data", + "insert_after": "esic_no", + "permlevel": 1 + }] + } + + for dt, docfields in india_specific_fields.items(): + for df in docfields: + create_custom_field_if_values_exist(dt, df) diff --git a/erpnext/patches/v4_0/remove_india_specific_fields.py b/erpnext/patches/v4_0/remove_india_specific_fields.py deleted file mode 100644 index 3070959f34..0000000000 --- a/erpnext/patches/v4_0/remove_india_specific_fields.py +++ /dev/null @@ -1,30 +0,0 @@ -# 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.custom_field.custom_field import create_custom_field_if_values_exist - -def execute(): - frappe.db.sql("delete from tabDocField where parent='Salary Slip' and options='Grade'") - docfields = { - ("Purchase Receipt", "challan_no"): frappe.get_meta("Purchase Receipt").get_field("challan_no"), - ("Purchase Receipt", "challan_date"): frappe.get_meta("Purchase Receipt").get_field("challan_date"), - ("Employee", "pf_number"): frappe.get_meta("Employee").get_field("pf_number"), - ("Employee", "pan_number"): frappe.get_meta("Employee").get_field("pan_number"), - ("Employee", "gratuity_lic_id"): frappe.get_meta("Employee").get_field("gratuity_lic_id"), - ("Employee", "esic_card_no"): frappe.get_meta("Employee").get_field("esic_card_no"), - ("Salary Slip", "esic_no"): frappe.get_meta("Salary Slip").get_field("esic_no"), - ("Salary Slip", "pf_no"): frappe.get_meta("Salary Slip").get_field("pf_no") - } - - for (doctype, fieldname), df in docfields.items(): - if not df: - continue - opts = df.as_dict() - if df.idx >= 2: - opts["insert_after"] = frappe.get_meta(doctype).get("fields")[df.idx - 2].fieldname - - frappe.delete_doc("DocField", df.name) - frappe.clear_cache(doctype=doctype) - create_custom_field_if_values_exist(doctype, opts)