Ir al contenido
Menú
Se marcó esta pregunta
1 Responder
2248 Vistas

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

Avatar
Descartar
Mejor respuesta

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
Publicaciones relacionadas Respuestas Vistas Actividad
0
nov 24
1578
2
jul 23
2223
0
jul 23
1649
0
abr 25
1299
0
dic 24
3104