blob: 9c183af1d1308e6674c4a109c65e9ac2b3ccd86a [file] [log] [blame]
Tyler Matteson53a64922019-01-17 14:04:01 -05001# Copyright (c) 2018, Frappe Technologies Pvt. Ltd. and Contributors
2# License: GNU General Public License v3. See license.txt
3
4from __future__ import unicode_literals
5import frappe
Subin Tom70049442021-08-31 18:33:16 +05306import os
7import json
8from frappe.permissions import add_permission, update_permission_property
Tyler Matteson53a64922019-01-17 14:04:01 -05009from frappe.custom.doctype.custom_field.custom_field import create_custom_fields
10
Tyler Matteson53a64922019-01-17 14:04:01 -050011def setup(company=None, patch=True):
Subin Tom70049442021-08-31 18:33:16 +053012 # Company independent fixtures should be called only once at the first company setup
13 if frappe.db.count('Company', {'country': 'United States'}) <=1:
14 setup_company_independent_fixtures(patch=patch)
15
16def setup_company_independent_fixtures(company=None, patch=True):
17 add_product_tax_categories()
Tyler Matteson53a64922019-01-17 14:04:01 -050018 make_custom_fields()
Subin Tom70049442021-08-31 18:33:16 +053019 add_permissions()
20 frappe.enqueue('erpnext.regional.united_states.setup.add_product_tax_categories', now=False)
Tyler Matteson53a64922019-01-17 14:04:01 -050021 add_print_formats()
Tyler Matteson53a64922019-01-17 14:04:01 -050022
Subin Tom70049442021-08-31 18:33:16 +053023# Product Tax categories imported from taxjar api
24def add_product_tax_categories():
25 with open(os.path.join(os.path.dirname(__file__), 'product_tax_category_data.json'), 'r') as f:
26 tax_categories = json.loads(f.read())
27 create_tax_categories(tax_categories['categories'])
28
29def create_tax_categories(data):
30 for d in data:
31 tax_category = frappe.new_doc('Product Tax Category')
32 tax_category.description = d.get("description")
33 tax_category.product_tax_code = d.get("product_tax_code")
34 tax_category.category_name = d.get("name")
35 try:
36 tax_category.db_insert()
37 except frappe.DuplicateEntryError:
38 pass
39
40
Deepesh Garg9df45322020-06-11 21:33:43 +053041def make_custom_fields(update=True):
Tyler Matteson53a64922019-01-17 14:04:01 -050042 custom_fields = {
43 'Supplier': [
44 dict(fieldname='irs_1099', fieldtype='Check', insert_after='tax_id',
45 label='Is IRS 1099 reporting required for supplier?')
vishdhad3ec1c12020-03-24 11:31:41 +053046 ],
47 'Sales Order': [
48 dict(fieldname='exempt_from_sales_tax', fieldtype='Check', insert_after='taxes_and_charges',
49 label='Is customer exempted from sales tax?')
50 ],
51 'Sales Invoice': [
52 dict(fieldname='exempt_from_sales_tax', fieldtype='Check', insert_after='taxes_section',
53 label='Is customer exempted from sales tax?')
54 ],
55 'Customer': [
56 dict(fieldname='exempt_from_sales_tax', fieldtype='Check', insert_after='represents_company',
57 label='Is customer exempted from sales tax?')
58 ],
59 'Quotation': [
60 dict(fieldname='exempt_from_sales_tax', fieldtype='Check', insert_after='taxes_and_charges',
61 label='Is customer exempted from sales tax?')
Subin Tom70049442021-08-31 18:33:16 +053062 ],
63 'Sales Invoice Item': [
64 dict(fieldname='product_tax_category', fieldtype='Link', insert_after='description', options='Product Tax Category',
65 label='Product Tax Category', fetch_from='item_code.product_tax_category'),
Ankush Menatb147b852021-09-01 16:45:57 +053066 dict(fieldname='tax_collectable', fieldtype='Currency', insert_after='net_amount',
Subin Tom70049442021-08-31 18:33:16 +053067 label='Tax Collectable', read_only=1),
Ankush Menatb147b852021-09-01 16:45:57 +053068 dict(fieldname='taxable_amount', fieldtype='Currency', insert_after='tax_collectable',
Subin Tom70049442021-08-31 18:33:16 +053069 label='Taxable Amount', read_only=1)
70 ],
71 'Item': [
72 dict(fieldname='product_tax_category', fieldtype='Link', insert_after='item_group', options='Product Tax Category',
73 label='Product Tax Category')
Tyler Matteson53a64922019-01-17 14:04:01 -050074 ]
75 }
Deepesh Garg9df45322020-06-11 21:33:43 +053076 create_custom_fields(custom_fields, update=update)
Tyler Matteson53a64922019-01-17 14:04:01 -050077
Subin Tom70049442021-08-31 18:33:16 +053078def add_permissions():
79 doctype = "Product Tax Category"
80 for role in ('Accounts Manager', 'Accounts User', 'System Manager','Item Manager', 'Stock Manager'):
81 add_permission(doctype, role, 0)
82 update_permission_property(doctype, role, 0, 'write', 1)
83 update_permission_property(doctype, role, 0, 'create', 1)
84
Tyler Matteson53a64922019-01-17 14:04:01 -050085def add_print_formats():
86 frappe.reload_doc("regional", "print_format", "irs_1099_form")
barredterra1521b312021-03-03 12:33:48 +010087 frappe.db.set_value("Print Format", "IRS 1099 Form", "disabled", 0)