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: item wise tax details and net amounts #43372

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
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@
"rate",
"section_break_9",
"currency",
"net_amount",
"tax_amount",
"total",
"allocated_amount",
"column_break_13",
"base_tax_amount",
"base_net_amount",
"base_total"
],
"fields": [
Expand Down Expand Up @@ -174,12 +176,29 @@
"label": "Account Currency",
"options": "Currency",
"read_only": 1
},
{
"columns": 2,
"fieldname": "net_amount",
"fieldtype": "Currency",
"in_list_view": 1,
"label": "Net Amount",
"options": "currency"
},
{
"fieldname": "base_net_amount",
"fieldtype": "Currency",
"label": "Net Amount (Company Currency)",
"oldfieldname": "tax_amount",
"oldfieldtype": "Currency",
"options": "Company:company:default_currency",
"read_only": 1
}
],
"index_web_pages_for_search": 1,
"istable": 1,
"links": [],
"modified": "2024-03-27 13:05:58.437605",
"modified": "2024-09-24 06:51:07.417348",
"modified_by": "Administrator",
"module": "Accounts",
"name": "Advance Taxes and Charges",
Expand All @@ -188,4 +207,4 @@
"sort_field": "creation",
"sort_order": "ASC",
"states": []
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class AdvanceTaxesandCharges(Document):
account_head: DF.Link
add_deduct_tax: DF.Literal["Add", "Deduct"]
allocated_amount: DF.Currency
base_net_amount: DF.Currency
base_tax_amount: DF.Currency
base_total: DF.Currency
charge_type: DF.Literal[
Expand All @@ -27,6 +28,7 @@ class AdvanceTaxesandCharges(Document):
currency: DF.Link | None
description: DF.SmallText
included_in_paid_amount: DF.Check
net_amount: DF.Currency
parent: DF.Data
parentfield: DF.Data
parenttype: DF.Data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from frappe.utils.scheduler import is_scheduler_inactive

from erpnext.accounts.doctype.pos_profile.pos_profile import required_accounting_dimensions
from erpnext.controllers.taxes_and_totals import ItemWiseTaxDetail


class POSInvoiceMergeLog(Document):
Expand Down Expand Up @@ -336,15 +337,14 @@ def update_item_wise_tax_detail(consolidate_tax_row, tax_row):
consolidated_tax_detail = {}

for item_code, tax_data in tax_row_detail.items():
tax_data = ItemWiseTaxDetail(**tax_data)
if consolidated_tax_detail.get(item_code):
consolidated_tax_data = consolidated_tax_detail.get(item_code)
consolidated_tax_detail.update(
{item_code: [consolidated_tax_data[0], consolidated_tax_data[1] + tax_data[1]]}
)
consolidated_tax_detail[item_code]["tax_amount"] += tax_data.tax_amount
consolidated_tax_detail[item_code]["net_amount"] += tax_data.net_amount
else:
consolidated_tax_detail.update({item_code: [tax_data[0], tax_data[1]]})
consolidated_tax_detail.update({item_code: tax_data})

consolidate_tax_row.item_wise_tax_detail = json.dumps(consolidated_tax_detail, separators=(",", ":"))
consolidate_tax_row.item_wise_tax_detail = json.dumps(consolidated_tax_detail)


def get_all_unconsolidated_invoices():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,13 +158,15 @@ def test_consolidated_invoice_item_taxes(self):
consolidated_invoice = frappe.get_doc("Sales Invoice", inv.consolidated_invoice)
item_wise_tax_detail = json.loads(consolidated_invoice.get("taxes")[0].item_wise_tax_detail)

tax_rate, amount = item_wise_tax_detail.get("_Test Item")
self.assertEqual(tax_rate, 9)
self.assertEqual(amount, 9)

tax_rate2, amount2 = item_wise_tax_detail.get("_Test Item 2")
self.assertEqual(tax_rate2, 5)
self.assertEqual(amount2, 5)
tax_data = item_wise_tax_detail.get("_Test Item")
self.assertEqual(tax_data.get("tax_rate"), 9)
self.assertEqual(tax_data.get("tax_amount"), 9)
self.assertEqual(tax_data.get("net_amount"), 100)

tax_data = item_wise_tax_detail.get("_Test Item 2")
self.assertEqual(tax_data.get("tax_rate"), 5)
self.assertEqual(tax_data.get("tax_amount"), 5)
self.assertEqual(tax_data.get("net_amount"), 100)
finally:
frappe.set_user("Administrator")
frappe.db.sql("delete from `tabPOS Profile`")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@
"dimension_col_break",
"section_break_9",
"account_currency",
"net_amount",
"tax_amount",
"tax_amount_after_discount_amount",
"total",
"column_break_14",
"base_net_amount",
"base_tax_amount",
"base_total",
"base_tax_amount_after_discount_amount",
Expand Down Expand Up @@ -233,12 +235,30 @@
"fieldtype": "Check",
"label": "Is Tax Withholding Account",
"read_only": 1
},
{
"columns": 2,
"fieldname": "net_amount",
"fieldtype": "Currency",
"in_list_view": 1,
"label": "Net Amount",
"oldfieldname": "tax_amount",
"oldfieldtype": "Currency",
"options": "currency"
},
{
"fieldname": "base_net_amount",
"fieldtype": "Currency",
"label": "Net Amount (Company Currency)",
"options": "Company:company:default_currency",
"print_hide": 1,
"read_only": 1
}
],
"idx": 1,
"istable": 1,
"links": [],
"modified": "2024-04-08 19:51:36.678551",
"modified": "2024-09-24 06:47:25.129901",
"modified_by": "Administrator",
"module": "Accounts",
"name": "Purchase Taxes and Charges",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class PurchaseTaxesandCharges(Document):
account_currency: DF.Link | None
account_head: DF.Link
add_deduct_tax: DF.Literal["Add", "Deduct"]
base_net_amount: DF.Currency
base_tax_amount: DF.Currency
base_tax_amount_after_discount_amount: DF.Currency
base_total: DF.Currency
Expand All @@ -35,6 +36,7 @@ class PurchaseTaxesandCharges(Document):
included_in_print_rate: DF.Check
is_tax_withholding_account: DF.Check
item_wise_tax_detail: DF.Code | None
net_amount: DF.Currency
parent: DF.Data
parentfield: DF.Data
parenttype: DF.Data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2071,12 +2071,12 @@ def test_item_wise_tax_breakup(self):
{
"item": "_Test Item",
"taxable_amount": 10000.0,
"Service Tax": {"tax_rate": 10.0, "tax_amount": 1000.0},
"Service Tax": {"tax_rate": 10.0, "tax_amount": 1000.0, "net_amount": 10000.0},
},
{
"item": "_Test Item 2",
"taxable_amount": 5000.0,
"Service Tax": {"tax_rate": 10.0, "tax_amount": 500.0},
"Service Tax": {"tax_rate": 10.0, "tax_amount": 500.0, "net_amount": 5000.0},
},
]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@
"rate",
"section_break_9",
"account_currency",
"net_amount",
"tax_amount",
"total",
"tax_amount_after_discount_amount",
"column_break_13",
"base_net_amount",
"base_tax_amount",
"base_total",
"base_tax_amount_after_discount_amount",
Expand Down Expand Up @@ -212,13 +214,30 @@
"label": "Account Currency",
"options": "Currency",
"read_only": 1
},
{
"columns": 2,
"fieldname": "net_amount",
"fieldtype": "Currency",
"in_list_view": 1,
"label": "Net Amount",
"options": "currency"
},
blaggacao marked this conversation as resolved.
Show resolved Hide resolved
{
"fieldname": "base_net_amount",
"fieldtype": "Currency",
"label": "Net Amount (Company Currency)",
"oldfieldname": "tax_amount",
"oldfieldtype": "Currency",
"options": "Company:company:default_currency",
"read_only": 1
}
],
"idx": 1,
"index_web_pages_for_search": 1,
"istable": 1,
"links": [],
"modified": "2024-03-27 13:10:38.190993",
"modified": "2024-09-24 06:49:32.034074",
"modified_by": "Administrator",
"module": "Accounts",
"name": "Sales Taxes and Charges",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class SalesTaxesandCharges(Document):

account_currency: DF.Link | None
account_head: DF.Link
base_net_amount: DF.Currency
base_tax_amount: DF.Currency
base_tax_amount_after_discount_amount: DF.Currency
base_total: DF.Currency
Expand All @@ -33,6 +34,7 @@ class SalesTaxesandCharges(Document):
included_in_paid_amount: DF.Check
included_in_print_rate: DF.Check
item_wise_tax_detail: DF.Code | None
net_amount: DF.Currency
parent: DF.Data
parentfield: DF.Data
parenttype: DF.Data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

from erpnext.accounts.report.sales_register.sales_register import get_mode_of_payments
from erpnext.accounts.report.utils import get_query_columns, get_values_for_columns
from erpnext.controllers.taxes_and_totals import ItemWiseTaxDetail
from erpnext.selling.report.item_wise_sales_history.item_wise_sales_history import (
get_customer_details,
)
Expand Down Expand Up @@ -596,22 +597,20 @@ def get_tax_accounts(
for item_code, tax_data in item_wise_tax_detail.items():
itemised_tax.setdefault(item_code, frappe._dict())

if isinstance(tax_data, list):
tax_rate, tax_amount = tax_data
else:
tax_rate = tax_data
tax_amount = 0
tax_data = ItemWiseTaxDetail(**tax_data)

if charge_type == "Actual" and not tax_rate:
tax_rate = "NA"
if charge_type == "Actual" and not tax_data.tax_rate:
tax_data.tax_rate = "NA"

item_net_amount = sum(
[flt(d.base_net_amount) for d in item_row_map.get(parent, {}).get(item_code, [])]
)

for d in item_row_map.get(parent, {}).get(item_code, []):
item_tax_amount = (
flt((tax_amount * d.base_net_amount) / item_net_amount) if item_net_amount else 0
flt((tax_data.tax_amount * d.base_net_amount) / item_net_amount)
if item_net_amount
else 0
)
if item_tax_amount:
tax_value = flt(item_tax_amount, tax_amount_precision)
Expand All @@ -623,7 +622,7 @@ def get_tax_accounts(

itemised_tax.setdefault(d.name, {})[description] = frappe._dict(
{
"tax_rate": tax_rate,
"tax_rate": tax_data.tax_rate,
"tax_amount": tax_value,
"is_other_charges": 0 if tuple([account_head]) in tax_accounts else 1,
}
Expand Down
Loading
Loading