blob: 46cfdb805ba435776b24d755b4ca35f62b436558 [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()
Nabin Hait852cb642017-07-05 12:58:19 +053017 add_print_formats()
Rushabh Mehta01659272017-06-27 18:05:17 +053018 if not patch:
19 make_fixtures()
Rushabh Mehta919a74a2017-06-22 16:37:04 +053020
21def update_address_template():
22 with open(os.path.join(os.path.dirname(__file__), 'address_template.html'), 'r') as f:
23 html = f.read()
24
25 address_template = frappe.db.get_value('Address Template', 'India')
26 if address_template:
27 frappe.db.set_value('Address Template', 'India', 'template', html)
28 else:
29 # make new html template for India
Rushabh Mehta9b09ff22017-06-27 12:17:39 +053030 frappe.get_doc(dict(
Rushabh Mehta919a74a2017-06-22 16:37:04 +053031 doctype='Address Template',
32 country='India',
33 template=html
Rushabh Mehta9b09ff22017-06-27 12:17:39 +053034 )).insert()
Rushabh Mehtab3c8f442017-06-21 17:22:38 +053035
36def add_hsn_codes():
Rushabh Mehta919a74a2017-06-22 16:37:04 +053037 if frappe.db.count('GST HSN Code') > 100:
38 return
39
Rushabh Mehtab3c8f442017-06-21 17:22:38 +053040 with open(os.path.join(os.path.dirname(__file__), 'hsn_code_data.json'), 'r') as f:
41 hsn_codes = json.loads(f.read())
42
Rushabh Mehta919a74a2017-06-22 16:37:04 +053043 frappe.db.commit()
Rushabh Mehtab3c8f442017-06-21 17:22:38 +053044 frappe.db.sql('truncate `tabGST HSN Code`')
45
46 for d in hsn_codes:
47 hsn_code = frappe.new_doc('GST HSN Code')
48 hsn_code.update(d)
49 hsn_code.name = hsn_code.hsn_code
50 hsn_code.db_insert()
51
Rushabh Mehta919a74a2017-06-22 16:37:04 +053052 frappe.db.commit()
53
54def add_custom_roles_for_reports():
55 for report_name in ('GST Sales Register', 'GST Purchase Register',
56 'GST Itemised Sales Register', 'GST Itemised Purchase Register'):
57
Rushabh Mehta919a74a2017-06-22 16:37:04 +053058 if not frappe.db.get_value('Custom Role', dict(report=report_name)):
59 frappe.get_doc(dict(
60 doctype='Custom Role',
61 report=report_name,
62 roles= [
63 dict(role='Accounts User'),
64 dict(role='Accounts Manager')
65 ]
66 )).insert()
67
Rushabh Mehtab3c8f442017-06-21 17:22:38 +053068def add_permissions():
Rushabh Mehta00ae4242017-06-27 17:31:41 +053069 for doctype in ('GST HSN Code', 'GST Settings'):
Rushabh Mehtab3c8f442017-06-21 17:22:38 +053070 add_permission(doctype, 'Accounts Manager', 0)
71 add_permission(doctype, 'All', 0)
72
Nabin Hait852cb642017-07-05 12:58:19 +053073def add_print_formats():
74 frappe.reload_doc("regional", "print_format", "gst_tax_invoice")
75
Rushabh Mehtab3c8f442017-06-21 17:22:38 +053076def make_custom_fields():
77 custom_fields = {
78 'Address': [
Rushabh Mehta919a74a2017-06-22 16:37:04 +053079 dict(fieldname='gstin', label='Party GSTIN', fieldtype='Data',
80 insert_after='fax'),
Rushabh Mehtab3c8f442017-06-21 17:22:38 +053081 dict(fieldname='gst_state', label='GST State', fieldtype='Select',
82 options='\n'.join(states), insert_after='gstin')
83 ],
84 'Purchase Invoice': [
85 dict(fieldname='supplier_gstin', label='Supplier GSTIN',
Rushabh Mehta919a74a2017-06-22 16:37:04 +053086 fieldtype='Data', insert_after='supplier_address',
Nabin Hait852cb642017-07-05 12:58:19 +053087 options='supplier_address.gstin', print_hide=1),
Rushabh Mehtab3c8f442017-06-21 17:22:38 +053088 dict(fieldname='company_gstin', label='Company GSTIN',
Rushabh Mehta919a74a2017-06-22 16:37:04 +053089 fieldtype='Data', insert_after='shipping_address',
Nabin Hait852cb642017-07-05 12:58:19 +053090 options='shipping_address.gstin', print_hide=1),
Rushabh Mehtab3c8f442017-06-21 17:22:38 +053091 ],
92 'Sales Invoice': [
93 dict(fieldname='customer_gstin', label='Customer GSTIN',
Rushabh Mehta919a74a2017-06-22 16:37:04 +053094 fieldtype='Data', insert_after='shipping_address',
Nabin Hait852cb642017-07-05 12:58:19 +053095 options='shipping_address_name.gstin', print_hide=1),
Rushabh Mehtab3c8f442017-06-21 17:22:38 +053096 dict(fieldname='company_gstin', label='Company GSTIN',
Rushabh Mehta919a74a2017-06-22 16:37:04 +053097 fieldtype='Data', insert_after='company_address',
Nabin Hait852cb642017-07-05 12:58:19 +053098 options='company_address.gstin', print_hide=1),
Rushabh Mehtab3c8f442017-06-21 17:22:38 +053099 ],
100 'Item': [
Nabin Hait852cb642017-07-05 12:58:19 +0530101 dict(fieldname='gst_hsn_code', label='HSN/SAC Code',
Rushabh Mehtab3c8f442017-06-21 17:22:38 +0530102 fieldtype='Link', options='GST HSN Code', insert_after='item_group'),
103 ],
104 'Sales Invoice Item': [
Nabin Hait852cb642017-07-05 12:58:19 +0530105 dict(fieldname='gst_hsn_code', label='HSN/SAC Code',
Rushabh Mehta919a74a2017-06-22 16:37:04 +0530106 fieldtype='Data', options='item_code.gst_hsn_code',
Nabin Hait852cb642017-07-05 12:58:19 +0530107 insert_after='description'),
Rushabh Mehtab3c8f442017-06-21 17:22:38 +0530108 ],
109 'Purchase Invoice Item': [
Nabin Hait852cb642017-07-05 12:58:19 +0530110 dict(fieldname='gst_hsn_code', label='HSN/SAC Code',
Rushabh Mehta919a74a2017-06-22 16:37:04 +0530111 fieldtype='Data', options='item_code.gst_hsn_code',
Nabin Hait852cb642017-07-05 12:58:19 +0530112 insert_after='description'),
Rushabh Mehtab3c8f442017-06-21 17:22:38 +0530113 ]
114 }
115
116 for doctype, fields in custom_fields.items():
117 for df in fields:
118 create_custom_field(doctype, df)
Nabin Hait852cb642017-07-05 12:58:19 +0530119
Rushabh Mehtab3c8f442017-06-21 17:22:38 +0530120def make_fixtures():
121 docs = [
122 {'doctype': 'Salary Component', 'salary_component': 'Professional Tax', 'description': 'Professional Tax', 'type': 'Deduction'},
123 {'doctype': 'Salary Component', 'salary_component': 'Provident Fund', 'description': 'Provident fund', 'type': 'Deduction'},
124 {'doctype': 'Salary Component', 'salary_component': 'House Rent Allowance', 'description': 'House Rent Allowance', 'type': 'Earning'},
125 {'doctype': 'Salary Component', 'salary_component': 'Basic', 'description': 'Basic', 'type': 'Earning'},
126 {'doctype': 'Salary Component', 'salary_component': 'Arrear', 'description': 'Arrear', 'type': 'Earning'},
127 {'doctype': 'Salary Component', 'salary_component': 'Leave Encashment', 'description': 'Leave Encashment', 'type': 'Earning'}
128 ]
129
130 for d in docs:
131 try:
132 doc = frappe.get_doc(d)
133 doc.flags.ignore_permissions = True
134 doc.insert()
135 except frappe.NameError:
136 pass