Show batch number in offline POS invoice

I have a custom JS print format as below.

<style>
	.print-format table, .print-format tr, 
	.print-format td, .print-format div, .print-format p {
		font-family: Monospace;
		line-height: 200%;
		vertical-align: middle;
	}
	@media screen {
		.print-format {
			width: 4in;
			padding: 0.25in;
			min-height: 8in;
		}
	}
</style>

<p class="text-center">
	{{ company }}<br>

	{{  __("POS No : ") }} {{ offline_pos_name }}<br>
</p>
<p>
	<b>{{ __("Customer") }}:</b> {{ customer }}<br>
</p>

<p>
	<b>{{ __("Date") }}:</b> {{ dateutil.global_date_format(posting_date) }}<br>

</p>

<hr>
<table class="table table-condensed cart no-border">
	<thead>
		<tr>
			<th width="40%">{{ __("Item") }}</b></th>
			<th width="20%">{{ __("Batch No.") }}</b></th>
			<th width="20%" class="text-right">{{ __("Qty") }}</th>
			<th width="20%" class="text-right">{{ __("Amount") }}</th>
		</tr>
	</thead>
	<tbody>
		{% for item in items %}
		<tr>
			<td>
				{{ item.item_name }}
				
			</td>
			<td>
				{{ item.batch_no }}
			</td>
			<td class="text-right">{{ format_number(item.qty, null,precision("difference")) }}<br>@ {{ format_currency(item.rate, currency) }}</td>
			<td class="text-right">{{ format_currency(item.amount, currency) }}</td>

		</tr>
		{% endfor %}
	</tbody>
</table>
<table class="table table-condensed no-border">
	<tbody>
		<tr>

			<td class="text-right" style="width: 70%">

				{{ __("Net Total") }}
			</td>
			<td class="text-right">

				{{ format_currency(total, currency) }}
			</td>








		</tr>
		{% for row in taxes %}

		{% if not row.included_in_print_rate %}
		<tr>
			<td class="text-right" style="width: 70%">
				{{ row.description }}
			</td>
			<td class="text-right">

				{{ format_currency(row.tax_amount, currency) }}
			</td>
		</tr>
		{% endif %}
		{% endfor %}

		{% if discount_amount %}
		<tr>
			<td class="text-right" style="width: 75%">
				{{ __("Discount") }}
			</td>
			<td class="text-right">

				{{ format_currency(discount_amount, currency) }}
			</td>
		</tr>
		{% endif %}
		<tr>
			<td class="text-right" style="width: 75%">
				<b>{{ __("Grand Total") }}</b>
			</td>
			<td class="text-right">

				{{ format_currency(grand_total, currency) }}
			</td>
		</tr>

		<tr>
			<td class="text-right" style="width: 75%">

				<b>{{ __("Paid Amount") }}</b>
			</td>
			<td class="text-right">

				{{ format_currency(paid_amount, currency) }}
			</td>
		</tr>



	</tbody>
</table>


<hr>
<p>{{ terms }}</p>
<p class="text-center">{{ __("Thank you, please visit again.") }}</p>    

When I print, it does not show the batch number. I’ve output the ‘item’ object to the javascript console by editing the line for the batch_no as below

{{ console.log(item) }}

The console shows the following value for batch_no:
batch_no: undefined

How can I get the batch number to show on the offline POS invoice/receipt?

Use our customization and check. If it helps.

We have customized offline pos to show only batch which have stock available and show its expiry and stock count.

Using that u can show the batch number in print if needed

Link: GitHub - f-9t9it/pos_bahrain: POS enhancement for ERPNext

@fkardame, thank you for the link. Quick question how do I integrate this into my erpnext?

Install this app using
Bench get-app pos_bahrain link
Bench --site sitename install-app pos_bahrain

1 Like

I’m getting the error below when accessing the POS module

Traceback (most recent call last):
File "/home/rockers/frappe-bench/apps/frappe/frappe/app.py", line 61, in application
response = frappe.handler.handle()
File "/home/rockers/frappe-bench/apps/frappe/frappe/handler.py", line 21, in handle
data = execute_cmd(cmd)
File "/home/rockers/frappe-bench/apps/frappe/frappe/handler.py", line 56, in execute_cmd
return frappe.call(method, **frappe.form_dict)
File "/home/rockers/frappe-bench/apps/frappe/frappe/__init__.py", line 1026, in call
return fn(*args, **newargs)
File "/home/rockers/frappe-bench/apps/pos_bahrain/pos_bahrain/api/item.py", line 40, in get_more_pos_data
'exchange_rates': get_exchange_rates(),
File "/home/rockers/frappe-bench/apps/pos_bahrain/pos_bahrain/api/item.py", line 101, in get_exchange_rates
as_dict=1
File "/home/rockers/frappe-bench/apps/frappe/frappe/database.py", line 210, in sql
self._cursor.execute(query)
File "/home/rockers/frappe-bench/env/lib/python2.7/site-packages/pymysql/cursors.py", line 170, in execute
result = self._query(query)
File "/home/rockers/frappe-bench/env/lib/python2.7/site-packages/pymysql/cursors.py", line 328, in _query
conn.query(q)
File "/home/rockers/frappe-bench/env/lib/python2.7/site-packages/pymysql/connections.py", line 517, in query
self._affected_rows = self._read_query_result(unbuffered=unbuffered)
File "/home/rockers/frappe-bench/env/lib/python2.7/site-packages/pymysql/connections.py", line 732, in _read_query_result
result.read()
File "/home/rockers/frappe-bench/env/lib/python2.7/site-packages/pymysql/connections.py", line 1075, in read
first_packet = self.connection._read_packet()
File "/home/rockers/frappe-bench/env/lib/python2.7/site-packages/pymysql/connections.py", line 684, in _read_packet
packet.check_error()
File "/home/rockers/frappe-bench/env/lib/python2.7/site-packages/pymysql/protocol.py", line 220, in check_error
err.raise_mysql_exception(self._data)
File "/home/rockers/frappe-bench/env/lib/python2.7/site-packages/pymysql/err.py", line 109, in raise_mysql_exception
raise errorclass(errno, errval)
InternalError: (1054, u"Unknown column 'alt_currency' in 'field list'")

Which table should I add the column to?

Ideally, you don’t need to manually add any columns. It should have been created when you installed pos_bahrain. Although not required, you should probably run the command below to recreate any missing columns

bench --site sitename migrate

It doesn’t hurt to run this as well -

bench clear-cache
1 Like

I run a bench update and this has fixed the error. Now how do I show the batch number on the printed invoice/receipt?

Hi @fkardame. I’ve installed the app and everything is working fine now. How do I get the selected batch number/id onto the invoice/receipt? Do I use a JavaScript function? Which one?

This doesn’t print batch number on receipt. You would need to modify your print format accordingly.

Any pointers on how I can achieve this? My custom JS print format is in the first post.

{{ item.batch_no }}

This should print item batch number in print format

Unfortunately this doesn’t work. As mentioned at the start, the output of console.log(item) shows item.batch_no as being undefined.

Hi @fkardame. Please help me with this. I know the data {batch_no} is there somewhere in the browser, after one has selected it from the pop-up batch number select form but how do I get it onto the print format?

Hello,
We have tried few things to display batch number in print format from pos but it failed.

I think the last option for you is to use Online POS and use POS Invoice print format as Server Side Script.

Use {{ Item.batch_no }} inside the item statement. This will work.

Thank you for all your help. I’ve been pulling out my hair for a while now, almost bald now :grinning:. I’ve opened a feature request on the github page, hopefully the ERPNext team will have time to look at this and help.
https://github.com/frappe/erpnext/issues/16953