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 62f43f9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 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
12 changes: 9 additions & 3 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,10 +690,15 @@ 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
Expand Down

0 comments on commit 62f43f9

Please sign in to comment.