2019-01-17 19:04:01 +00:00
|
|
|
# Copyright (c) 2018, Frappe Technologies Pvt. Ltd. and Contributors
|
|
|
|
# License: GNU General Public License v3. See license.txt
|
|
|
|
|
|
|
|
from __future__ import unicode_literals
|
|
|
|
import frappe
|
2021-08-31 13:03:16 +00:00
|
|
|
import os
|
|
|
|
import json
|
|
|
|
from frappe.permissions import add_permission, update_permission_property
|
2019-01-17 19:04:01 +00:00
|
|
|
from frappe.custom.doctype.custom_field.custom_field import create_custom_fields
|
|
|
|
|
|
|
|
def setup(company=None, patch=True):
|
2021-08-31 13:03:16 +00:00
|
|
|
# Company independent fixtures should be called only once at the first company setup
|
|
|
|
if frappe.db.count('Company', {'country': 'United States'}) <=1:
|
|
|
|
setup_company_independent_fixtures(patch=patch)
|
|
|
|
|
|
|
|
def setup_company_independent_fixtures(company=None, patch=True):
|
|
|
|
add_product_tax_categories()
|
2019-01-17 19:04:01 +00:00
|
|
|
make_custom_fields()
|
2021-08-31 13:03:16 +00:00
|
|
|
add_permissions()
|
|
|
|
frappe.enqueue('erpnext.regional.united_states.setup.add_product_tax_categories', now=False)
|
2019-01-17 19:04:01 +00:00
|
|
|
add_print_formats()
|
|
|
|
|
2021-08-31 13:03:16 +00:00
|
|
|
# Product Tax categories imported from taxjar api
|
|
|
|
def add_product_tax_categories():
|
|
|
|
with open(os.path.join(os.path.dirname(__file__), 'product_tax_category_data.json'), 'r') as f:
|
|
|
|
tax_categories = json.loads(f.read())
|
|
|
|
create_tax_categories(tax_categories['categories'])
|
|
|
|
|
|
|
|
def create_tax_categories(data):
|
|
|
|
for d in data:
|
|
|
|
tax_category = frappe.new_doc('Product Tax Category')
|
|
|
|
tax_category.description = d.get("description")
|
|
|
|
tax_category.product_tax_code = d.get("product_tax_code")
|
|
|
|
tax_category.category_name = d.get("name")
|
|
|
|
try:
|
|
|
|
tax_category.db_insert()
|
|
|
|
except frappe.DuplicateEntryError:
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
2020-06-11 16:03:43 +00:00
|
|
|
def make_custom_fields(update=True):
|
2019-01-17 19:04:01 +00:00
|
|
|
custom_fields = {
|
|
|
|
'Supplier': [
|
|
|
|
dict(fieldname='irs_1099', fieldtype='Check', insert_after='tax_id',
|
|
|
|
label='Is IRS 1099 reporting required for supplier?')
|
2020-03-24 06:01:41 +00:00
|
|
|
],
|
|
|
|
'Sales Order': [
|
|
|
|
dict(fieldname='exempt_from_sales_tax', fieldtype='Check', insert_after='taxes_and_charges',
|
|
|
|
label='Is customer exempted from sales tax?')
|
|
|
|
],
|
|
|
|
'Sales Invoice': [
|
|
|
|
dict(fieldname='exempt_from_sales_tax', fieldtype='Check', insert_after='taxes_section',
|
|
|
|
label='Is customer exempted from sales tax?')
|
|
|
|
],
|
|
|
|
'Customer': [
|
|
|
|
dict(fieldname='exempt_from_sales_tax', fieldtype='Check', insert_after='represents_company',
|
|
|
|
label='Is customer exempted from sales tax?')
|
|
|
|
],
|
|
|
|
'Quotation': [
|
|
|
|
dict(fieldname='exempt_from_sales_tax', fieldtype='Check', insert_after='taxes_and_charges',
|
|
|
|
label='Is customer exempted from sales tax?')
|
2021-08-31 13:03:16 +00:00
|
|
|
],
|
|
|
|
'Sales Invoice Item': [
|
|
|
|
dict(fieldname='product_tax_category', fieldtype='Link', insert_after='description', options='Product Tax Category',
|
|
|
|
label='Product Tax Category', fetch_from='item_code.product_tax_category'),
|
|
|
|
dict(fieldname='tax_collectable', fieldtype='Currency', insert_after='net_amount',
|
|
|
|
label='Tax Collectable', read_only=1),
|
|
|
|
dict(fieldname='taxable_amount', fieldtype='Currency', insert_after='tax_collectable',
|
|
|
|
label='Taxable Amount', read_only=1)
|
|
|
|
],
|
|
|
|
'Item': [
|
|
|
|
dict(fieldname='product_tax_category', fieldtype='Link', insert_after='item_group', options='Product Tax Category',
|
|
|
|
label='Product Tax Category')
|
2019-01-17 19:04:01 +00:00
|
|
|
]
|
|
|
|
}
|
2020-06-11 16:03:43 +00:00
|
|
|
create_custom_fields(custom_fields, update=update)
|
2019-01-17 19:04:01 +00:00
|
|
|
|
2021-08-31 13:03:16 +00:00
|
|
|
def add_permissions():
|
|
|
|
doctype = "Product Tax Category"
|
|
|
|
for role in ('Accounts Manager', 'Accounts User', 'System Manager','Item Manager', 'Stock Manager'):
|
|
|
|
add_permission(doctype, role, 0)
|
|
|
|
update_permission_property(doctype, role, 0, 'write', 1)
|
|
|
|
update_permission_property(doctype, role, 0, 'create', 1)
|
|
|
|
|
2019-01-17 19:04:01 +00:00
|
|
|
def add_print_formats():
|
|
|
|
frappe.reload_doc("regional", "print_format", "irs_1099_form")
|
2021-03-03 11:33:48 +00:00
|
|
|
frappe.db.set_value("Print Format", "IRS 1099 Form", "disabled", 0)
|