Skip to content

Commit

Permalink
fix: pos based on account settings (#2647)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sanket322 authored Oct 18, 2024
1 parent ef25eca commit aafed02
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 17 deletions.
20 changes: 20 additions & 0 deletions india_compliance/gst_india/overrides/test_transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -1178,3 +1178,23 @@ def test_so_and_po_after_item_update(self):
},
doc.items[1],
)


class TestPlaceOfSupply(IntegrationTestCase):
def test_pos_sales_invoice(self):
doc_args = {
"doctype": "Sales Invoice",
"customer": "_Test Registered Composition Customer",
}

settings = ["Accounts Settings", None, "determine_address_tax_category_from"]

# Shipping Address
frappe.db.set_value(*settings, "Shipping Address")
doc = create_transaction(**doc_args)
self.assertEqual(doc.place_of_supply, "24-Gujarat")

# Billing Address
frappe.db.set_value(*settings, "Billing Address")
doc = create_transaction(**doc_args)
self.assertEqual(doc.place_of_supply, "29-Karnataka")
10 changes: 1 addition & 9 deletions india_compliance/gst_india/setup/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,10 +239,6 @@ def set_default_accounts_settings():
"""
Accounts Settings overridden by India Compliance
- Determine Address Tax Category From:
This is overriden to be Billing Address, since that's the correct
address for determining GST applicablility
- Automatically Add Taxes and Charges from Item Tax Template:
This is overriden to be "No". Item Tax Templates are designed to have
all GST Accounts and are primarily used for selection of tax rate.
Expand All @@ -252,11 +248,7 @@ def set_default_accounts_settings():
show_accounts_settings_override_warning()

frappe.db.set_single_value(
"Accounts Settings",
{
"determine_address_tax_category_from": "Billing Address",
"add_taxes_from_item_tax_template": 0,
},
"Accounts Settings", "add_taxes_from_item_tax_template", 0
)

frappe.db.set_default("add_taxes_from_item_tax_template", 0)
Expand Down
2 changes: 1 addition & 1 deletion india_compliance/gst_india/setup/property_setters.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def get_property_setters(*, include_defaults=False):
"doctype": "Accounts Settings",
"fieldname": "determine_address_tax_category_from",
"property": "read_only",
"value": "1",
"value": "0",
},
{
"doctype": "Accounts Settings",
Expand Down
20 changes: 14 additions & 6 deletions india_compliance/gst_india/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,10 +387,18 @@ def get_place_of_supply(party_details, doctype):
:param party_details: A frappe._dict or document containing fields related to party
"""

pos_basis = frappe.get_cached_value(
"Accounts Settings", "Accounts Settings", "determine_address_tax_category_from"
)

if pos_basis == "Shipping Address" and doctype in SALES_DOCTYPES:
# POS Basis Shipping Address is only applicable for Sales
pos_gstin = party_details.company_gstin

# fallback to company GSTIN for sales or supplier GSTIN for purchases
# (in retail scenarios, customer / company GSTIN may not be set)

if doctype in SALES_DOCTYPES or doctype == "Payment Entry":
elif doctype in SALES_DOCTYPES or doctype == "Payment Entry":
# for exports, Place of Supply is set using GST category in absence of GSTIN
if party_details.gst_category == "Overseas":
return get_overseas_place_of_supply(party_details)
Expand All @@ -407,18 +415,18 @@ def get_place_of_supply(party_details, doctype):
if gst_state_number and gst_state:
return f"{gst_state_number}-{gst_state}"

party_gstin = party_details.billing_address_gstin or party_details.company_gstin
pos_gstin = party_details.billing_address_gstin or party_details.company_gstin

elif doctype == "Stock Entry":
party_gstin = party_details.bill_to_gstin or party_details.bill_from_gstin
pos_gstin = party_details.bill_to_gstin or party_details.bill_from_gstin
else:
# for purchase, subcontracting order and receipt
party_gstin = party_details.company_gstin or party_details.supplier_gstin
pos_gstin = party_details.company_gstin or party_details.supplier_gstin

if not party_gstin:
if not pos_gstin:
return

state_code = party_gstin[:2]
state_code = pos_gstin[:2]

if state := get_state(state_code):
return f"{state_code}-{state}"
Expand Down
2 changes: 1 addition & 1 deletion india_compliance/patches.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ india_compliance.patches.v15.remove_duplicate_web_template
[post_model_sync]
india_compliance.patches.v14.set_default_for_overridden_accounts_setting
execute:from india_compliance.gst_india.setup import create_custom_fields; create_custom_fields() #58
execute:from india_compliance.gst_india.setup import create_property_setters; create_property_setters() #8
execute:from india_compliance.gst_india.setup import create_property_setters; create_property_setters() #9
execute:from india_compliance.income_tax_india.setup import create_custom_fields; create_custom_fields() #2
india_compliance.patches.post_install.remove_old_fields #2
india_compliance.patches.post_install.set_gst_tax_type
Expand Down

0 comments on commit aafed02

Please sign in to comment.