Skip to Content
Menú
This question has been flagged
1 Respondre
2232 Vistes

when i make a scan to barcode is not equal to the barcode in the product 

Avatar
Descartar
Best Answer

Hi,

If your product's barcode is generated automatically, check to see that it is functioning properly.
Then check the barcode of the corresponding product while scanning the barcode.

Let's say there is a field for scanning the barcode when the product moves, in that case you can use the following code:

scan_barcode = fields.Char(
string="scan product",
help="scan barcode of product here")

@api.onchange('scan_barcode')
def onchange_scan_barcode(self):
"""checking barcode with the corresponding product"""
order_product = self.env['product.product'].search(
[('barcode', '=', self.scan_barcode)])
lst=[]
if order_product:
for rec in self.move_ids:
lst.append(rec.product_id.id)
for rec in self.move_ids:
if order_product.id in lst:
if order_product.id == rec.product_id.id:
po= self.env['purchase.order'].search([('name','=',self.origin)])
for product in po.order_line:
if product.product_id.id == rec.product_id.id:
rec.scanned_count += 1
rec.product_uom_qty += 1
rec.product_barcode=self.scan_barcode
self.scan_barcode = 0
break
else:
vals = {
'name': order_product.name,
'product_id': order_product.id,
'reference': rec.reference,
'product_uom_qty': 1,
'product_barcode':self.scan_barcode,
'product_uom': order_product.uom_id.id,
'picking_type_id': rec.picking_type_id.id,
'origin': rec.origin,
'scanned_count':1,
'location_id': rec.location_id,
'location_dest_id':rec.location_dest_id
}
self.write({
'move_ids': [(0, 0, vals),]
})
lst.append(order_product.id)
break
else:
raise ValidationError(_('Sorry there is no product with such barcode'))
self.scan_barcode = 0

Regards 

Avatar
Descartar
Related Posts Respostes Vistes Activitat
0
de nov. 24
1564
2
de jul. 23
2208
0
de jul. 23
1634
0
d’abr. 25
1281
0
de des. 24
3074