Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use doc_events to set item taxes #556

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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