Creating Custom print format - Part 2 -

Creating Custom print formats Part - 2. Add Serial numbers on invoice and Delivery notes

 · 2 min read


First part of this series is here - https://cloud.erpgulf.com/blog/blogs/print-formats

Video for this first part is here - https://youtu.be/Mn_YHcQz-6M


Macro conctpt - coloring example

------

{% macro color_qty(qty) %}

{% if qty > 100 %}

<p style="color:blue;"> {{qty}} </p>

{% else %}

<p style="color:red;"> {{qty}} </p>

{% endif %}

{% endmacro %}


Printing serial numbers on Delivery note or Sales Invoice .



Delivery Note

-------------

{% macro get_macro(item_code,serial_no) %}

       {% set serial = frappe.get_doc('Serial and Batch Bundle', serial_no)%}

        {% for serial_item in serial.entries %}

         <p style="color:blue;"> {{serial_item.serial_no}} </p>

        {% endfor %}

{% endmacro %}


---------------




<table class="table table-bordered table-condensed">

<tr>

  <td style="text-align:right">Item Subtotal with VAT<br></td>

  <td style="width: 10%;text-align:right">Tax Amount - </td>

  <td style="width: 10%;text-align:right">Tax Rate - </td>

  <td style="width: 15%;text-align:right">Taxable Amount<br> </td>

  <td style="width: 10%;text-align:right">Unit Price<br> </td>

  <td style="text-align:right">Qty<br></td>

  <!-- <td style="text-align:right"> </td> -->

  <td style="width: 50%;text-align:right">Item Model Number and Description <br> </td>

  <td style="text-align:right">S.NO<br> </td>

  </tr>

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

 <tr>

  <td style="text-align:right">{{frappe.format_value(row.amount + row.amount * 0.15)}}</td>

  <td style="text-align:right">{{frappe.format_value(row.amount * 0.15)}}</td>

  <td style="text-align:center">15%</td>

  <td style="text-align:right">{{frappe.format_value(row.amount)}}</td>

 <td style="text-align:right">{{frappe.format_value(row.rate)}}</td>

  <td style="text-align:center">{{row.qty | int}}</td>

  <td style="text-align:center">{{color_qty(row.rate)}}</td>

  <!-- <td style="text-align:right">{{row.delivery_date or ""}}</td> -->

  <td style="text-align:right;word-wrap: break-word;max-width:250px;">{{row.item_code}}<br>{{row.description}} 


{% if row.serial_and_batch_bundle %} <br> Serial NO {{get_macro(row.item_code,row.serial_and_batch_bundle)}} {% endif %}</td>

  <td style="text-align:center">{{loop.index}}</td>

 </tr>


 {%- endfor -%}

</table>



-----




Sales invoice - Direct ( With "update stock" checked )

-----------


{% macro get_macro(item_code,serial_no) %}


      {% set serial = frappe.get_doc('Serial and Batch Bundle', serial_no)%}


       {% for serial_item in serial.entries %}


        <p style="color:blue;"> {{serial_item.serial_no}} </p>


       {% endfor %}


{% endmacro %}






<table class="table table-bordered table-condensed">


<tr>


 <td style="text-align:right">Item Subtotal with VAT<br></td>


 <td style="width: 10%;text-align:right">Tax Amount - </td>


 <td style="width: 10%;text-align:right">Tax Rate - </td>


 <td style="width: 15%;text-align:right">Taxable Amount<br> </td>


 <td style="width: 10%;text-align:right">Unit Price<br> </td>


 <td style="text-align:right">Qty<br></td>


 <!-- <td style="text-align:right"> </td> -->


 <td style="width: 50%;text-align:right">Item Model Number and Description <br> </td>


 <td style="text-align:right">S.NO<br> </td>


 </tr>


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


<tr>


 <td style="text-align:right">{{frappe.format_value(row.amount + row.amount * 0.15)}}</td>


 <td style="text-align:right">{{frappe.format_value(row.amount * 0.15)}}</td>


 <td style="text-align:center">15%</td>


 <td style="text-align:right">{{frappe.format_value(row.amount)}}</td>


<td style="text-align:right">{{frappe.format_value(row.rate)}}</td>


 <td style="text-align:center">{{row.qty | int}}</td>



 <td style="text-align:right;word-wrap: break-word;max-width:250px;">{{row.item_code}}<br>{{row.description}}


{% if row.serial_and_batch_bundle %} <br> Serial NO {{get_macro(row.item_code,row.serial_and_batch_bundle)}} {% endif %}</td>


 <td style="text-align:center">{{loop.index}}</td>


</tr>



{%- endfor -%}


</table>





Sales invoice  ( With Delivery note , "update stock" unticked )

-----------



{% macro get_macro(item_code,delivery_note) %}

  {% set doc = frappe.get_doc('Delivery Note', delivery_note)%}

  {% for item in doc.items %}

    {% if item.item_code == item_code and item.serial_and_batch_bundle %}

      {{"Serial No."}}

      {% set serial_code = item.serial_and_batch_bundle %}

       {% set serial = frappe.get_doc('Serial and Batch Bundle', serial_code)%}

        {% for serial_item in serial.entries %}

          {{serial_item.serial_no}}

        {% endfor %}

    {% endif %}

  {% endfor %}

{% endmacro %}



<table class="table table-bordered table-condensed">

<tr>

  <td style="text-align:right">Item Subtotal with VAT<br></td>

  <td style="width: 10%;text-align:right">Tax Amount - </td>

  <td style="width: 10%;text-align:right">Tax Rate - </td>

  <td style="width: 15%;text-align:right">Taxable Amount<br> </td>

  <td style="width: 10%;text-align:right">Unit Price<br> </td>

  <td style="text-align:right">Qty<br></td>

  <!-- <td style="text-align:right"> </td> -->

  <td style="width: 50%;text-align:right">Item Model Number and Description <br> </td>

  <td style="text-align:right">S.NO<br> </td>

  </tr>

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

 <tr>

  <td style="text-align:right">{{frappe.format_value(row.amount + row.amount * 0.15)}}</td>

  <td style="text-align:right">{{frappe.format_value(row.amount * 0.15)}}</td>

  <td style="text-align:center">15%</td>

  <td style="text-align:right">{{frappe.format_value(row.amount)}}</td>

 <td style="text-align:right">{{frappe.format_value(row.rate)}}</td>

  <td style="text-align:center">{{row.qty | int}}</td>

  <td style="text-align:center">{{color_qty(row.rate)}}</td>

  <td style="text-align:right;word-wrap: break-word;max-width:250px;">{{row.item_code}}<br>{{row.description}} 

{% if row.delivery_note %} {{get_macro(row.item_code,row.delivery_note)}} {% endif %}</td>

  <td style="text-align:center">{{loop.index}}</td>

 </tr>


 {%- endfor -%}

</table>


Team ERPGulf

The team behind ERPGulf blogs here, expresses their thoughts, shares the experience, often show the frustrations. Contact us on support@ERPGulf.com

1 comment
sami May 13, 2024

Clear and useful explanation

Add Comment