How to calculate GST in custom print format in erpnext?

I have created a Sales Invoice as per GST rules. All the calculations in Invoice is working properly in my custom print format.
I need to calculate GST in my custom print format as same as “GST Tax Invoice” template. Can anyone tell me how to do that or what is object name through which I can fetch the data same like in GST Tax Invoice calculating.

This is GST Tax Invoice Template

It would be highly appreciated if someone will provide me complete guidance to implement! :slightly_smiling_face:

this is custom print format

You can duplidate GST Tax Invoice print format from:

  1. Setup > Print Format > GST Tax Invoice > Menu > Duplicate

  2. Give name to a Custom Print Format.

  3. Open Custom Print Format (duplicated from GST format) in the Print Format Builder.

  4. Add/Edit fields in the print format as per your requirement and save.

Hope this helps.

Thanks for your reply @umair .

But can you please tell me where to find the template code of GST Tax Invoice.

Actually I need to show GST in my custom HTML coded template which is very different from default GST Tax Invoice template.

Hi, copy and paste beow code. You can print many number of tax rows as you want.

        {%- for row in doc.taxes -%}
            {%- if not row.included_in_print_rate -%}
            {% if row.tax_amount > 0  %}
                                  
                <div style='border:1px solid #ccc;' class="col-xs-6 text-left "> <b> {{ row.description }}</b></div>   
                    <div style='border:1px solid #ccc;' class="col-xs-6 text-right ">{{row.get_formatted("tax_amount")}}</div>

             {%- endif -%} 
            {%- endif -%}
        {%- endfor -%} 

    </div>
4 Likes

Thank you so much @anandhuded2

That works really great. :grinning:

You are welcome to use this code @UmaG has developed:

How to display Item Wise Tax in invoice?

Thanks

Jay

1 Like

In item wise tax markup, how to calculate for each grouped item?

{{ doc.other_charges_calculation }}

I have just fetching item wise tax markup by calling {{ doc.other_charges_calculation }}.

Dear Jay,

I have used the documents you all referred for Itemwise tax calculation. But I get below error:

jinja2.exceptions.UndefinedError: ‘erpnext.stock.doctype.item_tax.item_tax.ItemTax object’ has no attribute ‘tax_rate’

Please help on this.

My code is as below.

<tr style="border-color : black ;">
   <td width=15% rowspan=4 colspan=2 style="border-color : black ; border-right-color : white ;" >
  
  <img src=http://192.168.1.30/files/Ekabyte%20logo.jpg alt="logo" width="150" height="39"><br><br>
   <td width=25% colspan=2>
       Invoice No.<br>
       <b>{{ doc.name }}</b>
   </td>
   <td width=25% colspan=8>
       Dated<br>
   <b>{{ frappe.utils.formatdate(doc.posting_date) }}</b>
   </td>
{{ doc.company or "" }} {{ frappe.db.get_value("Company", doc.company, "registration_details") or "" }}

#8/2, 1st Floor, ARK Complex,
Sri Abhinav Vidyathirta Road,
Chikkanna Garden, Shankarapuram,
Bengaluru-560 004.India

Referrence No. &   Date
{{ doc.name }} dt.  {{ frappe.utils.formatdate(doc.posting_date) }}  
Other Reference(s)
{{doc.contact_display or ""}}  
Buyer's Order No.
{{doc.po_no or " "}}  
Dated
{{doc.po_date or ""}}  
Eway Bill No.
{{doc.ewaybill or ""}}  
Despatch Document No & Date
{{doc.despatch_document_no_and_date or ""}}  
Buyer (Bill to)
{{ doc.customer_name or "" }}
{{ doc.address_display or "" }}
   </td>
   

</tr>
Despatched through
{{doc.transporter or ""}}  
Destination
{{doc.destination or ""}}  
Shipping Address
       <p><b>{{ doc.dispatch_address_name or "" }}</b></p>
        <p>{{ doc.dispatch_address or "" }}</p>
   
  
   </td>
<table>
    
<tbody>

<tr class="">
	<th bgcolor= "orange" width="3%" class="text-center">Sl.<br>No</th>
	<th bgcolor= "orange" colspan=3 width="54%" class="text-center">Product Description</th>
    <th bgcolor= "orange" width="5%" class="text-center">HSN/SAC Code</th>
    <th bgcolor= "orange" width="5%" class="text-center">Unit Price</th>
	<th bgcolor= "orange" width="2%" class="text-center">Qty</th>
	<th bgcolor= "orange" width="8%" class="text-center">CGST</th>
	<th bgcolor= "orange" width="9%" class="text-center">SGST</th>
	<th bgcolor= "orange" width="9%" class="text-center">IGST</th>
	<th bgcolor= "orange" width="5%" class="text-center">Total</th>
</tr>




{% set cgst_rate = [] -%}
 {% set sgst_rate = [] -%}
 {% set igst_rate = [] -%}
{% set cgst_account_head = [] -%}
 {% set sgst_account_head = [] -%}
 {% set igst_account_head = [] -%}
{% set tot_cgst_amount = [] %}
{% set tot_sgst_amount = [] %}


{% set grand_total = {"qty":0.0, "amount":0.0, "cgst_amt":0.0, "sgst_amt":0.0, "igst_amt":0.0} %}
{%- for row in doc.taxes -%}
   {% if 'CGST' in row.account_head -%}
	{% set _ = cgst_account_head.append(row.account_head) %}
	{% set _ = cgst_rate.append(row.rate) %}
   {%- endif -%}
   {% if 'SGST' in row.account_head -%}
	 {% set _ = sgst_account_head.append(row.account_head) %}
	{% set _ = sgst_rate.append(row.rate) %}	
   {%- endif -%}
   {% if 'IGST' in row.account_head -%}
	{% set _ = igst_account_head.append(row.account_head) %}
	{% set _ = igst_rate.append(row.rate) %}
   {%- endif -%}
{%- endfor -%}

{%- for row in doc.items -%}


{% set cgst_amt = [] -%}
{% set sgst_amt = [] -%}
{% set igst_amt = [] -%}
{% set it_cgst_rate = [] -%}
{% set it_sgst_rate = [] -%}
{% set it_igst_rate = [] -%}
{% set rate_found_item = 0 -%}
      {%- set item_record = frappe.get_doc("Item", row.item_code) -%}
	{% for item_tax in item_record.taxes %}
	  {% if item_tax.tax_type == igst_account_head[0] %}	
		{% set _ = it_igst_rate.append(item_tax.tax_rate) %}
		{% set _ = igst_amt.append(row.amount * it_igst_rate[0] / 100) -%}
		{% set rate_found_item = 1 -%}
	{% endif %}		
	{% if item_tax.tax_type == sgst_account_head[0] %}
		
		{% set _ = it_sgst_rate.append(item_tax.tax_rate) %}
		{% set _ = sgst_amt.append(row.amount * it_sgst_rate[0] / 100) -%}
		{% set rate_found_item = 1 -%}
	{% endif %}	
	{% if item_tax.tax_type == cgst_account_head[0] %}
		{% set _ = it_cgst_rate.append(item_tax.tax_rate) %}
		{% set _ = cgst_amt.append(row.amount * it_cgst_rate[0] / 100) -%}
		{% set rate_found_item = 1 -%}
	{% endif %}		
{% endfor %}	
{% if rate_found_item == 0 %}

	{% if cgst_rate[0] -%}
	   {% set _ = cgst_amt.append((row.amount * cgst_rate[0])/100) -%}
	   {% set _= it_cgst_rate.append(cgst_rate[0]) -%}
	   {% set rate_found_inv = 1 -%}
       	{%- endif -%}
	{% if sgst_rate[0] -%}
	   {% set _ = sgst_amt.append((row.amount * sgst_rate[0])/100) -%}
	   {% set _= it_sgst_rate.append(sgst_rate[0]) -%}
	   
       	{%- endif -%}
	{% if igst_rate[0] -%}
	   {% set _ = igst_amt.append((row.amount * igst_rate[0])/100) -%}
	   {% set _= it_igst_rate.append(igst_rate[0]) -%}
	   {% set rate_found_inv = 1 -%}
       	{%- endif -%}
{% endif %}
{% if not it_cgst_rate[0] %}
	{% set _ = it_cgst_rate.append(0) %}
	{% set _ = cgst_amt.append(0) %}
{% endif %}
{% if not it_sgst_rate[0] %}
	{% set _ = it_sgst_rate.append(0) %}
	{% set _ = sgst_amt.append(0) %}
{% endif %}
{% if not it_igst_rate[0] %}
	{% set _ = it_igst_rate.append(0) %}
	{% set _ = igst_amt.append(0) %}
{% endif %}
{% set temp_cgst_amt = grand_total["cgst_amt"] + cgst_amt[0] %}
{% set temp_sgst_amt = grand_total["sgst_amt"] + sgst_amt[0] %}
{% set temp_igst_amt = grand_total["igst_amt"] + igst_amt[0] %}
{% set temp_qty = grand_total["qty"] + row.qty %}
{% set temp_amount = grand_total["amount"] + row.amount %}
{% set check = grand_total.update({"qty": temp_qty, "amount": temp_amount, "cgst_amt":temp_cgst_amt, "sgst_amt":temp_sgst_amt, "igst_amt":temp_igst_amt}) %}



	<td style="width: 6%; text-align: center;"><span style="font-family:verdana;"><span style="font-size: 8px;"></span></span>{{ row.idx }}</td>

    
	<td style="width: 48%;" colspan=3><span style="font-family:verdana;"><span style="font-size: 8px;"></span></span>
		                  
      
		     
      <b> {{ row.item_name }} </b> <br>
        <p> {{ row.description }} </p>
        
         {% if row.part_number != None %}
       <b>Part No: {{row.get_formatted("part_number", doc) }}</b><br>
      {%- endif %}
		     
                    
     {% if row.warranty != None %}
      <b> Wty:  {{row.get_formatted("warranty", doc) }}</b><br>
     {%- endif %} 

     {% if row.serial_no != None %}
      <b>Serial No: {{ row.serial_no }} </b>
     {%- endif %}
    <td style="width: 10%; text-align: center;"><span style="font-family:verdana;"><span style="font-size: 8px;"></span></span>{% if row.gst_hsn_code != None %}{{ row.gst_hsn_code }} {%- endif %}</td>
    <td style="width: 1%; text-align: right;"><span style="font-family:verdana;"><span style="font-size: 8px;"></span></span>{{
		row.get_formatted("rate", doc) }}</td>
    
        
    
         
    
	
	<td style="width: 1%; text-align: center;"><span style="font-family:verdana;"><span style="font-size: 8px;"></span></span>{{ row.qty|round|int }}<br><small>{{ row.uom or row.stock_uom }}</small></td>
	
	<td style="width: 9%; text-align: right;"><span style="font-family:verdana;"><span style="font-size: 8px;"></span></span>{{
		"{:,.2f}".format(cgst_amt[0])  }}<br><small>{{
		it_cgst_rate[0] }}%</small></td>
	<td style="width: 9%; text-align: right;"><span style="font-family:verdana;"><span style="font-size: 8px;"></span></span>{{
		"{:,.2f}".format(sgst_amt[0])  }}<br><small>{{
		it_sgst_rate[0] }}%</small></td>
	<td style="width: 9%; text-align: right;"><span style="font-family:verdana;"><span style="font-size: 8px;"></span></span>{{
		"{:,.2f}".format(igst_amt[0])  }}<br><small>{{
		it_igst_rate[0] }}%</small></td>
    
	<td style="width: 10%; text-align: right;" colspan=2><span style="font-family:verdana;"><span style="font-size: 8px;"></span></span> <b>  {{
		row.get_formatted("amount", doc) }} </b></td>
{%- endfor -%}
<TD  colspan=6 align=left ><B>SUB TOTAL</B></TD>


<TD WIDTH=10% align=center><B>{{ doc.get_formatted("total_qty", doc) }}</B></TD>      
<TD WIDTH=10% align=right><B>{{ "{:,.2f}".format(grand_total["cgst_amt"])  }}</B></TD>
<TD WIDTH=10% align=right><B>{{ "{:,.2f}".format(grand_total["sgst_amt"])  }}</B></TD>
<TD  WIDTH=10% align=right><B>{{ "{:,.2f}".format(grand_total["igst_amt"])  }}</B></TD>
    
<TD  WIDTH=20% align=right><B>{{ doc.get_formatted("total", doc) }}</B></TD>
<TR>
GST Total {{ doc.get_formatted("total_taxes_and_charges", doc) }} ADJ {{ doc.get_formatted("base_rounding_adjustment", doc) }} Grand Total (INR) {{ doc.get_formatted("base_grand_total", doc) }} Amount Chargeable (in Words):
{{ doc.get_formatted("base_in_words", doc) }}
<TD  colspan=5 align=left >

Declaration

  1. Goods once sold will not be taken back or exchanged.
  2. All Payments should be made by A/C Payee Cheque/DD.
  3. Payment should be made immediately on delivery
    otherwise interest @ 21% Per annum will be charged Rs.250/- will
    be charged for cheque bounce.
  4. Warranty on all materials are as per manufacturer’s policy.
  5. No Warranty on Burnt, Physical damage and Track cut items.
Date & Time           : {{ doc.get_formatted("posting_date", doc) }} at {{ doc.get_formatted("posting_time", doc) }}
Company's Bank Details
Bank Name            :
A/c No.                   :
Customer's seal and Signature for {{ doc.company }}
                                                                         Authorised Signatory

This is a Computer Generated Invoice

Please help on this