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: Mapping of Sales and Purchase Templates #2485

Merged
merged 11 commits into from
Aug 2, 2024
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import frappe
from frappe import _, bold
from frappe.contacts.doctype.address.address import get_address_display
from erpnext.accounts.party import get_address_tax_category
from erpnext.stock.get_item_details import get_item_tax_template

from india_compliance.gst_india.overrides.sales_invoice import (
update_dashboard_with_gst_logs,
Expand All @@ -9,6 +11,7 @@
GSTAccounts,
get_place_of_supply,
ignore_gst_validations,
is_inter_state_supply,
set_gst_tax_type,
validate_gst_category,
validate_gst_transporter_id,
Expand All @@ -17,7 +20,7 @@
validate_mandatory_fields,
validate_place_of_supply,
)
from india_compliance.gst_india.utils import is_api_enabled
from india_compliance.gst_india.utils import get_gst_accounts_by_type, is_api_enabled
from india_compliance.gst_india.utils.e_waybill import get_e_waybill_info
from india_compliance.gst_india.utils.taxes_controller import (
CustomTaxController,
Expand All @@ -29,6 +32,68 @@
SUBCONTRACTING_ORDER_RECEIPT_FIELD_MAP = {"total_taxable_value": "total"}


def after_mapping(doc, method, source_doc):
doc.taxes_and_charges = ""
doc.taxes = []
if ignore_gst_validations(doc):
return

set_taxes(doc)

tax_category = source_doc.tax_category

if not tax_category:
tax_category = get_address_tax_category(
frappe.db.get_value("Supplier", source_doc.supplier, "tax_category"),
source_doc.supplier_address,
)

if not tax_category:
Ninad1306 marked this conversation as resolved.
Show resolved Hide resolved
return

args = {"company": doc.company, "tax_category": tax_category}

for item in doc.items:
out = {}
item_doc = frappe.get_cached_doc("Item", item.item_code)
get_item_tax_template(args, item_doc, out)
item.item_tax_template = out.get("item_tax_template")


def set_taxes(doc):
tax_types = ["cgst", "sgst"]
if is_inter_state_supply(doc):
tax_types = ["igst"]

for tax_type in tax_types:
account = get_gst_accounts_by_type(doc.company, "Output").get(
tax_type + "_account"
)

if not account:
return

rate, description = frappe.db.get_value(
"Sales Taxes and Charges",
{
"parenttype": "Sales Taxes and Charges Template",
"account_head": account,
},
("rate", "description"),
) or (0, account)

doc.append(
"taxes",
{
"charge_type": "On Net Total",
"account_head": account,
"rate": rate,
"gst_tax_type": tax_type,
"description": description,
},
)


def get_dashboard_data(data):
doctype = (
"Subcontracting Receipt"
Expand Down
1 change: 1 addition & 0 deletions india_compliance/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@
},
"Subcontracting Order": {
"validate": "india_compliance.gst_india.overrides.subcontracting_transaction.validate",
"after_mapping": "india_compliance.gst_india.overrides.subcontracting_transaction.after_mapping",
},
"Subcontracting Receipt": {
"onload": "india_compliance.gst_india.overrides.subcontracting_transaction.onload",
Expand Down