Issue with Customized Print Format


Not sure if I’m at the right place. Here is the issue I’m having with printing quotation:

After creating several quotations (some draft, somme submitted {open}), if I try to print one of the quotations, the document will fetch data from the last created quotation, instead of the items from the selected quotation.

Here is the code I use to make the quotation adapted to the client:

{% set row = frappe.get_doc("Quotation Item", doc.quotation_item) %}
{% set u = frappe.get_doc("Quotation", doc.quotation) %}
<table class="table table-sm">
      <th scope="col" width="5%">#</th>
      <th scope="col" width="60%">{{ _("Code") }} / {{ _("Name") }}</th>
      <th scope="col" width="10%" class="text-right">{{ _("Quantity") }}</th>
      <th scope="col width="10%"" class="text-right">{{ _("Amount") }} ({{ doc.currency }})</th>
  {%- for row in u.items -%}
      <td>{{ row.idx }}</th>
      <td><small class="font-italic">{{ row.item_code }}</small></br>{{ row.description }}</td>
      <td class="text-right">{{ "{:,.0f}".format(row.qty) }} {{ row.stock_uom or "" }} </td>
      <td class="text-right">{{ "{:,.2f}".format(row.net_amount) or "" }} </td>
  {%- endfor -%}

Can anyone tell me what I’m doing wrong? Did I miss something? Or am I completely crazy? (please note that I’m not very familiar with programming language. I basically checked some of the guides and feedbacks in the forums to come up with the format above)

Any input is much appreciated.

Best regards,

There’s no need to do a get_doc if you’re printing a quotation table in a quotation print format , ie. the same doc. get_doc is useful when fetching from a different document.

Just run a loop for the table directly like:

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

Try removing the first two lines using get_doc from the code and then check the print format if it’s fetching the right values.

1 Like

Awesome! Worked like a charm! Thank you for the help!