Repository navigation
feat: support taxable value overrides for custom resolvers #4452
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
Open
vorasmit
wants to merge
17
commits into
resilient-tech:develop
Choose a base branch
from
vorasmit:taxable_value_overrides
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
b77a010
feat: support taxable value overrides for custom resolvers
vorasmit a4670c4
feat: support for taxes on MRP in India Compliance
vorasmit cae8ed7
feat: taxes on margin; taxes inclusive; handle e-Invoice in both scen…
vorasmit b5a189a
feat: configurable margin and mrp charge types based on GST Settings
vorasmit e8c0a2a
fix: changes as per reivew; removed taxes_controller implementation
vorasmit 60a6388
test: clear Sales Taxes and Charges cache
vorasmit 4450dd8
fix: changes as per review
Anish59312 9160f1e
Merge branch 'develop' into taxable_value_overrides
ljain112 c7864ea
test: update taxable value assertions in e-invoice tests
ljain112 87bb407
Merge branch 'develop' into taxable_value_overrides
ljain112 ee70cec
test: enable On MRP / On Margin through GST Settings in tests
ljain112 78675c5
fix: keep margin-scheme credit note nil when the sale was at a loss
ljain112 54232c9
fix: handle inclusive and exclusive tax
ljain112 f9d2fe5
fix: take MRP and purchase price in company currency
ljain112 ec1e7ed
chore: note company currency in MRP and margin scheme settings
ljain112 064f1a8
fix: store resolver taxable value at field precision
ljain112 4f9fb5e
chore: trim taxable value docstrings and comments to house style
ljain112 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| import frappe | ||
| from frappe.utils import flt | ||
|
|
||
| from india_compliance.gst_india.constants import TAX_TYPES | ||
|
|
||
|
|
||
| def get_item_taxable_value(doc, item, default): | ||
| # reset: the same item is resolved again on every save | ||
| item._dont_update_taxable_value = False | ||
| item._deemed_taxable_value = None | ||
|
|
||
| resolvers = frappe.get_hooks("erpnext_taxable_base_resolvers") or {} | ||
| if not resolvers: | ||
| return default | ||
|
|
||
| for tax in doc.get("taxes") or []: | ||
| if tax.get("gst_tax_type") not in TAX_TYPES: | ||
| continue | ||
|
|
||
| path = resolvers.get(tax.charge_type) | ||
| if not path: | ||
| continue | ||
|
|
||
| method = path[-1] if isinstance(path, list | tuple) else path | ||
| base = flt(frappe.get_attr(method)(frappe._dict(doc=doc), item, tax)) | ||
|
|
||
| # a resolver may tax a deemed base but report the net value (MRP) | ||
| if getattr(item, "_dont_update_taxable_value", None): | ||
| return default | ||
|
|
||
| return base * flt(doc.get("conversion_rate") or 1) | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| return default | ||
|
|
||
|
|
||
| def _item_rate(item, tax): | ||
| item_tax_rate = frappe.parse_json(item.get("item_tax_rate")) or {} | ||
|
|
||
| if tax.get("account_head") in item_tax_rate: | ||
| return flt(item_tax_rate[tax.account_head]) | ||
|
|
||
| return flt(tax.get("rate")) | ||
|
|
||
|
|
||
| def _inclusive_rate(doc, item, tax): | ||
| # CGST and SGST rows share one base, so their rates add up | ||
| rates = [_item_rate(item, t) for t in doc.get("taxes") or [] if t.charge_type == tax.charge_type] | ||
| return sum(rates) or _item_rate(item, tax) | ||
|
|
||
|
|
||
| # Rule 31D: tax from the MRP, report the net sale value | ||
| def on_mrp(calc, item, tax): | ||
| conversion_rate = flt(calc.doc.get("conversion_rate")) or 1 | ||
| rate = _inclusive_rate(calc.doc, item, tax) | ||
| rsp = flt(item.get("gst_retail_sale_price")) * flt(item.qty) / conversion_rate | ||
| deemed = rsp * 100 / (100 + rate) if rate else rsp | ||
|
|
||
| item._dont_update_taxable_value = True | ||
| item._deemed_taxable_value = deemed * conversion_rate | ||
|
|
||
| return deemed | ||
|
|
||
|
|
||
| # Rule 32(5): only the margin is taxed; Rule 35 takes GST out when the price includes it | ||
| def on_margin(calc, item, tax): | ||
| conversion_rate = flt(calc.doc.get("conversion_rate")) or 1 | ||
| cost = flt(item.get("gst_purchase_price")) * flt(item.qty) / conversion_rate | ||
| margin = flt(item.amount) - cost | ||
| if abs(flt(item.amount)) < abs(cost): | ||
| margin = 0 | ||
|
|
||
| if not tax.get("included_in_print_rate"): | ||
| return margin | ||
|
|
||
| rate = _inclusive_rate(calc.doc, item, tax) | ||
| return margin * 100 / (100 + rate) if rate else margin | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.