Hello. I want to be able to pull the uom conversion factor of an item for another UOM , from within the print format of the Delivery Note, specifically in the item table. I understand that following code:
{{frappe.db.get_value("UOM Conversion Detail", {"uom": i.uom}, "conversion_factor")}}
will fetch the conversion factor of the uom currently used in the delivery note. How do I get the uom factor for a different uom (already set up in the item master)?
For example:
Item has two UOMs:
- meters - default
- rolls - conversion 0.1 (or 10 meters to 1 roll)
Delivery notes will use meters by default. But in the same document record, I would like to be able to show the rolls equivalent in the print format (and print format only). Any help appreciated. Thanks.
{% for i in doc.items %}
{% set item = frappe.get_doc("Item", i.item_code) %}
{% for u in item.uoms %}
{{frappe.db.get_value("UOM Conversion Detail", {"uom":u.uom}, "conversion_factor")}}
{% endfor %}
{% endfor %}
1 Like
Many thanks @Khadija that works!
1 Like
Just to try to add and contribute, I only wanted to get a certain type of UOM reflected in my custom print, hence the final snippet I’m using is:
{% for i in doc.items %}
{% for u in item.uoms %}
{%-if frappe.db.get_value("UOM Conversion Detail", {"uom":u.uom}, "uom") == "Roll"-%}
<b><u>(
{{(i.qty / frappe.db.get_value("UOM Conversion Detail", {"uom":u.uom}, "conversion_factor"))|round(2)}} {{ frappe.db.get_value("UOM Conversion Detail", {"uom":u.uom},"uom")}}
)</u></b>
{%- endif %}
{%-if frappe.db.get_value("UOM Conversion Detail", {"uom":u.uom}, "uom") == "Bag"-%}
<b><u>(
{{(i.qty / frappe.db.get_value("UOM Conversion Detail", {"uom":u.uom}, "conversion_factor"))|round(2)}} {{ frappe.db.get_value("UOM Conversion Detail", {"uom":u.uom},"uom")}}
)</u></b>
{%- endif %}
{% endfor %}
{% endfor %}
So I’m encountering some problems with this code. Apparently, you need to use the uoms
table name to match the same unique name from the uoms child table. Corrected code:
{%- for i in doc.items -%}
{%- set item = frappe.get_doc("Item", i.item_code) -%}
{% for u in item.uoms %}
{%-if frappe.db.get_value("UOM Conversion Detail", {"uom":u.uom}, "uom") == "Roll"-%}
(
{{frappe.db.get_value("UOM Conversion Detail", {"name":u.name}, "conversion_factor")}}
)
{%-elif frappe.db.get_value("UOM Conversion Detail", {"uom":u.uom}, "uom") == "Bag"-%}
(
{{frappe.db.get_value("UOM Conversion Detail", {"name":u.name}, "conversion_factor")}}
)
{%- endif %}
{% endfor %}
{%- endfor -%}