Helloo Community!!
Does anyone know how to iterate over the entire doctype ??
Helloo Community!!
Does anyone know how to iterate over the entire doctype ??
Explore what you want, then if someone knows, they will answer you.
{% set parent1 = none %}
{% set parent2 = none %}
{% set documents = frappe.get_all('Purchase Receipt Item', filters={}, fields=['name', 'docstatus', 'item_code', 'received_qty', 'qty', 'purchase_order', 'purchase_order_item', 'parent'], order_by="parent DESC") %}
{% set order_counts = {} %}
{% for pri in documents %}
{% set purchase_order = pri.purchase_order %}
{% set parent = pri.parent %}
{% if purchase_order not in order_counts %}
{% set _ = order_counts.update({purchase_order: []}) %}
{% endif %}
{% if parent not in order_counts[purchase_order] %}
{% set _ = order_counts[purchase_order].append(parent) %}
{% endif %}
{% endfor %}
<h2>Count of Unique Parents per Purchase Order:</h2>
<ul>
{% for order, parents in order_counts.items() %}
<li>
{{ order }}: {{ parents|length }}
{% if parents|length == 2 %}
<ul>
{% set sorted_parents = parents|sort %}
{% set parent1 = sorted_parents[0] %}
{% set parent2 = sorted_parents[1] %}
<li>First Parent: {{ parent1 }}</li>
<li>Second Parent: {{ parent2 }}</li>
</ul>
{% endif %}
</li>
{% endfor %}
</ul>
<p>parent1: {{ parent1 }}</p>
<p>parent2: {{ parent2 }}</p>
This is my code. I need to update the parent1 and parent2 values inside the loop and i need them outside the loop…
But iam getting parent1 and parent2 values in inside the loop, but outside the loop iam getting none. That means values are not updated correctly.
I need some help to update the values correctly…
i have been the same issue so i solve it by add custom field and hidden it then via client script i did the calculate then in the print just received the value
@manal_erpnext ,We can do like that but in my case, after printing that value i need to set that value to “0” again.
okey you can reset it after event print in js or set 0 when the doc refresh
frappe.ui.form.on('Doctype Name', {
refresh(frm) {
frm.set_value('Custom Field Name',0);
frm.refresh_field('Custom Field Name');
}
})