Skip to content

Commit

Permalink
Merge pull request #556 from sagarvora/use-doc_events-to-set-item-taxes
Browse files Browse the repository at this point in the history
fix: use `doc_events` to set item taxes
  • Loading branch information
sagarvora authored Apr 4, 2023
2 parents b1e037d + f783fad commit 9c15be8
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 18 deletions.
24 changes: 23 additions & 1 deletion india_compliance/gst_india/overrides/item.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@
from frappe import _


def validate_hsn_code(doc, method=None):
def validate(doc, method=None):
validate_hsn_code(doc)
set_taxes_from_hsn_code(doc)


def validate_hsn_code(doc):
# HSN Code is being validated only for sales items
if not doc.is_sales_item:
return
Expand Down Expand Up @@ -31,3 +36,20 @@ def validate_hsn_code(doc, method=None):
" HSN/SAC code."
).format(min_hsn_digits)
)


def set_taxes_from_hsn_code(doc):
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
3 changes: 1 addition & 2 deletions india_compliance/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
"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"},
"Payment Entry": {
"validate": (
"india_compliance.gst_india.overrides.payment_entry.update_place_of_supply"
Expand Down Expand Up @@ -153,7 +153,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 9c15be8

Please sign in to comment.