Skip to content

Commit

Permalink
fix: use doc_events to set item taxes
Browse files Browse the repository at this point in the history
  • Loading branch information
sagarvora committed Apr 4, 2023
1 parent b1e037d commit 097188a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 17 deletions.
17 changes: 17 additions & 0 deletions india_compliance/gst_india/overrides/item.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,20 @@ def validate_hsn_code(doc, method=None):
" HSN/SAC code."
).format(min_hsn_digits)
)


def set_item_tax_from_hsn_code(doc, method=None):
if doc.taxes or not doc.gst_hsn_code:
return

hsn_doc = frappe.get_doc("GST HSN Code", doc.gst_hsn_code)

for tax in hsn_doc.taxes:
doc.append(
"taxes",
{
"item_tax_template": tax.item_tax_template,
"tax_category": tax.tax_category,
"valid_from": tax.valid_from,
},
)
15 changes: 0 additions & 15 deletions india_compliance/gst_india/overrides/transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -646,21 +646,6 @@ def get_tax_template(master_doctype, company, is_inter_state, state_code):
return default_tax


def set_item_tax_from_hsn_code(item):
if not item.taxes and item.gst_hsn_code:
hsn_doc = frappe.get_doc("GST HSN Code", item.gst_hsn_code)

for tax in hsn_doc.taxes:
item.append(
"taxes",
{
"item_tax_template": tax.item_tax_template,
"tax_category": tax.tax_category,
"valid_from": tax.valid_from,
},
)


def validate_reverse_charge_transaction(doc, method=None):
base_gst_tax = 0
base_reverse_charge_booked = 0
Expand Down
8 changes: 6 additions & 2 deletions india_compliance/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,12 @@
"india_compliance.gst_india.overrides.transaction.validate_transaction"
),
},
"Item": {"validate": "india_compliance.gst_india.overrides.item.validate_hsn_code"},
"Item": {
"validate": [
"india_compliance.gst_india.overrides.item.validate_hsn_code",
"india_compliance.gst_india.overrides.item.set_item_tax_from_hsn_code",
]
},
"Payment Entry": {
"validate": (
"india_compliance.gst_india.overrides.payment_entry.update_place_of_supply"
Expand Down Expand Up @@ -153,7 +158,6 @@
"erpnext.accounts.party.get_regional_address_details": (
"india_compliance.gst_india.overrides.transaction.update_party_details"
),
"erpnext.stock.doctype.item.item.set_item_tax_from_hsn_code": "india_compliance.gst_india.overrides.transaction.set_item_tax_from_hsn_code",
"erpnext.assets.doctype.asset.asset.get_depreciation_amount": (
"india_compliance.income_tax_india.overrides.asset.get_depreciation_amount"
),
Expand Down

0 comments on commit 097188a

Please sign in to comment.