Print Format Issues Fetching Purchase Invoice Item table into another Doctype such as Payment Entry

Hi,

I am new to ERPNext and currently trying to create a custom Print format where the requirement is to bring the Purchase Invoice Item Information in a custom Print Format for Payment Entry.

In short, in Payment Entry we have the Item table consisting of Purchase Invoice Reference Name, now i need those invoices corresponding information such as Item, Accepted Qty, Rate, Amount.

For the current doctype I am the below snippet.

	<span style="top:9.1cm;left: 1.7cm;
		position: absolute;">
		{%- for item in doc.references -%}

			{{ item.reference_name }}<br>

	{%- endfor -%}
	</span>
			<span style="top:9.1cm;left: 16.0cm;
		position: absolute;">
		{%- for item in doc.references -%}

			{{ item.allocated_amount  }}<br>

	{%- endfor -%}
	</span>

Can anyone help to bring values from another doctype?

Best Regards,
Kartive.

@Kartive_lfc, Try this

<table class="table table-bordered table-condensed">
<thead>
<tr>
<th>Sr. No</th>
<th>Type</th>
<th>Name</th>
<th>Due Date</th>
<th>Item Name</th>
<th>Qty</th>
<th>Rate</th>
<th>Amount</th>
<th>Outstanding</th>
<th>Allocated</th>
</tr>
</thead>
{% for items in doc.references %}
	<tr>
		<td>{{ items.idx }} </td>
		<td>{{ items.reference_doctype }} </td>
		<td>{{ items.reference_name }} </td>
		<td>{{ items.due_date }} </td>
{%	set result=frappe.db.get_value("Purchase Invoice Item",filters={'parent':items.reference_name},fieldname=['rate','qty','amount','item_name'],as_dict=true) %}
		<td>{{ result.item_name }} </td>
		<td>{{ result.qty }} </td>
		<td>{{ result.rate }} </td>
		<td>{{ result.amount }} </td>
		<td>{{ items.outstanding_amount }} </td>
		<td>{{ items.allocated_amount }} </td>
	</tr>
{% endfor %}
</table> 

I hope this solves your problem.

3 Likes

Thanks @ROHAN_JAIN1, it helped a lot :smiley:

1 Like

Thankyou, it helps a lot.
But using this code, it is showing only 1 item instead of all items.
Please help me. How can I show all items?

You need
for docInvoice in doc.references
for item in docInvoice.items

2 Likes

Please tell me how to use it as I am getting jinja error after using this. I think that I am using in wrong way.

Here is my code:

{% for items in doc.references %}

{%	set result=frappe.db.get_value("Sales Invoice Item",filters={'parent':items.reference_name},fieldname=['rate','qty','amount','item_name'],as_dict=true) %}

Received a sum of ₹{{ items.allocated_amount }} ({{ frappe.utils.money_in_words(items.allocated_amount ) }}), from {{ doc.party_name }} {{ frappe.db.get_value("Address", doc.shipping_address_name, "address_line1") }}, {{ frappe.db.get_value("Address", doc.shipping_address_name, "city") }},  {{ frappe.db.get_value("Address", doc.shipping_address_name, "pincode") }}, {{ frappe.db.get_value("Address", doc.shipping_address_name, "state") }}, {{ frappe.db.get_value("Address", doc.shipping_address_name, "country") }} by cash on account of 
{% for item in docInvoice.items %}
{{ result.item_name }}.
{% endfor %}
{% endfor %}
<br>
<br>
<br>
<strong style="float: right;">Cashier</strong>

Thankyou

1 Like

Please elaborate more.
I will be very thankful to you.

in place of docInvoice.Items it should be doc.items only

Thanks
But problem is same. After doing changes which you said, item name is not printing.

{% for items in doc.references %}

{%	set result=frappe.db.get_value("Sales Invoice Item",filters={'parent':items.reference_name},fieldname=['rate','qty','amount','item_name'],as_dict=true) %}


<b>Received amount: </b> {{ frappe.db.get_value("Payment Entry", doc.payment_amounts_section, "paid_amount") }} from <b>{{ doc.party_name }} {{ frappe.db.get_value("Address", doc.shipping_address_name, "address_line1") }}, {{ frappe.db.get_value("Address", doc.shipping_address_name, "city") }},  {{ frappe.db.get_value("Address", doc.shipping_address_name, "pincode") }}, {{ frappe.db.get_value("Address", doc.shipping_address_name, "state") }}, {{ frappe.db.get_value("Address", doc.shipping_address_name, "country") }}</b> on account of 
{% for item in doc.items %}
{{ result.item_name }}.
{% endfor %}
{% endfor %}
<br>
<br>
<br>

EDIT - hope this will help.

 {% for items in doc.references %}
 {% for result in frappe.db.get_list("Sales Invoice Item",filters={'parent':items.reference_name},fields=['rate','qty','amount','item_name']) %}
<tr>
	<td>{{ items.idx }} </td>
	<td>{{ items.reference_doctype }} </td>
	<td>{{ items.reference_name }} </td>
	<td>{{ items.due_date }} </td>
	<td>{{ result.item_name }}</td>
	<td>{{ result.qty }} </td>
	<td>{{ result.rate }} </td>
	<td>{{ result.amount }} </td>
	<td>{{ items.outstanding_amount }} </td>
	<td>{{ items.allocated_amount }} </td>
</tr>
{% endfor %}
{% endfor %}

Thankyou very much.