blob: d4f73e56e9c053906b09517a2d5478ff637a3dfa [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 Mehta919a74a2017-06-22 16:37:04 +053011def setup(company=None):
Rushabh Mehtab3c8f442017-06-21 17:22:38 +053012 make_custom_fields()
13 make_fixtures()
14 add_permissions()
Rushabh Mehta919a74a2017-06-22 16:37:04 +053015 add_custom_roles_for_reports()
Rushabh Mehtab3c8f442017-06-21 17:22:38 +053016 add_hsn_codes()
Rushabh Mehta919a74a2017-06-22 16:37:04 +053017 update_address_template()
18
19def update_address_template():
20 with open(os.path.join(os.path.dirname(__file__), 'address_template.html'), 'r') as f:
21 html = f.read()
22
23 address_template = frappe.db.get_value('Address Template', 'India')
24 if address_template:
25 frappe.db.set_value('Address Template', 'India', 'template', html)
26 else:
27 # make new html template for India
Rushabh Mehta9b09ff22017-06-27 12:17:39 +053028 frappe.get_doc(dict(
Rushabh Mehta919a74a2017-06-22 16:37:04 +053029 doctype='Address Template',
30 country='India',
31 template=html
Rushabh Mehta9b09ff22017-06-27 12:17:39 +053032 )).insert()
Rushabh Mehtab3c8f442017-06-21 17:22:38 +053033
34def add_hsn_codes():
Rushabh Mehta919a74a2017-06-22 16:37:04 +053035 if frappe.db.count('GST HSN Code') > 100:
36 return
37
Rushabh Mehtab3c8f442017-06-21 17:22:38 +053038 with open(os.path.join(os.path.dirname(__file__), 'hsn_code_data.json'), 'r') as f:
39 hsn_codes = json.loads(f.read())
40
Rushabh Mehta919a74a2017-06-22 16:37:04 +053041 frappe.db.commit()
Rushabh Mehtab3c8f442017-06-21 17:22:38 +053042 frappe.db.sql('truncate `tabGST HSN Code`')
43
44 for d in hsn_codes:
45 hsn_code = frappe.new_doc('GST HSN Code')
46 hsn_code.update(d)
47 hsn_code.name = hsn_code.hsn_code
48 hsn_code.db_insert()
49
Rushabh Mehta919a74a2017-06-22 16:37:04 +053050 frappe.db.commit()
51
52def add_custom_roles_for_reports():
53 for report_name in ('GST Sales Register', 'GST Purchase Register',
54 'GST Itemised Sales Register', 'GST Itemised Purchase Register'):
55
Rushabh Mehta919a74a2017-06-22 16:37:04 +053056 if not frappe.db.get_value('Custom Role', dict(report=report_name)):
57 frappe.get_doc(dict(
58 doctype='Custom Role',
59 report=report_name,
60 roles= [
61 dict(role='Accounts User'),
62 dict(role='Accounts Manager')
63 ]
64 )).insert()
65
Rushabh Mehtab3c8f442017-06-21 17:22:38 +053066def add_permissions():
Rushabh Mehta00ae4242017-06-27 17:31:41 +053067 for doctype in ('GST HSN Code', 'GST Settings'):
Rushabh Mehtab3c8f442017-06-21 17:22:38 +053068 add_permission(doctype, 'Accounts Manager', 0)
69 add_permission(doctype, 'All', 0)
70
71def make_custom_fields():
72 custom_fields = {
73 'Address': [
Rushabh Mehta919a74a2017-06-22 16:37:04 +053074 dict(fieldname='gstin', label='Party GSTIN', fieldtype='Data',
75 insert_after='fax'),
Rushabh Mehtab3c8f442017-06-21 17:22:38 +053076 dict(fieldname='gst_state', label='GST State', fieldtype='Select',
77 options='\n'.join(states), insert_after='gstin')
78 ],
79 'Purchase Invoice': [
80 dict(fieldname='supplier_gstin', label='Supplier GSTIN',
Rushabh Mehta919a74a2017-06-22 16:37:04 +053081 fieldtype='Data', insert_after='supplier_address',
82 options='supplier_address.gstin'),
Rushabh Mehtab3c8f442017-06-21 17:22:38 +053083 dict(fieldname='company_gstin', label='Company GSTIN',
Rushabh Mehta919a74a2017-06-22 16:37:04 +053084 fieldtype='Data', insert_after='shipping_address',
85 options='shipping_address.gstin'),
Rushabh Mehtab3c8f442017-06-21 17:22:38 +053086 ],
87 'Sales Invoice': [
88 dict(fieldname='customer_gstin', label='Customer GSTIN',
Rushabh Mehta919a74a2017-06-22 16:37:04 +053089 fieldtype='Data', insert_after='shipping_address',
90 options='shipping_address_name.gstin'),
Rushabh Mehtab3c8f442017-06-21 17:22:38 +053091 dict(fieldname='company_gstin', label='Company GSTIN',
Rushabh Mehta919a74a2017-06-22 16:37:04 +053092 fieldtype='Data', insert_after='company_address',
93 options='company_address.gstin'),
Rushabh Mehtab3c8f442017-06-21 17:22:38 +053094 ],
95 'Item': [
96 dict(fieldname='gst_hsn_code', label='GST HSN Code',
97 fieldtype='Link', options='GST HSN Code', insert_after='item_group'),
98 ],
99 'Sales Invoice Item': [
100 dict(fieldname='gst_hsn_code', label='GST HSN Code',
Rushabh Mehta919a74a2017-06-22 16:37:04 +0530101 fieldtype='Data', options='item_code.gst_hsn_code',
102 insert_after='income_account'),
Rushabh Mehtab3c8f442017-06-21 17:22:38 +0530103 ],
104 'Purchase Invoice Item': [
105 dict(fieldname='gst_hsn_code', label='GST HSN Code',
Rushabh Mehta919a74a2017-06-22 16:37:04 +0530106 fieldtype='Data', options='item_code.gst_hsn_code',
107 insert_after='expense_account'),
Rushabh Mehtab3c8f442017-06-21 17:22:38 +0530108 ]
109 }
110
111 for doctype, fields in custom_fields.items():
112 for df in fields:
113 create_custom_field(doctype, df)
114
115def make_fixtures():
116 docs = [
117 {'doctype': 'Salary Component', 'salary_component': 'Professional Tax', 'description': 'Professional Tax', 'type': 'Deduction'},
118 {'doctype': 'Salary Component', 'salary_component': 'Provident Fund', 'description': 'Provident fund', 'type': 'Deduction'},
119 {'doctype': 'Salary Component', 'salary_component': 'House Rent Allowance', 'description': 'House Rent Allowance', 'type': 'Earning'},
120 {'doctype': 'Salary Component', 'salary_component': 'Basic', 'description': 'Basic', 'type': 'Earning'},
121 {'doctype': 'Salary Component', 'salary_component': 'Arrear', 'description': 'Arrear', 'type': 'Earning'},
122 {'doctype': 'Salary Component', 'salary_component': 'Leave Encashment', 'description': 'Leave Encashment', 'type': 'Earning'}
123 ]
124
125 for d in docs:
126 try:
127 doc = frappe.get_doc(d)
128 doc.flags.ignore_permissions = True
129 doc.insert()
130 except frappe.NameError:
131 pass