td style=“vertical-align: top;font-size: smaller;”
{% set total_qty = 0 %}
{% for row in doc.items %}
{% set total_qty = total_qty + (row.qty or 0) %}
{% endfor %}
{{ total_qty }}
td
I want to show the total quantity in my print is this correct
If it works then it’s correct. Otherwise you can use namespaces.
Hi @amal_31845,
If the default transaction (Sales Order/Purchase Order/Invoice … ) then I think total_qty is already there.
{{ doc.get_formatted('total_qty') }}
If not a default transaction, then you can use it.
{{ doc.items | sum(attribute='qty') }}
Thank You!
In my print format i want add these into a table
This is my table
but in the sales invoice it is given as long text not table so how can i get each value
@NCP
You asked about a sales invoice item, and I provided the code, but I have no idea about the taxes table.
I haven’t try but try it.
{{ doc.get_formatted('other_charges_calculation') }}
Thank You!
but i need to print each hsn value below but i cant get it because it is Longtext
Try to parse it in Jinja using strip, split and replace. Since it’s a long text I think you start by getting every row. something like
{% set rows = other_charges_calculation.split('\n') %}
Then you can loop through your rows, look for any pattern that you can use as a delimiter.
Store data in namespaces to use them globally.
Hi,
If you want total of quantity then use {{doc.total_qty}}
{% if doc.irn %}
{% set e_invoice_log = frappe.db.get_value(“e-Invoice Log”, doc.irn, (“invoice_data”), as_dict=True) %}
{%- set invoice_data = _dict(json.loads(e_invoice_log.invoice_data)) -%}
{%
set transaction_details = {
“IRN”: invoice_data.Irn,
“Ack. No”: invoice_data.AckNo,
“Ack. Date”: frappe.utils.format_datetime(
invoice_data.AckDt, “dd/MM/yyyy hh:mm:ss”
),
}
%}
{% for key, value in transaction_details.items() %}
{% endfor %}
{% endif %}
{% if doc.irn %}
{% set e_invoice_log = frappe.db.get_value(“e-Invoice Log”, doc.irn, (“signed_qr_code”), as_dict=True) %}
<img src=data:image/png;base64,{{ get_qr_code(e_invoice_log.signed_qr_code, scale=2) }} style= “float: right; width: 175px;” >
{% endif %}
this is working
{% set rows = doc.other_charges_calculation.split(‘\n’) %}
{% if rows %}
<tbody>
{% for i in range(0, rows|length, 4) %}
<tr>
<td>{{ rows[i] }}</td>
<td>{{ rows[i + 1] }}</td>
<td>{{ rows[i + 2] }}</td>
<td>{{ rows[i + 3] }}</td>
</tr>
{% endfor %}
</tbody>
{% endif %}
</table>
From the image you shared (before you edited your post), it seems that the longtext field actually just holds an HTML table. You can simply split at the end of every table row and table cell. Consider skipping the header rows because it might be a little bit complex.
<table>
{% set rows = doc.other_charges_calculation.split('</tr>') %}
<tbody>
{% for row in rows %}
<!-- Skip header rows-->
{% if loop.index >1 %}
<tr>
{% set cells = row.split('</td>') %}
{% for cell in cells %}
<!-- Skip any blank cell-->
{% if cell.strip() %}
<td>{{ cell|striptags|safe }}</td>
{% endif %}
{% endfor %}
</tr>
{% endif %}
{% endfor %}
</tbody>
</table>