Tuesday, July 23, 2019

how to add barcodes to reports in odoo


ODOO

reports

barcodes

 

 

we can generate two types of barcodes in odoo as the image show , so let us show how we can add any one to our reports

we will start with code (1) and we can add it by following steps
  • add the barcode field in our python file as bellow
barcode = fields.Char('Barcode', size=20)
  • add sql constraints to make barcode unique for each report
 _sql_constraints = [
        ('unique_name_barcode',
         'unique(barcode)',
         'Barcode must be unique per Report!'),
    ]
  • add create function which will create the barcode automatically when we create report 
@api.model
    def create(self,vals):
        """
        Method to create sequence for report barcode
        """
        vals['barcode'] = self.env['ir.sequence'].get('student.student')
        return super(student_student, self).create(vals) 
// student.student is the model which is contain the barcode field 
// student_student the of the class that is contain the barcode field
// this function will create the sequence with the barcode 
  • add the barcode to our report as bellow 
<img t-att-src="'data:image/png;base64,%s'% (get_barcode('Code128',doc.barcode))"/>

Now we  will code the barcode (2) by following the same steps but in our report template we must show the barcode as bellow 

<img t-att-src="'/report/barcode/?type=%s&amp;value=%s&amp;width=%s&amp;height=%s' % ('QR', doc.barcode, 50, 50)" style="width:150px;height:150px;"/>

No comments:

Post a Comment

Odoo Invoice Qr code issues

There are two main issues must of us facing with the QR code in Odoo invoice & these issues are 1/ QR code displayed as broken image w...