Jinja format of Sales Order

  1. In the “standard” print settings, there is a Sales Order which has
    • a block for Items(Table)

I have found that Jinja print formats offer better formatting control - probably since I don’t really know what I’m doing - I just mangle things until they work OK.

I created a jinja template for the items(Table) which contains something approx like this… (I now it’s not pretty but it works OK for my needs…)

{# Get the tax/VAT rate for THIS.document #}
{% set this_docs_vat_rate = frappe.db.get_value("Sales Taxes and Charges", {"parent": doc.name}, "rate") %}

		{%- for row in doc.items -%}
			<td style="width: 3%;">{{ row.idx }}</td>
			<td class="sm">
				   {{ row.item_code }}<br>
				   <span class="xs">{% if row.item_code != row.item_name -%} {{ row.item_name}} {%- endif %}</span>
			<td class="rt xs" style="width: 10%;">{{ "%.2f"|format(row.rate) }}</td>
			<td class="rt xs" style="width: 10%;">{{ "%.2f"|format(row.rate * (this_docs_vat_rate/100)  )}}</td>
         {# <br><small>@{{ (this_docs_vat_rate) }}%</small> #}
			<td class="rt xs" style="width: 10%;">{{ "%.2f"|format(row.rate * (1+(this_docs_vat_rate/100)) ) }}</td>
			<td class="cn sm" style="width: 8%;">{{ row.qty }}</td>
			<td class="rt sm vb" style="width: 10%;">{{ "%.2f"|format(row.amount * (1) ) }}</td>
			<td class="rt sm vb" style="width: 10%;">{{ "%.2f"|format(row.amount * (1+ (this_docs_vat_rate/100)) ) }}</td>
		{%- endfor -%}
  1. In the standard prints, the Sales Order print format also has

    • a block for Pricing Rules Detail (Table)
      • Pricing Rule
      • Item Code
      • Margin Type
      • Rate or Discount
      • Rule Applied
  2. Can anyone assist with the equivalent jinja block

    • with relevant Pricing Rule outer block/loop & inner block field names
      • ie. doc.items → xxx.yyy
    • to create the same table using Jinja print format?
1 Like

Could you explain more or show an example? I don’t get what’s the catch here, just do it the same way you did the items table.

{% for rule in doc.pricing_rules %}
{% endfor %} 
1 Like

Share images of the results

If your site is in developer mode, pressing the alt key on your keyboard will bring out a tooltip of all field names, which you can use to write your jinja code.

You can also inspect the field and in the html code you will see a data-fieldname attribute for the field which has the field name.

1 Like

For the Items table I saw this,

and then tracked the field names to


so I could manage the “replacement” of the item block in jinja…

I could see this in the standard format

but I didn’t know what the field names were, or how to get them (I am not a programmer :crazy_face:)

Your rule.XXXX is what I needed to find. Thank you for the help!