def get_itemised_tax_breakup_data(doc): itemised_tax = get_itemised_tax(doc.taxes) itemised_taxable_amount = get_itemised_taxable_amount(doc.items) if not frappe.get_meta(doc.doctype + " Item").has_field('gst_hsn_code'): return itemised_tax, itemised_taxable_amount item_hsn_map = frappe._dict() for d in doc.items: item_hsn_map.setdefault(d.item_code or d.item_name, d.get("gst_hsn_code")) hsn_tax = {} for item, taxes in itemised_tax.items(): hsn_code = item_hsn_map.get(item) hsn_tax.setdefault(hsn_code, frappe._dict()) for tax_account, tax_detail in taxes.items(): hsn_tax[hsn_code].setdefault(tax_account, {"tax_rate": 0, "tax_amount": 0}) hsn_tax[hsn_code][tax_account]["tax_rate"] = tax_detail.get("tax_rate") hsn_tax[hsn_code][tax_account]["tax_amount"] += tax_detail.get("tax_amount") # set taxable amount hsn_taxable_amount = frappe._dict() for item, taxable_amount in itemised_taxable_amount.items(): hsn_code = item_hsn_map.get(item) hsn_taxable_amount.setdefault(hsn_code, 0) hsn_taxable_amount[hsn_code] += itemised_taxable_amount.get(item) return hsn_tax, hsn_taxable_amount
def get_itemised_tax_breakup_data(doc): itemised_tax = get_itemised_tax(doc.taxes) itemised_taxable_amount = get_itemised_taxable_amount(doc.items) if not frappe.get_meta(doc.doctype + " Item").has_field('gst_hsn_code'): return itemised_tax, itemised_taxable_amount item_hsn_map = frappe._dict() for d in doc.items: item_hsn_map.setdefault(d.item_code or d.item_name, d.get("gst_hsn_code")) hsn_tax = {} for item, taxes in itemised_tax.items(): hsn_code = item_hsn_map.get(item) hsn_tax.setdefault(hsn_code, frappe._dict()) for tax_account, tax_detail in taxes.items(): hsn_tax[hsn_code].setdefault(tax_account, { "tax_rate": 0, "tax_amount": 0 }) hsn_tax[hsn_code][tax_account]["tax_rate"] = tax_detail.get( "tax_rate") hsn_tax[hsn_code][tax_account]["tax_amount"] += tax_detail.get( "tax_amount") # set taxable amount hsn_taxable_amount = frappe._dict() for item, taxable_amount in itemised_taxable_amount.items(): hsn_code = item_hsn_map.get(item) hsn_taxable_amount.setdefault(hsn_code, 0) hsn_taxable_amount[hsn_code] += itemised_taxable_amount.get(item) return hsn_tax, hsn_taxable_amount
def get_itemised_tax_breakup_data(doc, account_wise=False, hsn_wise=False): itemised_tax = get_itemised_tax(doc.taxes, with_tax_account=account_wise) itemised_taxable_amount = get_itemised_taxable_amount(doc.items) if not frappe.get_meta(doc.doctype + " Item").has_field("gst_hsn_code"): return itemised_tax, itemised_taxable_amount hsn_wise_in_gst_settings = frappe.db.get_single_value( "GST Settings", "hsn_wise_tax_breakup") tax_breakup_hsn_wise = hsn_wise or hsn_wise_in_gst_settings if tax_breakup_hsn_wise: item_hsn_map = frappe._dict() for d in doc.items: item_hsn_map.setdefault(d.item_code or d.item_name, d.get("gst_hsn_code")) hsn_tax = {} for item, taxes in itemised_tax.items(): item_or_hsn = item if not tax_breakup_hsn_wise else item_hsn_map.get( item) hsn_tax.setdefault(item_or_hsn, frappe._dict()) for tax_desc, tax_detail in taxes.items(): key = tax_desc if account_wise: key = tax_detail.get("tax_account") hsn_tax[item_or_hsn].setdefault(key, { "tax_rate": 0, "tax_amount": 0 }) hsn_tax[item_or_hsn][key]["tax_rate"] = tax_detail.get("tax_rate") hsn_tax[item_or_hsn][key]["tax_amount"] += tax_detail.get( "tax_amount") # set taxable amount hsn_taxable_amount = frappe._dict() for item in itemised_taxable_amount: item_or_hsn = item if not tax_breakup_hsn_wise else item_hsn_map.get( item) hsn_taxable_amount.setdefault(item_or_hsn, 0) hsn_taxable_amount[item_or_hsn] += itemised_taxable_amount.get(item) return hsn_tax, hsn_taxable_amount