Skip to content

Commit

Permalink
fix: tax_item_rate calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
blaggacao committed Nov 20, 2024
1 parent 9673bf8 commit b8a81f7
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 12 deletions.
10 changes: 6 additions & 4 deletions erpnext/controllers/accounts_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -3176,10 +3176,12 @@ def set_child_tax_template_and_map(item, child_item, parent_doc):
)

child_item.item_tax_template = _get_item_tax_template(ctx, item.taxes)
if child_item.get("item_tax_template"):
child_item.item_tax_rate = get_item_tax_map(
parent_doc.get("company"), child_item.item_tax_template, as_json=True
)
child_item.item_tax_rate = get_item_tax_map(
parent_doc.get("company"),
child_item.item_tax_template,
as_json=True,
parent_doc=parent_doc,
)


def add_taxes_from_tax_template(child_item, parent_doc, db_insert=True):
Expand Down
4 changes: 1 addition & 3 deletions erpnext/controllers/taxes_and_totals.py
Original file line number Diff line number Diff line change
Expand Up @@ -501,9 +501,7 @@ def get_current_tax_and_net_amount(self, item, tax, item_tax_map):
)

elif tax.charge_type == "On Net Total":
if not item_tax_map:
current_net_amount = item.net_amount
elif tax.account_head in item_tax_map:
if tax.account_head in item_tax_map:
current_net_amount = item.net_amount
current_tax_amount = (tax_rate / 100.0) * item.net_amount
elif tax.charge_type == "On Previous Row Amount":
Expand Down
24 changes: 19 additions & 5 deletions erpnext/stock/get_item_details.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ def get_item_details(
ctx.company,
out.item_tax_template or ctx.item_tax_template,
as_json=True,
parent_doc=doc,
)

get_party_item_code(ctx, item, out)
Expand Down Expand Up @@ -689,13 +690,26 @@ def is_within_valid_range(ctx: ItemDetailsCtx, tax) -> bool:


@frappe.whitelist()
def get_item_tax_map(company, item_tax_template, as_json=True):
def get_item_tax_map(company, tax_template=None, as_json=True, parent_doc: dict | Document | None = None):
item_tax_map = {}
if item_tax_template:
template = frappe.get_cached_doc("Item Tax Template", item_tax_template)
doctype = "Item Tax Template"
if not tax_template and parent_doc:
doctype = frappe.get_meta(parent_doc).get_link_doctype("taxes_and_charges")
tax_template = parent_doc.get("taxes_and_charges")

if doctype and tax_template:
template = frappe.get_cached_doc(doctype, tax_template)
for d in template.taxes:
if frappe.get_cached_value("Account", d.tax_type, "company") == company:
item_tax_map[d.tax_type] = d.tax_rate
try:
# Item Tax Template
account_head = d.tax_type
rate = d.tax_rate
except AttributeError:
# Sales/Purchase Taxes and Charges
account_head = d.account_head
rate = d.rate
if frappe.get_cached_value("Account", account_head, "company") == company:
item_tax_map[account_head] = rate

return json.dumps(item_tax_map) if as_json else item_tax_map

Expand Down

0 comments on commit b8a81f7

Please sign in to comment.