Odoo Barcode Generate Code
Sample Code for Barcode
@api.multi
def _create_stock_serial(self, quantity):
serial_obj = self.env['stock.serial']
action_report_obj = self.env['ir.actions.report']
attachment_obj = self.env['ir.attachment']
for lot in self:
for i in range(int(quantity)):
vals = {
'quantity': 1,
'lot_id':lot.id,
}
serial_id = serial_obj.create(vals)
barcode = action_report_obj.barcode(
'QR',
value=serial_id.name,
width=200,
height=200,
humanreadable=False
)
attachment_vals = {
'res_name': serial_id.name,
'res_model': 'stock.serial',
'res_id': serial_id.id,
'datas': base64.encodestring(barcode),
'type': 'binary',
'datas_fname': serial_id.name+'.png',
'name': serial_id.name,
}
attachment_id = attachment_obj.create(attachment_vals)
serial_id.attachment_id = attachment_id