brotherton-erpnext/erpnext/regional/india/setup.py

253 lines
10 KiB
Python
Raw Normal View History

2017-06-21 11:52:38 +00:00
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
import frappe, os, json
[domain] Healthcare (#10664) * Medical module for erpnext * Changes in core for Medical module * patient registration updated * fix - appointment invioce - fields missing * pages- indicator instead of bg-color * Lab Test field renamed service type * Department added Lab Test * procedure name in prescription * fixes sample collection * filter disabled patient * fix patient admission * updated patient age * availability check msg updated * fixes, removed procedure from invoice * sample print renamed * fixes, validation * service desk physician in filter * refactor scheduler * Appointment -field property - set only once = 1 * Appointment - Mark closed and pending buttons removed * Appointment - readonly = 1 if value set * Appointment - availabilty * Appointment - Cancel - info - cancel invoice * Appointment - set pending appointments * Dosage form - new DT * Drug Prescription - Dosage form added * Facility - Floor - removed from Fecility * Floor - removed * Lab Test Template - item creation validation * Procedure - Create Procedure * Procedure Appointment - new DT * Service Unit - Floor reference removed * Zone Fcilities - Unused DT removed * Appointment Desk - fixed * Service Desk - method pointing from procedure changed to procedure_appointment * Consultation print - got featured * Consultation - removed patient refernce to procedure prescription * Procedure Prescription - removed patient refernce * Lab Test - Changed field properties and value * Lab Test - field property changed * Lab Test - methods rewrite - lab test doc creation * Lab Test - create lab test from invoice and consultaion - got changed * Button History changed to Medical Record * Service Desk - Updated * Notification - Procedure Appointment * fix-get procedure prescription * fix field added to test prescription * msgprint on invoice creation * fix data on install * Merge branch erpnext/develop * fixes- minor * Setup wizard - Create Sensitivity * Appointment - Validate and Save if there is no schedule for Physician * Consultation - Button create vital signs and medical record * Review Type - New DocType * Review Detail and Treatment Plan - Childs - Consultation * Patient Medical Record - field Attach doc * Consultation - New Fields * Consultation - Manage new Fields - Medical record add action * Patient Relation - Child DocType - Patient * Patient - Patient Relation added * Patient - collapsible = 1 * Laboratory Settings - fields - message for lab test * Laboratory Settings - get message for lab test * SMS text for lab test and invoice test report * Procedure Stock Detail - Stock detail for Procedure and Template * Template Stage Detail - Stage detail for Procedure Template * Procedure Stage Detail - Stage detail for Procedure * Service Unit - field - warehouse * Scheduler - msg - content changed * Laboratory Settings - defualt - msg content * Invoice Test Report - msg print * Print Format-Changed-Consultation-Invoice Test Report-Lab Test * OP Settings - Expnse Account for Stock Entry in Procedure * Procedure and Procedure Template - Manage Stock Stage and Sample Collection * Procedure Appointment - Manage Stock and Stage * Lab Test - fixed - resource not find * Invoice Test Report - fixed - resource not find * Procedure - doc reload after insert * Patient Medical Record - fixed - refernce missed * Create Vital Signs -on client side * Rename module Medical to Healthcare * Remove In Patient (IP) Feature. * Rename - Procedure to Clinical Procedure * Remove spaces in Naming Series * Rename Duration to Drug Prescription Duration * Duration to Drug Prescription Duration * Merge All Settings to Healthcare Settings * Healthcare settings - import fixed * Procedure related documents are removed * Appointment Desk and Sevrvice Desk are removed * Consultation - minimal * Consultation - minimal * Consultation - minimal - patient detials in collapsible section * Message Print to Alerts * Patient - some fields removed * Patient - create consultation - message print to alerts * Consultation - show patient details updated * Setup wizard - Duration to Drug Prescritpion Duration * Healthcare Settings - patient registration - fee collection * Lab Test - Create Sales Invoice bug fixed * Healthcare menu rearranged * Healthcare Settings - Optimised and Rearragnged * Healthcare Settings - Expense account removed * Receivable account removed from patient * Patient - Optimised and Rearragnged * Removed Referring Physician * Healthcare Settings - bold headings removed * Physician - Patient - Fields are Segregated * Remove Service Unit * Remove - Service Type * Consultation invoice * Lab Test - invoice * Patient - Invoice * Rename Appointment to Patient Appointment * wip * Patient Dashboard, Physician Form cleanup * Dosage renamed to Prescription Dosage * Renamed Drug Prescription Duration to Prescription Duration * Patient Appointment booking modal * Patient Age - calculate by dob * Remove - scheduler * Consultation - Appointment to Patient Appointment * Patient Dashboard - rearranged * Patient Appointment * Removed rer_physician from lab test and consultation * Patient Appontment Changes * Appointment and Consultation - optimized * Patient Appointment - fee validity code optimized * Consultation and Patient Appointment - Invoice validate two side * fix: #13 remove relation to admission * Healthcare - Patient Portal * fix import error * domain Healthcare added on install * Removed - Invoice Test Report * Physician Schedule - menu * Consultation - patient details - re write * New Doctype-Medical Code * Consultation - Daignosis codification * Medical Code - Codification - Settings * Medical Code Standard - Medical Code - Codification - Settings * fix appointment calendar * fix appointment analytics * Menu Medical Code Standard * New Doctype - Medical Code Standard * Set Physician Role insted of IP Physician and OP Physician Role * fixed some json files * Medical code - permission to physician * Unused Childs - Work Schedule and User List - Removed * Label Procedure to Lab Test * Lab Test and Patient - code optimised * Add Item Groups - setup wizard * Healthcare Settings - add Role - Medical Administrator * Healthcare - Demo setup - Make Demo * Fee Validity - Logic Test * Test Fee Validity - Optimised * Healthcare Doctypes - Restricted to Domain Healthcare * Domainify - remove Healthcare Roles - Other Domains * Healthcare doctypes - beta checked * Codacy fixes * Codacy - fixes * Codacy - fixes * Codacy - fixes * Codacy - fixes * Codacy - fixes * Lab Test - print hide =1 for some fields * Consultation - Codification field label to Medical Coding * Codacy fixes - import frappe and etc. * Codacy fixes - import frappe in test_vital_signs * Codacy fixes * Codacy fixes * Codacy fixes and remove delete perm for patient * send_sms - import form frappe * Healthcare Settings * Lab Prescription - Consultation - Test Code - read_only = 0 * Portal fixes * Patient Appointment - filter physician - if has schedule * Physician - IP Charge - Removed * test - files * Web Form - Patient Profile - removed * Role Medical Administrator to Healthcare Administrator * WIP healthcare documentation * Coday - fixes * Travis - fixes * Lab Test Report - menu * Reorder Healthcare settings - group lab config to bottom * Sample Collection - New - allow Sample and patient Selection * Rate - similar behaviour and Label as in Item Standard Selling Rate * Healthcare documentation * Lab Test Samples to Lab Test sample * Commplaints to Complaint * Commplaints to Complaint * Antibiotics to Antibiotic * Appointment Token Number - remove * View - Medical record * Codacy fixes * update healthcare docs * Cleanup Docs - Search, quick entry, trsck change, etc. * [minor] ux changes
2017-09-13 07:22:30 +00:00
from frappe.custom.doctype.custom_field.custom_field import create_custom_fields
2017-06-21 11:52:38 +00:00
from frappe.permissions import add_permission
from erpnext.regional.india import states
def setup(company=None, patch=True):
2017-06-21 11:52:38 +00:00
make_custom_fields()
add_permissions()
2017-06-22 11:07:04 +00:00
add_custom_roles_for_reports()
2017-09-28 13:25:40 +00:00
frappe.enqueue('erpnext.regional.india.setup.add_hsn_sac_codes', now=frappe.flags.in_test)
add_print_formats()
if not patch:
update_address_template()
2018-05-11 07:46:16 +00:00
make_fixtures(company)
2017-06-22 11:07:04 +00:00
def update_address_template():
with open(os.path.join(os.path.dirname(__file__), 'address_template.html'), 'r') as f:
html = f.read()
address_template = frappe.db.get_value('Address Template', 'India')
if address_template:
frappe.db.set_value('Address Template', 'India', 'template', html)
else:
# make new html template for India
frappe.get_doc(dict(
2017-06-22 11:07:04 +00:00
doctype='Address Template',
country='India',
template=html
)).insert()
2017-06-21 11:52:38 +00:00
def add_hsn_sac_codes():
# HSN codes
2017-06-21 11:52:38 +00:00
with open(os.path.join(os.path.dirname(__file__), 'hsn_code_data.json'), 'r') as f:
hsn_codes = json.loads(f.read())
create_hsn_codes(hsn_codes, code_field="hsn_code")
# SAC Codes
with open(os.path.join(os.path.dirname(__file__), 'sac_code_data.json'), 'r') as f:
sac_codes = json.loads(f.read())
create_hsn_codes(sac_codes, code_field="sac_code")
def create_hsn_codes(data, code_field):
for d in data:
hsn_code = frappe.new_doc('GST HSN Code')
hsn_code.description = d["description"]
hsn_code.hsn_code = d[code_field]
hsn_code.name = d[code_field]
try:
hsn_code.db_insert()
except frappe.DuplicateEntryError:
pass
2017-06-21 11:52:38 +00:00
2017-06-22 11:07:04 +00:00
def add_custom_roles_for_reports():
for report_name in ('GST Sales Register', 'GST Purchase Register',
'GST Itemised Sales Register', 'GST Itemised Purchase Register'):
if not frappe.db.get_value('Custom Role', dict(report=report_name)):
frappe.get_doc(dict(
doctype='Custom Role',
report=report_name,
roles= [
dict(role='Accounts User'),
dict(role='Accounts Manager')
]
)).insert()
2017-06-21 11:52:38 +00:00
def add_permissions():
for doctype in ('GST HSN Code', 'GST Settings'):
2017-06-21 11:52:38 +00:00
add_permission(doctype, 'All', 0)
def add_print_formats():
frappe.reload_doc("regional", "print_format", "gst_tax_invoice")
frappe.reload_doc("accounts", "print_format", "gst_pos_invoice")
frappe.db.sql(""" update `tabPrint Format` set disabled = 0 where
name in('GST POS Invoice', 'GST Tax Invoice') """)
2017-06-21 11:52:38 +00:00
def make_custom_fields():
hsn_sac_field = dict(fieldname='gst_hsn_code', label='HSN/SAC',
2017-09-11 13:51:37 +00:00
fieldtype='Data', options='item_code.gst_hsn_code', insert_after='description',
allow_on_submit=1, print_hide=1)
invoice_gst_fields = [
dict(fieldname='gst_section', label='GST Details', fieldtype='Section Break',
insert_after='language', print_hide=1, collapsible=1),
dict(fieldname='invoice_copy', label='Invoice Copy',
fieldtype='Select', insert_after='gst_section', print_hide=1, allow_on_submit=1,
options='Original for Recipient\nDuplicate for Transporter\nDuplicate for Supplier\nTriplicate for Supplier'),
dict(fieldname='reverse_charge', label='Reverse Charge',
fieldtype='Select', insert_after='invoice_copy', print_hide=1,
options='Y\nN', default='N'),
dict(fieldname='invoice_type', label='Invoice Type',
fieldtype='Select', insert_after='invoice_copy', print_hide=1,
options='Regular\nSEZ\nExport\nDeemed Export', default='Regular'),
dict(fieldname='export_type', label='Export Type',
fieldtype='Select', insert_after='invoice_type', print_hide=1,
depends_on='eval:in_list(["SEZ", "Export", "Deemed Export"], doc.invoice_type)',
options='\nWith Payment of Tax\nWithout Payment of Tax'),
dict(fieldname='ecommerce_gstin', label='E-commerce GSTIN',
fieldtype='Data', insert_after='export_type', print_hide=1),
dict(fieldname='gst_col_break', fieldtype='Column Break', insert_after='ecommerce_gstin'),
dict(fieldname='reason_for_issuing_document', label='Reason For Issuing document',
2018-02-05 10:39:51 +00:00
fieldtype='Select', insert_after='gst_col_break', print_hide=1,
depends_on='eval:doc.is_return==1',
2018-02-12 11:24:13 +00:00
options='\n01-Sales Return\n02-Post Sale Discount\n03-Deficiency in services\n04-Correction in Invoice\n05-Change in POS\n06-Finalization of Provisional assessment\n07-Others')
]
purchase_invoice_gst_fields = [
2017-06-21 11:52:38 +00:00
dict(fieldname='supplier_gstin', label='Supplier GSTIN',
2017-06-22 11:07:04 +00:00
fieldtype='Data', insert_after='supplier_address',
fetch_from='supplier_address.gstin', print_hide=1),
2017-06-21 11:52:38 +00:00
dict(fieldname='company_gstin', label='Company GSTIN',
fieldtype='Data', insert_after='shipping_address_display',
fetch_from='shipping_address.gstin', print_hide=1),
2018-02-05 10:39:51 +00:00
dict(fieldname='place_of_supply', label='Place of Supply',
fieldtype='Data', insert_after='shipping_address',
print_hide=1, read_only=0),
2018-01-29 08:27:34 +00:00
dict(fieldname='eligibility_for_itc', label='Eligibility For ITC',
fieldtype='Select', insert_after='reason_for_issuing_document', print_hide=1,
options='input\ninput service\ncapital goods\nineligible', default="ineligible"),
dict(fieldname='itc_integrated_tax', label='Availed ITC Integrated Tax',
fieldtype='Data', insert_after='eligibility_for_itc', print_hide=1),
dict(fieldname='itc_central_tax', label='Availed ITC Central Tax',
fieldtype='Data', insert_after='itc_integrated_tax', print_hide=1),
dict(fieldname='itc_state_tax', label='Availed ITC State/UT Tax',
fieldtype='Data', insert_after='itc_central_tax', print_hide=1),
dict(fieldname='itc_cess_amount', label='Availed ITC Cess',
fieldtype='Data', insert_after='itc_state_tax', print_hide=1),
]
sales_invoice_gst_fields = [
dict(fieldname='billing_address_gstin', label='Billing Address GSTIN',
fieldtype='Data', insert_after='customer_address',
fetch_from='customer_address.gstin', print_hide=1),
2017-06-21 11:52:38 +00:00
dict(fieldname='customer_gstin', label='Customer GSTIN',
fieldtype='Data', insert_after='shipping_address_name',
fetch_from='shipping_address_name.gstin', print_hide=1),
dict(fieldname='place_of_supply', label='Place of Supply',
2018-01-10 12:18:03 +00:00
fieldtype='Data', insert_after='customer_gstin',
print_hide=1, read_only=0),
2017-06-21 11:52:38 +00:00
dict(fieldname='company_gstin', label='Company GSTIN',
2017-06-22 11:07:04 +00:00
fieldtype='Data', insert_after='company_address',
fetch_from='company_address.gstin', print_hide=1),
2018-01-29 08:27:34 +00:00
dict(fieldname='port_code', label='Port Code',
fieldtype='Data', insert_after='reason_for_issuing_document', print_hide=1,
depends_on="eval:doc.invoice_type=='Export' "),
dict(fieldname='shipping_bill_number', label=' Shipping Bill Number',
fieldtype='Data', insert_after='port_code', print_hide=1,
depends_on="eval:doc.invoice_type=='Export' "),
dict(fieldname='shipping_bill_date', label='Shipping Bill Date',
fieldtype='Date', insert_after='shipping_bill_number', print_hide=1,
depends_on="eval:doc.invoice_type=='Export' ")
]
inter_state_gst_field = [
dict(fieldname='is_inter_state', label='Is Inter State',
fieldtype='Check', insert_after='disabled', print_hide=1)
]
custom_fields = {
'Address': [
dict(fieldname='gstin', label='Party GSTIN', fieldtype='Data',
insert_after='fax'),
dict(fieldname='gst_state', label='GST State', fieldtype='Select',
options='\n'.join(states), insert_after='gstin'),
dict(fieldname='gst_state_number', label='GST State Number',
fieldtype='Int', insert_after='gst_state', read_only=1),
2017-06-21 11:52:38 +00:00
],
2018-02-05 10:39:51 +00:00
'Purchase Invoice': invoice_gst_fields + purchase_invoice_gst_fields,
'Sales Invoice': invoice_gst_fields + sales_invoice_gst_fields,
'Delivery Note': sales_invoice_gst_fields,
'Sales Taxes and Charges Template': inter_state_gst_field,
'Purchase Taxes and Charges Template': inter_state_gst_field,
2017-06-21 11:52:38 +00:00
'Item': [
dict(fieldname='gst_hsn_code', label='HSN/SAC',
2017-06-21 11:52:38 +00:00
fieldtype='Link', options='GST HSN Code', insert_after='item_group'),
],
'Quotation Item': [hsn_sac_field],
'Supplier Quotation Item': [hsn_sac_field],
'Sales Order Item': [hsn_sac_field],
'Delivery Note Item': [hsn_sac_field],
'Sales Invoice Item': [hsn_sac_field],
'Purchase Order Item': [hsn_sac_field],
'Purchase Receipt Item': [hsn_sac_field],
'Purchase Invoice Item': [hsn_sac_field],
'Employee': [
dict(fieldname='ifsc_code', label='IFSC Code',
fieldtype='Data', insert_after='bank_ac_no', print_hide=1,
2018-04-05 16:05:29 +00:00
depends_on='eval:doc.salary_mode == "Bank"') ]
2017-06-21 11:52:38 +00:00
}
create_custom_fields(custom_fields, ignore_validate = frappe.flags.in_patch)
2018-05-11 07:46:16 +00:00
def make_fixtures(company=None):
docs = []
company = company.name if company else frappe.db.get_value("Global Defaults", None, "default_company")
set_salary_components(docs)
set_tds_account(docs, company)
set_tax_withholding_category(docs, company)
2017-06-21 11:52:38 +00:00
for d in docs:
try:
doc = frappe.get_doc(d)
doc.flags.ignore_permissions = True
doc.insert()
except frappe.NameError:
pass
2018-05-11 07:46:16 +00:00
def set_salary_components(docs):
docs.extend([
{'doctype': 'Salary Component', 'salary_component': 'Professional Tax', 'description': 'Professional Tax', 'type': 'Deduction'},
{'doctype': 'Salary Component', 'salary_component': 'Provident Fund', 'description': 'Provident fund', 'type': 'Deduction'},
{'doctype': 'Salary Component', 'salary_component': 'House Rent Allowance', 'description': 'House Rent Allowance', 'type': 'Earning'},
{'doctype': 'Salary Component', 'salary_component': 'Basic', 'description': 'Basic', 'type': 'Earning'},
{'doctype': 'Salary Component', 'salary_component': 'Arrear', 'description': 'Arrear', 'type': 'Earning'},
{'doctype': 'Salary Component', 'salary_component': 'Leave Encashment', 'description': 'Leave Encashment', 'type': 'Earning'}
])
def set_tax_withholding_category(docs, company):
accounts = []
tds_account = frappe.db.get_value("Account", filter={"account_type": "Payable",
"account_name": "TDS", "company": company})
if company and tds_account:
accounts = [
{
'company': company,
'account': tds_account
}
]
docs.extend([
{
'doctype': 'Tax Withholding Category', '__newname': 'TDS',
'percent_of_tax_withheld': 10,'threshold': 150000, 'book_on_invoice': 1,
'book_on_advance': 0, "withhold_cumulative_tax_amount": 0,
'accounts': accounts
}
])
def set_tds_account(docs, company):
docs.extend([
{
2018-05-12 12:12:20 +00:00
'doctype': 'Account', 'account_name': 'TDS', 'account_type': 'Tax',
'parent_account': 'Duties and Taxes', 'company': company
2018-05-11 07:46:16 +00:00
}
])