blob: a9f3a30d105f243b32181ba358d7d7851e0d2bff [file] [log] [blame]
Rushabh Mehtab3c8f442017-06-21 17:22:38 +05301# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
2# License: GNU General Public License v3. See license.txt
3
4from __future__ import unicode_literals
5
6import frappe, os, json
7from frappe.custom.doctype.custom_field.custom_field import create_custom_field
8from frappe.permissions import add_permission
9from erpnext.regional.india import states
10
Rushabh Mehta01659272017-06-27 18:05:17 +053011def setup(company=None, patch=True):
Rushabh Mehtab3c8f442017-06-21 17:22:38 +053012 make_custom_fields()
Rushabh Mehtab3c8f442017-06-21 17:22:38 +053013 add_permissions()
Rushabh Mehta919a74a2017-06-22 16:37:04 +053014 add_custom_roles_for_reports()
Rushabh Mehtab3c8f442017-06-21 17:22:38 +053015 add_hsn_codes()
Rushabh Mehta919a74a2017-06-22 16:37:04 +053016 update_address_template()
Rushabh Mehta01659272017-06-27 18:05:17 +053017 if not patch:
18 make_fixtures()
Rushabh Mehta919a74a2017-06-22 16:37:04 +053019
20def update_address_template():
21 with open(os.path.join(os.path.dirname(__file__), 'address_template.html'), 'r') as f:
22 html = f.read()
23
24 address_template = frappe.db.get_value('Address Template', 'India')
25 if address_template:
26 frappe.db.set_value('Address Template', 'India', 'template', html)
27 else:
28 # make new html template for India
Rushabh Mehta9b09ff22017-06-27 12:17:39 +053029 frappe.get_doc(dict(
Rushabh Mehta919a74a2017-06-22 16:37:04 +053030 doctype='Address Template',
31 country='India',
32 template=html
Rushabh Mehta9b09ff22017-06-27 12:17:39 +053033 )).insert()
Rushabh Mehtab3c8f442017-06-21 17:22:38 +053034
35def add_hsn_codes():
Rushabh Mehta919a74a2017-06-22 16:37:04 +053036 if frappe.db.count('GST HSN Code') > 100:
37 return
38
Rushabh Mehtab3c8f442017-06-21 17:22:38 +053039 with open(os.path.join(os.path.dirname(__file__), 'hsn_code_data.json'), 'r') as f:
40 hsn_codes = json.loads(f.read())
41
Rushabh Mehta919a74a2017-06-22 16:37:04 +053042 frappe.db.commit()
Rushabh Mehtab3c8f442017-06-21 17:22:38 +053043 frappe.db.sql('truncate `tabGST HSN Code`')
44
45 for d in hsn_codes:
46 hsn_code = frappe.new_doc('GST HSN Code')
47 hsn_code.update(d)
48 hsn_code.name = hsn_code.hsn_code
49 hsn_code.db_insert()
50
Rushabh Mehta919a74a2017-06-22 16:37:04 +053051 frappe.db.commit()
52
53def add_custom_roles_for_reports():
54 for report_name in ('GST Sales Register', 'GST Purchase Register',
55 'GST Itemised Sales Register', 'GST Itemised Purchase Register'):
56
Rushabh Mehta919a74a2017-06-22 16:37:04 +053057 if not frappe.db.get_value('Custom Role', dict(report=report_name)):
58 frappe.get_doc(dict(
59 doctype='Custom Role',
60 report=report_name,
61 roles= [
62 dict(role='Accounts User'),
63 dict(role='Accounts Manager')
64 ]
65 )).insert()
66
Rushabh Mehtab3c8f442017-06-21 17:22:38 +053067def add_permissions():
Rushabh Mehta00ae4242017-06-27 17:31:41 +053068 for doctype in ('GST HSN Code', 'GST Settings'):
Rushabh Mehtab3c8f442017-06-21 17:22:38 +053069 add_permission(doctype, 'Accounts Manager', 0)
70 add_permission(doctype, 'All', 0)
71
72def make_custom_fields():
73 custom_fields = {
74 'Address': [
Rushabh Mehta919a74a2017-06-22 16:37:04 +053075 dict(fieldname='gstin', label='Party GSTIN', fieldtype='Data',
76 insert_after='fax'),
Rushabh Mehtab3c8f442017-06-21 17:22:38 +053077 dict(fieldname='gst_state', label='GST State', fieldtype='Select',
78 options='\n'.join(states), insert_after='gstin')
79 ],
80 'Purchase Invoice': [
81 dict(fieldname='supplier_gstin', label='Supplier GSTIN',
Rushabh Mehta919a74a2017-06-22 16:37:04 +053082 fieldtype='Data', insert_after='supplier_address',
83 options='supplier_address.gstin'),
Rushabh Mehtab3c8f442017-06-21 17:22:38 +053084 dict(fieldname='company_gstin', label='Company GSTIN',
Rushabh Mehta919a74a2017-06-22 16:37:04 +053085 fieldtype='Data', insert_after='shipping_address',
86 options='shipping_address.gstin'),
Rushabh Mehtab3c8f442017-06-21 17:22:38 +053087 ],
88 'Sales Invoice': [
89 dict(fieldname='customer_gstin', label='Customer GSTIN',
Rushabh Mehta919a74a2017-06-22 16:37:04 +053090 fieldtype='Data', insert_after='shipping_address',
91 options='shipping_address_name.gstin'),
Rushabh Mehtab3c8f442017-06-21 17:22:38 +053092 dict(fieldname='company_gstin', label='Company GSTIN',
Rushabh Mehta919a74a2017-06-22 16:37:04 +053093 fieldtype='Data', insert_after='company_address',
94 options='company_address.gstin'),
Rushabh Mehtab3c8f442017-06-21 17:22:38 +053095 ],
96 'Item': [
97 dict(fieldname='gst_hsn_code', label='GST HSN Code',
98 fieldtype='Link', options='GST HSN Code', insert_after='item_group'),
99 ],
100 'Sales Invoice Item': [
101 dict(fieldname='gst_hsn_code', label='GST HSN Code',
Rushabh Mehta919a74a2017-06-22 16:37:04 +0530102 fieldtype='Data', options='item_code.gst_hsn_code',
103 insert_after='income_account'),
Rushabh Mehtab3c8f442017-06-21 17:22:38 +0530104 ],
105 'Purchase Invoice Item': [
106 dict(fieldname='gst_hsn_code', label='GST HSN Code',
Rushabh Mehta919a74a2017-06-22 16:37:04 +0530107 fieldtype='Data', options='item_code.gst_hsn_code',
108 insert_after='expense_account'),
Rushabh Mehtab3c8f442017-06-21 17:22:38 +0530109 ]
110 }
111
112 for doctype, fields in custom_fields.items():
113 for df in fields:
114 create_custom_field(doctype, df)
115
116def make_fixtures():
117 docs = [
118 {'doctype': 'Salary Component', 'salary_component': 'Professional Tax', 'description': 'Professional Tax', 'type': 'Deduction'},
119 {'doctype': 'Salary Component', 'salary_component': 'Provident Fund', 'description': 'Provident fund', 'type': 'Deduction'},
120 {'doctype': 'Salary Component', 'salary_component': 'House Rent Allowance', 'description': 'House Rent Allowance', 'type': 'Earning'},
121 {'doctype': 'Salary Component', 'salary_component': 'Basic', 'description': 'Basic', 'type': 'Earning'},
122 {'doctype': 'Salary Component', 'salary_component': 'Arrear', 'description': 'Arrear', 'type': 'Earning'},
123 {'doctype': 'Salary Component', 'salary_component': 'Leave Encashment', 'description': 'Leave Encashment', 'type': 'Earning'}
124 ]
125
126 for d in docs:
127 try:
128 doc = frappe.get_doc(d)
129 doc.flags.ignore_permissions = True
130 doc.insert()
131 except frappe.NameError:
132 pass