Skip to content

Commit

Permalink
refactor: better variables and structure of pos
Browse files Browse the repository at this point in the history
  • Loading branch information
vorasmit committed Oct 18, 2024
1 parent 92f4608 commit ef52fb2
Showing 1 changed file with 18 additions and 25 deletions.
43 changes: 18 additions & 25 deletions india_compliance/gst_india/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,14 +387,22 @@ 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":
if doctype in SALES_DOCTYPES or doctype == "Payment Entry":
pos_gstin = party_details.company_gstin
elif doctype == "Stock Entry":
pos_gstin = party_details.bill_from_gstin
else:
pos_gstin = party_details.supplier_gstin

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

determine_address_tax_category_from = frappe.db.get_single_value(
"Accounts Settings", "determine_address_tax_category_from"
)

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 @@ -411,33 +419,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
if determine_address_tax_category_from == "Billing Address"
and party_details.billing_address_gstin
else 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
if determine_address_tax_category_from == "Billing Address"
and party_details.bill_to_gstin
else 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
if determine_address_tax_category_from == "Billing Address"
and party_details.company_gstin
else 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

0 comments on commit ef52fb2

Please sign in to comment.