Displaying inventory item's custom field in sales invoice

In our sales invoice, we want to display both “Unit Price” and “MRP”. Unit price is our discounted price.
For that, we have added a custom field called “MRP” in the “Inventory item” fields.

How do we display the MRP field using the “Sales Invoice Template”? Which variable name
should I refer to display the custom “MRP” field in the sales invoice?

Can you please help?


{{ line.item.custom_fields["MRP"] }}


{{ line.item.custom_fields.MRP }}

That worked fine! Thanks @lubos !!

Now, I am having problem to calculate total savings as there seem to be some issue with text to decimal conversion.

In the default sales invoice template, I have added the following code.

                {% assign savings=0 %}
                {% for line in lines %}
                {% assign item_mrp = line.item.custom_fields.MRP | plus: 0 %}
                {% assign item_saving = item_mrp | minus: line.unit_price | times: line.qty %}
                {% assign savings = savings | plus: item_saving %}

The ‘item_mrp’ has the right value. However, following error message
is thrown at {% assign item_saving = item_mrp | minus: line.unit_price | times: line.qty %}

“Liquid error: Parameter count mismatch”

I am new to Liquid. Am I missing something in the above code?
Why any arithmetic expression using ‘item_mrp’ after its first assignment fails? Please help to resolve this.

The reason is that MRP is a text field.

I can see you are already using the filter plus: 0 to convert text into decimal. That’s clever. However this might not be available in Manager implementation.

I might add support for it today. I’ll keep you posted.

OK, I’ve added filter called to_number to the latest version (16.1.84). It’s a bit non-standard but was easiest to implement.

So, instead…

{% assign item_mrp = line.item.custom_fields.MRP | plus: 0 %}

do this:

{% assign item_mrp = line.item.custom_fields.MRP | to_number %}

Wow, that’s great! Thank you @lubos for your prompt response and support!