Item wise Tax rate issue

Dear Team, I was further troubleshooting with itemwise tax rate and it shows as below error:

Failed to load resource: the server responded with a status of 417 (EXPECTATION FAILED)

Traceback (most recent call last):
File “apps/frappe/frappe/utils/jinja.py”, line 94, in render_template
return get_jenv().from_string(template).render(context)
File “env/lib/python3.9/site-packages/jinja2/environment.py”, line 1291, in render
self.environment.handle_exception()
File “env/lib/python3.9/site-packages/jinja2/environment.py”, line 925, in handle_exception
raise rewrite_traceback_stack(source=source)
File “”, line 183, in top-level template code
jinja2.exceptions.UndefinedError: ‘erpnext.stock.doctype.item_tax.item_tax.ItemTax object’ has no attribute ‘tax_rate’

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “apps/frappe/frappe/app.py”, line 69, in application
response = frappe.api.handle()
File “apps/frappe/frappe/api.py”, line 55, in handle
return frappe.handler.handle()
File “apps/frappe/frappe/handler.py”, line 37, in handle
data = execute_cmd(cmd)
File “apps/frappe/frappe/handler.py”, line 75, in execute_cmd
return frappe.call(method, **frappe.form_dict)
File “apps/frappe/frappe/init.py”, line 1447, in call
return fn(*args, **newargs)
File “apps/frappe/frappe/www/printview.py”, line 246, in get_html_and_style
html = get_rendered_template(
File “apps/frappe/frappe/www/printview.py”, line 205, in get_rendered_template
html = template.render(args, filters={“len”: len})
File “env/lib/python3.9/site-packages/jinja2/environment.py”, line 1291, in render
self.environment.handle_exception()
File “env/lib/python3.9/site-packages/jinja2/environment.py”, line 925, in handle_exception
raise rewrite_traceback_stack(source=source)
File “apps/frappe/frappe/templates/print_formats/standard.html”, line 32, in top-level template code
{{ render_field(df, doc, no_of_cols) }}
File “env/lib/python3.9/site-packages/jinja2/sandbox.py”, line 393, in call
return __context.call(__obj, *args, **kwargs)
File “env/lib/python3.9/site-packages/jinja2/runtime.py”, line 828, in _invoke
rv = self._func(*arguments)
File “apps/frappe/frappe/templates/print_formats/standard_macros.html”, line 5, in template

{{ frappe.render_template(df.options, {“doc”: doc}) or “” }}

File “env/lib/python3.9/site-packages/jinja2/sandbox.py”, line 393, in call
return __context.call(__obj, *args, **kwargs)
File “apps/frappe/frappe/utils/jinja.py”, line 96, in render_template
throw(
File “apps/frappe/frappe/init.py”, line 503, in throw
msgprint(
File “apps/frappe/frappe/init.py”, line 478, in msgprint
_raise_exception()
File “apps/frappe/frappe/init.py”, line 433, in _raise_exception
raise raise_exception(msg)
frappe.exceptions.ValidationError:

Is this might be any issue with the python components need to
be addressed here. Kindly guide me to fix the issue.

Hi ,

It may help to say the context in which the error occurred. What was the action that produced the error? The message suggests a jinja problem, was there any customization of a print template involved?

This error occurs while printing Sales invoice PDF. Sales invoice template not rendering.

  1. I go to sales invoice and having different taxes for different item as shown below image.

  1. I try to print the page. But its not rendering. Screenshot attached.

My code as below:

   <P class="a"><div align="center"> <h2> Tax Invoice </h2> </div>

<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>
{{ 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

   </td>
  
   <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>
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 tot_igst_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>
        
        
         {% 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("rounded_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            : HDFC Bank Ltd.
A/c No.                   :
Branch & IFS Code :
Customer's seal and Signature for {{ doc.company }}
                                                                                     Authorised Signatory

This is a Computer Generated Invoice

Please help on this. This same code is works if I have same tax for all products.