ERPNext.com Frappe Cloud Support Partners Foundation Frappe School

How can manage barcode for weighed items in POS?

dear all
i hope you are fine

i have a problem regarding to pos barcode reader

let me descrip my issue deeply

in normal case i set barcode in item master
and it works successfully in pos

but the problem is (there are items are weighted
by scale machin ) and scale machine printout label immediatly
contains barcode and weight together in one label
as the picture below

the first 7 degits express the barcode
and last 6 digits express the weight
what i need is
in scanning erpnext divides barcode automatically into
(item code - weight in quantity)

let me say what i did till now

i defined new field in (item master) this field is checkable
(is this scale item) - dependent
on this check i set the number of weight digits and sorting
(barcode digits - weight digit )

how can i customize that in pos??

3 Likes

Hi there,

i think the barcode is composed like this:

  • 1st digit: is 2 - fixed number for weighted items
  • from 2nd to 7th digit for item code (actually it’s a PLU of the weight scale)
  • from 8th to 12nd is the weight or the price value (in your case is the price)
  • the 13rd is the check digit.

It’s needed to customize the ERPNext core part in order to properly read the barcode

1 Like

Hi @m_mohammad,

You need to make changes in the pos.js file,

Add one more key “length”: 7 in the below code

1 Like

@rohit_w it’s needed to customize Item as well in order to add PLU code …otherwise it can’t be matched, other than that it’s needed to read the price

2 Likes

Based on my need i have customized this piece of code for barcode weighted items …
Needs improve like

  • Define and save one or more barcode weighted items starting code like (280)
  • So the code reads the setting and checks

Right now if your Barcode starts with 280 and your item code is 4 digits it will get the Kgs (5 digits) and figure if they have 4,3,2,1 zero … Hope this helps as it is working for me.

on top of POS declare you var pesokg;

Under get_items: function on the if (key)

	if (key) {
		console.log('continua procura')
		if (key.length == 13){ 
			//Codigo barras por KG; Weighted barcode 
			if (key.startsWith('280')){
				//Talho especifico ... for specific customer or barcode type TO BE REVIEWED
				// key.substr(3,4) Codigo do Produto Max 4 digitos; item max 4 digits
				return $.grep(this.item_data, function (item) {
					if (item.item_code == key.substr(3,4)) {
						// guarda os kg para depois; keeps kgs for later
						pesokg1 = key.substr(13-6,5)
						if (pesokg1.startsWith('0000')){
							pesokg='0.' + pesokg1.substr(4)

						}else if (pesokg1.startsWith('000')){
							pesokg='0.' + pesokg1.substr(3)
						}else if (pesokg1.startsWith('00')){
							pesokg='0.' + pesokg1.substr(2)
						}else if (pesokg1.startsWith('0')){
							pesokg=pesokg1.substr(1,1) +'.' + pesokg1.substr(2,pesokg1.length)

						}
						search_status = false;
						return true
					}
				})

			}
		}
1 Like

Hi @rohit_w. Is this a working solution as defined so far?

Hello @Helio_Jesus

Excuse me for the mention on you as well.

I can’t seem to get any of these solutions to work. My script behaves as if I have not made any of these changes. I’m not even seeing my console log.

I’m experimenting with a ERPNext v7.2 Virtual Machine.
Editing file: frappe@erpnext:~$ vi frappe-bench/apps/erpnext/erpnext/accounts/page/pos/pos.js
POS.js file coming up

Also. Have you made any new updates to the script?

Thanks in Advance,
Adam

quite an old version, could u move on latest?

1 Like

Do you think this will help resolve my issue? I have in V9.2 in production. And was planning on transfering the script after seeing that it works.

Hi,

I still have this customer on the same version 8 and is working… i have not updated the script yet.
I have updated my local to v10 and this is still working…
Dont forget that this needs to be on POS.js and on get_items: function

Also if is a local server you need to bench build before bench start so those changes are taken place…
In my case because i have many testing companies i usually before bench start i do bench --site XXX migrate and only after i start bench start.

glad to help if more required.

Ah thanks for your time @Helio_Jesus. I think Bench build is what I need to do. I’ll revert!

Great! Thanks @Helio_Jesus. It worked!!!

Kindly advise on how I can pass pesokg to qty within the cart so that its automatically added instead of manually punched in.

Thanks again.

@adam26d Glad to hear.

To add the result add the below changes:

  1. Add Before frappe.pages

var pesokg;
frappe.pages[‘pos’].on_page_load = function (wrapper) {

  1. ON add_to_cart: function after caught = true; replacing d.qty += 1; by below
    if (pesokg) {
    if (d.qty == undefined){
    d.qty = Number(pesokg);
    }else{
    d.qty += Number(pesokg);
    }
    pesokg =0;
    }else{
    d.qty += 1;
    //Sell only stock available
    if (d.qty > me.get_actual_qty(me.items[0])){
    d.qty -= 1;
    }
    }

  2. On add_new_item_to_grid: function after this.child.discount_percentage = 0.0; and replacing this.child.qty = 1; by below

     if (pesokg) {
     	if (this.child.qty == undefined){
     		this.child.qty = Number(pesokg);
     	}else{
     		this.child.qty += Number(pesokg);
     	}
     	pesokg =0;
     }else{
     	this.child.qty = 1;
     }
    

Hope you manage … any help just let me know.

2 Likes

Oh wow. Its working just great!

I really appreciate your assistance @Helio_Jesus.

Now I just need to add an extra line to support weights above 10 KG. I think I can do this with some ease.

Have a great day!

2 Likes

DONE

if(key){
     //console.log('continua procura 1');
     if (key.length == 13){
           //Codigo barras por KG; Weighted barcode 
           if (key.startsWith('200')){
                    //Talho especifico ... for specific customer or barcode type TO BE REVIEWED
                    // key.substr(3,4) Codigo do Produto Max 4 digitos; item max 4 digits
                    return $.grep(this.item_data, function (item) {

                    if (item.barcode == key.substr(0,7)) {
                               // guarda os kg para depois; keeps                              
                               pesokg1 = key.substr(7,6)
                               if (pesokg1.startsWith('0000')){
                                         pesokg='0.' + pesokg1.substr(4)

                                }else if (pesokg1.startsWith('000')){
                                         pesokg='0.' + pesokg1.substr(3)
                                }else if (pesokg1.startsWith('00')){
                                         pesokg='0.' + pesokg1.substr(2)
                                }else if (pesokg1.startsWith('0')){
                                         pesokg=pesokg1.substr(1,1) +'.' + pesokg1.substr(2,pesokg1.length)
                                }else if (!pesokg1.startsWith('0')){
                                         pesokg=pesokg1.substr(0,2) +'.' + pesokg1.substr(2,pesokg1.length)

                                }

                                            search_status = false;
                                            return true
                                    }
                            })

                    }
        }

                    return $.grep(this.item_data, function(item){
                            if(search_status){
                                    if(in_list(me.batch_no_data[item.item_code], me.search.$input.val())){

We need to standardise this feature guys.

2 Likes

Great I helped. You’re welcome.
:facepunch:

2 Likes

The solution works in V7 so far. My production is in V9.2, and its not bringing up any items. What am I missing?

Because no item is coming up. The barcode matching isnt working. And generally the search of the pos has been disturbed and wont even search items by name.

Hi adam26d

Is this the full code?

Where should I insert it?

Would appreciate it if you can give me a step by step guide on this, I have a supermarket and I want to use this for the meat products.

Regards

Hello @olamide_shodunke

Please follow all of Helio_Jesus’ steps. For the part going under if (key) {
use my code instead of his, I’ve made a minor enhancement. You’ll also need to adjust the item part and weight part of the barcode accordingly using the first key.substr().

The file to edit is ~/frappe-bench/apps/erpnext/erpnext/accounts/page/pos/pos.js so far this works only in offline mode. Still figuring out online mode only.

Hello @adam26d @Helio_Jesus

I am confused on where exactly to insert the code “for the part going under if (key) {…”

see my code as below and please correct my mistakes

if (key) {
//console.log(‘continua procura 1’);
if (key.length == 13){
//Codigo barras por KG; Weighted barcode
if (key.startsWith(‘200’)){
//Talho especifico … for specific customer or barcode type TO BE REVIEWED
// key.substr(3,4) Codigo do Produto Max 4 digitos; item max 4 digits
return $.grep(this.item_data, function (item) {

                if (item.barcode == key.substr(3,4)) {
                           // guarda os kg para depois; keeps                              
                           pesokg1 = key.substr(13-6,5)
                           if (pesokg1.startsWith('0000')){
                                     pesokg='0.' + pesokg1.substr(4)

                            }else if (pesokg1.startsWith('000')){
                                     pesokg='0.' + pesokg1.substr(3)
                            }else if (pesokg1.startsWith('00')){
                                     pesokg='0.' + pesokg1.substr(2)
                            }else if (pesokg1.startsWith('0')){
                                     pesokg=pesokg1.substr(1,1) +'.' + pesokg1.substr(2,pesokg1.length)
                            }else if (!pesokg1.startsWith('0')){
                                     pesokg=pesokg1.substr(0,2) +'.' + pesokg1.substr(2,pesokg1.length)

                            }
		return $.grep(this.items_list, function (item) {
			if (search_status) {
				if (in_list(me.batch_no_data[item.item_code], me.serach_item.$input.val())) {
					search_status = false;
					return me.item_batch_no[item.item_code] = me.serach_item.$input.val()
				} else if (me.serial_no_data[item.item_code]
					&& in_list(Object.keys(me.serial_no_data[item.item_code]), me.serach_item.$input.val())) {
					search_status = false;
					me.item_serial_no[item.item_code] = [me.serach_item.$input.val(), me.serial_no_data[item.item_code][me.serach_item.$input.val()]]
					return true
				} else if (item.barcode == me.serach_item.$input.val()) {
					search_status = false;
					return item.barcode == me.serach_item.$input.val();
				} else if (reg.test(item.item_code.toLowerCase()) || (item.description && reg.test(item.description.toLowerCase())) ||
					reg.test(item.item_name.toLowerCase()) || reg.test(item.item_group.toLowerCase())) {
					return true
				}
			}
		})
	} else {
		return this.items_list;
	}
},