Compare commits
2 Commits
version-13
...
mergify/bp
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7debdc3269 | ||
|
|
f5160dc83d |
@@ -4,7 +4,7 @@ import frappe
|
||||
|
||||
from erpnext.hooks import regional_overrides
|
||||
|
||||
__version__ = "13.55.2"
|
||||
__version__ = "13.54.4"
|
||||
|
||||
|
||||
def get_default_company(user=None):
|
||||
|
||||
@@ -704,7 +704,7 @@ def get_pos_reserved_qty(item_code, warehouse):
|
||||
reserved_qty = (
|
||||
frappe.qb.from_(p_inv)
|
||||
.from_(p_item)
|
||||
.select(Sum(p_item.qty).as_("qty"))
|
||||
.select(Sum(p_item.stock_qty).as_("stock_qty"))
|
||||
.where(
|
||||
(p_inv.name == p_item.parent)
|
||||
& (IfNull(p_inv.consolidated_invoice, "") == "")
|
||||
@@ -715,7 +715,7 @@ def get_pos_reserved_qty(item_code, warehouse):
|
||||
)
|
||||
).run(as_dict=True)
|
||||
|
||||
return reserved_qty[0].qty or 0 if reserved_qty else 0
|
||||
return flt(reserved_qty[0].stock_qty) if reserved_qty else 0
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import traceback
|
||||
<<<<<<< HEAD
|
||||
|
||||
import frappe
|
||||
import taxjar
|
||||
@@ -94,6 +95,26 @@ SUPPORTED_STATE_CODES = [
|
||||
"WI",
|
||||
"WY",
|
||||
]
|
||||
=======
|
||||
import frappe
|
||||
import taxjar
|
||||
from erpnext import get_default_company
|
||||
from frappe import _
|
||||
from frappe.contacts.doctype.address.address import get_company_address
|
||||
from frappe.utils import cint
|
||||
|
||||
TAX_ACCOUNT_HEAD = frappe.db.get_single_value("TaxJar Settings", "tax_account_head")
|
||||
SHIP_ACCOUNT_HEAD = frappe.db.get_single_value("TaxJar Settings", "shipping_account_head")
|
||||
TAXJAR_CREATE_TRANSACTIONS = frappe.db.get_single_value("TaxJar Settings", "taxjar_create_transactions")
|
||||
TAXJAR_CALCULATE_TAX = frappe.db.get_single_value("TaxJar Settings", "taxjar_calculate_tax")
|
||||
SUPPORTED_COUNTRY_CODES = ["AT", "AU", "BE", "BG", "CA", "CY", "CZ", "DE", "DK", "EE", "ES", "FI",
|
||||
"FR", "GB", "GR", "HR", "HU", "IE", "IT", "LT", "LU", "LV", "MT", "NL", "PL", "PT", "RO",
|
||||
"SE", "SI", "SK", "US"]
|
||||
SUPPORTED_STATE_CODES = ['AL', 'AK', 'AZ', 'AR', 'CA', 'CO', 'CT', 'DE', 'DC', 'FL', 'GA', 'HI', 'ID', 'IL',
|
||||
'IN', 'IA', 'KS', 'KY', 'LA', 'ME', 'MD', 'MA', 'MI', 'MN', 'MS', 'MO', 'MT', 'NE',
|
||||
'NV', 'NH', 'NJ', 'NM', 'NY', 'NC', 'ND', 'OH', 'OK', 'OR', 'PA', 'RI', 'SC', 'SD',
|
||||
'TN', 'TX', 'UT', 'VT', 'VA', 'WA', 'WV', 'WI', 'WY']
|
||||
>>>>>>> 7004944cc0 (feat: Taxjar Integration update (#27143))
|
||||
|
||||
|
||||
def get_client():
|
||||
@@ -108,7 +129,13 @@ def get_client():
|
||||
|
||||
if api_key and api_url:
|
||||
client = taxjar.Client(api_key=api_key, api_url=api_url)
|
||||
<<<<<<< HEAD
|
||||
client.set_api_config("headers", {"x-api-version": "2022-01-24"})
|
||||
=======
|
||||
client.set_api_config('headers', {
|
||||
'x-api-version': '2020-08-07'
|
||||
})
|
||||
>>>>>>> 7004944cc0 (feat: Taxjar Integration update (#27143))
|
||||
return client
|
||||
|
||||
|
||||
@@ -146,7 +173,11 @@ def create_transaction(doc, method):
|
||||
try:
|
||||
if doc.is_return:
|
||||
client.create_refund(tax_dict)
|
||||
<<<<<<< HEAD
|
||||
else:
|
||||
=======
|
||||
else:
|
||||
>>>>>>> 7004944cc0 (feat: Taxjar Integration update (#27143))
|
||||
client.create_order(tax_dict)
|
||||
except taxjar.exceptions.TaxJarResponseError as err:
|
||||
frappe.throw(_(sanitize_error_response(err)))
|
||||
@@ -186,6 +217,7 @@ def get_tax_data(doc):
|
||||
|
||||
shipping = sum([tax.tax_amount for tax in doc.taxes if tax.account_head == SHIP_ACCOUNT_HEAD])
|
||||
|
||||
<<<<<<< HEAD
|
||||
line_items = [get_line_item_dict(item, doc.docstatus) for item in doc.items]
|
||||
|
||||
if from_shipping_state not in SUPPORTED_STATE_CODES:
|
||||
@@ -193,8 +225,18 @@ def get_tax_data(doc):
|
||||
|
||||
if to_shipping_state not in SUPPORTED_STATE_CODES:
|
||||
to_shipping_state = get_state_code(to_address, "Shipping")
|
||||
=======
|
||||
line_items = [get_line_item_dict(item) for item in doc.items]
|
||||
>>>>>>> 7004944cc0 (feat: Taxjar Integration update (#27143))
|
||||
|
||||
if from_shipping_state not in SUPPORTED_STATE_CODES:
|
||||
from_shipping_state = get_state_code(from_address, 'Company')
|
||||
|
||||
if to_shipping_state not in SUPPORTED_STATE_CODES:
|
||||
to_shipping_state = get_state_code(to_address, 'Shipping')
|
||||
|
||||
tax_dict = {
|
||||
<<<<<<< HEAD
|
||||
"from_country": from_country_code,
|
||||
"from_zip": from_address.pincode,
|
||||
"from_state": from_shipping_state,
|
||||
@@ -234,9 +276,42 @@ def get_line_item_dict(item, docstatus):
|
||||
|
||||
if docstatus == 1:
|
||||
tax_dict.update({"sales_tax": item.get("tax_collectable")})
|
||||
=======
|
||||
'from_country': from_country_code,
|
||||
'from_zip': from_address.pincode,
|
||||
'from_state': from_shipping_state,
|
||||
'from_city': from_address.city,
|
||||
'from_street': from_address.address_line1,
|
||||
'to_country': to_country_code,
|
||||
'to_zip': to_address.pincode,
|
||||
'to_city': to_address.city,
|
||||
'to_street': to_address.address_line1,
|
||||
'to_state': to_shipping_state,
|
||||
'shipping': shipping,
|
||||
'amount': doc.net_total,
|
||||
'plugin': 'erpnext',
|
||||
'line_items': line_items
|
||||
}
|
||||
return tax_dict
|
||||
>>>>>>> 7004944cc0 (feat: Taxjar Integration update (#27143))
|
||||
|
||||
return tax_dict
|
||||
def get_state_code(address, location):
|
||||
if address is not None:
|
||||
state_code = get_iso_3166_2_state_code(address)
|
||||
if state_code not in SUPPORTED_STATE_CODES:
|
||||
frappe.throw(_("Please enter a valid State in the {0} Address").format(location))
|
||||
else:
|
||||
frappe.throw(_("Please enter a valid State in the {0} Address").format(location))
|
||||
|
||||
return state_code
|
||||
|
||||
def get_line_item_dict(item):
|
||||
return dict(
|
||||
id = item.get('idx'),
|
||||
quantity = item.get('qty'),
|
||||
unit_price = item.get('rate'),
|
||||
product_tax_code = item.get('product_tax_category')
|
||||
)
|
||||
|
||||
def set_sales_tax(doc, method):
|
||||
TAX_ACCOUNT_HEAD = frappe.db.get_single_value("TaxJar Settings", "tax_account_head")
|
||||
@@ -261,9 +336,12 @@ def set_sales_tax(doc, method):
|
||||
setattr(doc, "taxes", [tax for tax in doc.taxes if tax.account_head != TAX_ACCOUNT_HEAD])
|
||||
return
|
||||
|
||||
<<<<<<< HEAD
|
||||
# check if delivering within a nexus
|
||||
check_for_nexus(doc, tax_dict)
|
||||
|
||||
=======
|
||||
>>>>>>> 7004944cc0 (feat: Taxjar Integration update (#27143))
|
||||
tax_data = validate_tax_request(tax_dict)
|
||||
if tax_data is not None:
|
||||
if not tax_data.amount_to_collect:
|
||||
@@ -278,6 +356,7 @@ def set_sales_tax(doc, method):
|
||||
doc.run_method("calculate_taxes_and_totals")
|
||||
break
|
||||
else:
|
||||
<<<<<<< HEAD
|
||||
doc.append(
|
||||
"taxes",
|
||||
{
|
||||
@@ -291,9 +370,36 @@ def set_sales_tax(doc, method):
|
||||
for item in tax_data.breakdown.line_items:
|
||||
doc.get("items")[cint(item.id) - 1].tax_collectable = item.tax_collectable
|
||||
doc.get("items")[cint(item.id) - 1].taxable_amount = item.taxable_amount
|
||||
=======
|
||||
doc.append("taxes", {
|
||||
"charge_type": "Actual",
|
||||
"description": "Sales Tax",
|
||||
"account_head": TAX_ACCOUNT_HEAD,
|
||||
"tax_amount": tax_data.amount_to_collect
|
||||
})
|
||||
# Assigning values to tax_collectable and taxable_amount fields in sales item table
|
||||
for item in tax_data.breakdown.line_items:
|
||||
doc.get('items')[cint(item.id)-1].tax_collectable = item.tax_collectable
|
||||
doc.get('items')[cint(item.id)-1].taxable_amount = item.taxable_amount
|
||||
>>>>>>> 7004944cc0 (feat: Taxjar Integration update (#27143))
|
||||
|
||||
doc.run_method("calculate_taxes_and_totals")
|
||||
|
||||
def check_sales_tax_exemption(doc):
|
||||
# if the party is exempt from sales tax, then set all tax account heads to zero
|
||||
sales_tax_exempted = hasattr(doc, "exempt_from_sales_tax") and doc.exempt_from_sales_tax \
|
||||
or frappe.db.has_column("Customer", "exempt_from_sales_tax") \
|
||||
and frappe.db.get_value("Customer", doc.customer, "exempt_from_sales_tax")
|
||||
|
||||
if sales_tax_exempted:
|
||||
for tax in doc.taxes:
|
||||
if tax.account_head == TAX_ACCOUNT_HEAD:
|
||||
tax.tax_amount = 0
|
||||
break
|
||||
doc.run_method("calculate_taxes_and_totals")
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
def check_for_nexus(doc, tax_dict):
|
||||
TAX_ACCOUNT_HEAD = frappe.db.get_single_value("TaxJar Settings", "tax_account_head")
|
||||
@@ -364,7 +470,11 @@ def get_shipping_address_details(doc):
|
||||
if doc.shipping_address_name:
|
||||
shipping_address = frappe.get_doc("Address", doc.shipping_address_name)
|
||||
elif doc.customer_address:
|
||||
<<<<<<< HEAD
|
||||
shipping_address = frappe.get_doc("Address", doc.customer_address)
|
||||
=======
|
||||
shipping_address = frappe.get_doc("Address", doc.customer_address_name)
|
||||
>>>>>>> 7004944cc0 (feat: Taxjar Integration update (#27143))
|
||||
else:
|
||||
shipping_address = get_company_address_details(doc)
|
||||
|
||||
|
||||
@@ -307,9 +307,15 @@ erpnext.patches.v13_0.remove_bad_selling_defaults
|
||||
erpnext.patches.v13_0.trim_whitespace_from_serial_nos # 16-01-2022
|
||||
erpnext.patches.v13_0.migrate_stripe_api
|
||||
erpnext.patches.v13_0.reset_clearance_date_for_intracompany_payment_entries
|
||||
<<<<<<< HEAD
|
||||
execute:frappe.reload_doc("erpnext_integrations", "doctype", "TaxJar Settings")
|
||||
execute:frappe.reload_doc("erpnext_integrations", "doctype", "Product Tax Category")
|
||||
erpnext.patches.v13_0.custom_fields_for_taxjar_integration #08-11-2021
|
||||
=======
|
||||
erpnext.patches.v13_0.einvoicing_deprecation_warning
|
||||
erpnext.patches.v13_0.custom_fields_for_taxjar_integration
|
||||
erpnext.patches.v14_0.delete_einvoicing_doctypes
|
||||
>>>>>>> 7004944cc0 (feat: Taxjar Integration update (#27143))
|
||||
erpnext.patches.v13_0.set_operation_time_based_on_operating_cost
|
||||
erpnext.patches.v13_0.create_website_items #30-09-2021
|
||||
erpnext.patches.v13_0.populate_e_commerce_settings
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
<<<<<<< HEAD
|
||||
import frappe
|
||||
from frappe.custom.doctype.custom_field.custom_field import create_custom_fields
|
||||
|
||||
@@ -70,3 +71,34 @@ def execute():
|
||||
"erpnext.erpnext_integrations.doctype.taxjar_settings.taxjar_settings.add_product_tax_categories",
|
||||
now=True,
|
||||
)
|
||||
=======
|
||||
from __future__ import unicode_literals
|
||||
import frappe
|
||||
from frappe.custom.doctype.custom_field.custom_field import create_custom_fields
|
||||
from erpnext.regional.united_states.setup import add_permissions
|
||||
|
||||
def execute():
|
||||
company = frappe.get_all('Company', filters = {'country': 'United States'}, fields=['name'])
|
||||
if not company:
|
||||
return
|
||||
|
||||
frappe.reload_doc("regional", "doctype", "product_tax_category")
|
||||
|
||||
custom_fields = {
|
||||
'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')
|
||||
]
|
||||
}
|
||||
create_custom_fields(custom_fields, update=True)
|
||||
add_permissions()
|
||||
frappe.enqueue('erpnext.regional.united_states.setup.add_product_tax_categories', now=True)
|
||||
>>>>>>> 7004944cc0 (feat: Taxjar Integration update (#27143))
|
||||
|
||||
@@ -4,6 +4,9 @@
|
||||
# import frappe
|
||||
from frappe.model.document import Document
|
||||
|
||||
<<<<<<< HEAD
|
||||
|
||||
=======
|
||||
>>>>>>> 7004944cc0 (feat: Taxjar Integration update (#27143))
|
||||
class ProductTaxCategory(Document):
|
||||
pass
|
||||
|
||||
@@ -4,6 +4,9 @@
|
||||
# import frappe
|
||||
import unittest
|
||||
|
||||
<<<<<<< HEAD
|
||||
|
||||
=======
|
||||
>>>>>>> 7004944cc0 (feat: Taxjar Integration update (#27143))
|
||||
class TestProductTaxCategory(unittest.TestCase):
|
||||
pass
|
||||
|
||||
4084
erpnext/regional/united_states/product_tax_category_data.json
Normal file
4084
erpnext/regional/united_states/product_tax_category_data.json
Normal file
File diff suppressed because it is too large
Load Diff
@@ -11,14 +11,44 @@ from frappe.custom.doctype.custom_field.custom_field import create_custom_fields
|
||||
|
||||
def setup(company=None, patch=True):
|
||||
# Company independent fixtures should be called only once at the first company setup
|
||||
<<<<<<< HEAD
|
||||
if frappe.db.count("Company", {"country": "United States"}) <= 1:
|
||||
setup_company_independent_fixtures(patch=patch)
|
||||
|
||||
|
||||
def setup_company_independent_fixtures(company=None, patch=True):
|
||||
=======
|
||||
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()
|
||||
>>>>>>> 7004944cc0 (feat: Taxjar Integration update (#27143))
|
||||
make_custom_fields()
|
||||
add_permissions()
|
||||
frappe.enqueue('erpnext.regional.united_states.setup.add_product_tax_categories', now=False)
|
||||
add_print_formats()
|
||||
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
# 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
|
||||
|
||||
>>>>>>> 7004944cc0 (feat: Taxjar Integration update (#27143))
|
||||
|
||||
def make_custom_fields(update=True):
|
||||
custom_fields = {
|
||||
@@ -62,9 +92,37 @@ def make_custom_fields(update=True):
|
||||
label="Is customer exempted from sales tax?",
|
||||
)
|
||||
],
|
||||
<<<<<<< HEAD
|
||||
}
|
||||
create_custom_fields(custom_fields, update=update)
|
||||
|
||||
=======
|
||||
'Quotation': [
|
||||
dict(fieldname='exempt_from_sales_tax', fieldtype='Check', insert_after='taxes_and_charges',
|
||||
label='Is customer exempted from sales tax?')
|
||||
],
|
||||
'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')
|
||||
]
|
||||
}
|
||||
create_custom_fields(custom_fields, update=update)
|
||||
|
||||
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)
|
||||
>>>>>>> 7004944cc0 (feat: Taxjar Integration update (#27143))
|
||||
|
||||
def add_print_formats():
|
||||
frappe.reload_doc("regional", "print_format", "irs_1099_form")
|
||||
|
||||
Reference in New Issue
Block a user