Fetch Data From Other Doctype

Hi Developers !

I’m new here and need some help .

I currently develop on custom print format for Payment Entry. As far as I know, Payment Entry somehow is connected with Sales Invoice. So let say, in the Payment Entry, I would like to have the party/customer address which only can be retrieved from the Sales Invoice. How can I fetch the data ? Would you mind to explain on this?

Or any other possible way could be really helpful too !

Thank you in advance :grinning:

frappe.db.get_value(“[doctype]”, “[name]”, “fieldname”)
frappe.db.get_value(“Sales Invoice”,“invoice_number”,“address_display”)

Hi @Maheshwari_Bhavesh

I already try it but I got some error . It pop-up an error said “Encountered unknown tag ‘frappe’.”

Do you know why this happen? Should I setup anything before using that scripting ?

share your code here

<div id="container">
	{%- macro add_header(page_num, max_pages, doc, letter_head, no_letterhead) -%}
    {% if letter_head and not no_letterhead %}
    <div class="letter-head">{{ letter_head }}</div>
    {% endif %}
    
    {% if max_pages > 1 %}
    <p class="text-right">{{ _("Page #{0} of {1}").format(page_num, max_pages) }}</p>
    {% endif %}
{%- endmacro -%}
{{ add_header(0,1,doc,letter_head, no_letterhead) }}
<div id="container">

<table style="width:50%;float:left;">
<colgroup>
   <col style="width:20%;">
    <col style="width:30%;">
  </colgroup>
<tr>
<td>Received From:</td>
<td>{{ doc.party_name }},<br>
frappe.db.get_value(“Sales Invoice”,“invoice_number”,“address_display”)
</td>
</tr>
</table>

<table style="width:50%;float:right;">
<colgroup>
   <col style="width:5%;">
    <col style="width:30%;">
    <col style="width:15%;">
  </colgroup>
<tr>
<td></td>
<td style="font: bold 1.2em verdana, sans-serif;">Official Receipt No.</td>
<td style="font: bold 1.2em verdana, sans-serif;">: {{ doc.name}}</td>
</tr>
<tr>
<td></td>
<td>Date</td>
<td>: {{ doc.posting_date }}</td>
</tr>
<tr>
<td></td>
<td>Cheques No.</td>
<td>: {{ doc.reference_no }}</td>
</tr>
<tr>
<td></td>
<td>Received In</td>
<td>: {{ doc.mode_of_payment }}</td>
</tr>
<tr><td colspans="2"></td></tr>
</table>
</div>

@Maheshwari_Bhavesh, Is it if I want to use “frappe” scripting, I must install it first ? Because at this moment, I don’t even have frappe in my computer. Or should I put anything before that scripting in order to open the database ?

You’ll have to put the frappe.db.get_value() inside curly braces as well:

{{ frappe.db.get_value("Sales Invoice", doc.sales_invoice, "address_display") }}
where doc.sales_invoice should be the field that links to the Sales Invoice.

2 Likes

thanks, @rmeyer I have been looking for this for couple of days,

1 Like

@Maheshwari_Bhavesh Is it possible to fetch the sales invoice Item Information?

If so, can you please provide the steps?

Best Regards,
Kartive

@Kartive_lfc
Use below code:

{% set items = doc.items %}
//iterate items
{%- for row in items -%}
{{ row.item_code }}// it will prints your item codes.
{%- endfor -%}

1 Like