Jinja templating error

Hi,

im really confused about this code
{% set dn = “” %}
{% set delimiter = " , " %}
{% for group in doc.items|groupby(‘delivery_note’) %}
{% if dn == “” and group.grouper!=“None” %}
{% set dn = group.grouper %}
{% else %}
{% set dn = dn | delimiter | group.grouper %}
{% endif %}
{% endfor %}
{% if not dn == “” %}
FromDN : {{dn}}
{% endif %}

i just want to add DN information in Sales Invoice print format, but its giving me error there is no filter group… but group is defined already… and grouper is default things for that fuction in jinja docs

please advise…

thanks

This error I guess, i caused due to scope resolution implications in Jinja.Do check the documentation

which documentation do you refer to ?

http://jinja.pocoo.org/docs/dev/templates/#block-nesting-and-scope

@bobzz_zone Which information you want to print in Sales Invoice?

@kolate_sambhaji i want to set information which delivery note is included in the invoice… but i wont show it at the items table… i want summarize it

@bobzz_zone
We have delivery note number in Sales Invoice Item.
From this Delivery Note Number you can fetch delivery note information in Sales Invoice Print Format.

Sample code to print shipping address and delivery date:

{%- for row in doc.items|slice(1) -%}
{% set dn = frappe.get_doc("Delivery Note", row[0].delivery_note) %}
    Shipping Address: {{ dn.shipping_address or '' }}<br>
    Delivery Date: {{ dn.posting_date or '' }}
{%- endfor -%}

What i mean is i want to print the DN number its like :

Items From : DN-0001 , DN-0010


something like that…

can you share your code for same?

You can find delivery note number in Sales Invoice Item.

{%- for row in doc.items -%}
    DN Number: {{ row.delivery_note or '' }} <br>
{%- endfor -%}

see my first post… it was my code right now, and its error

the problem in you codes is , it will show duplicate delivery note

the things is i want to group the delivery note

thanks

@bobzz_zone

FromDN 
{% for group in doc.items|groupby('delivery_note') %}
{{ group.grouper or ''}},
{%- endfor -%}

above code will print, also it will remove None

 FromDN DN-00002,DN-00003,DN-00004,  

Let me know if you need any change in this?

1 Like

Hi, its works … thanks… but can you exmplain to me why my code is didnt works ?..

Thanks

1 Like

@bobzz_zone, Can you share the full template code then? I want to see how it work…

Tks

sure here my code

<div class="page-break">

<div class="row">

    <div class="col-xs-6">
         <div>
            <div class="row" style="font-size:17px;">
                <div class="col-xs-5 text-right">
                    <strong>No.</strong>
                </div>
                <div class="col-xs-7" ><strong>{{doc.name}}</strong>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-xs-5 text-right">
                <label>Customer Name</label>
            </div>
            <div class="col-xs-7 ">
        {{doc.customer_name}}
            </div>
        </div>

       

    </div>

    <div class="col-xs-6">

        

        <div class="row">
            <div class="col-xs-5 text-right">

                <label>Issued Date</label>

            </div>
            <div class="col-xs-7 ">
        {{doc.get_formatted("posting_date")}}
            </div>
        </div>
        <div class="row">
            <div class="col-xs-5 text-right">

                <label>Due Date</label>

            </div>
            <div class="col-xs-7 ">
        {{doc.get_formatted("due_date")}}
            </div>
        </div>
    </div>

</div>
{% set dn = "" %}
{% set delimiter = " , " %}

{% for group in doc.items|groupby('delivery_note') %}
{% if dn == "" %}
{% set dn = group.grouper or '' %}
{% else %}
{% set dn = dn | delimiter | group.grouper %}
{% endif %}
{%- endfor -%}
{% if dn != "" %}
<div class="row">
<div class="col-xs-12">
Surat Jalan :{{dn}}
</div>
</div>
{% endif %}
<div class="row">
<style>#list-item td {padding:1px!important;}</style>
<div class="col-xs-12">
<table class="table table-bordered" id="list-item">
    <thead>
        <tr>
            <th>No.</th>
            <th>Item</th>
            <th>Qty</th>
            <th>Harga</th>
            <th>Total</th>
<th>Surat Jalan</th>
        </tr>
    </thead>
<tbody>
    {% for row in doc.items -%}
    
        <tr>
            <td style="width: 3%;">{{ row.idx }}</td>
            <td style="width: 42%;">
                {{ row.item_code }} - {{row.item_name}}
            </td>
            <td style="width: 10%;">{{ "%d"|format(row.qty) }} {{row.stock_uom}}</td>
            <td style="width: 15%;">{{row.get_formatted("rate",doc)}}</td>
            <td style="width: 15%;">{{row.get_formatted("amount",doc)}}</td>
<td style="width: 15%;">{{row.delivery_note}}</td>
        </tr>
    
    {%- endfor %}
</tbody>
</table>
</div>
</div>
<div class="row">
<div class="col-xs-9 text-right">
{% if "%d"|format(doc.base_discount_amount)==0 %}
<strong>Net Total</strong><br/>
<strong>Discount</strong><br/>
<strong>Total</strong>
{% else %}
<strong>Total</strong>
{% endif %}
</div>
<div class="col-xs-3">
{% if "%d"|format(doc.base_discount_amount)==0 %}
{{doc.get_formatted("total")}}<br/>
{{doc.get_formatted("base_discount_amount")}}<br/>
{{doc.get_formatted("grand_total")}}
{% else %}
{{doc.get_formatted("total")}}
{% endif %}
</div>
</div>