Untitled
unknown
python
a year ago
2.4 kB
1
Indexable
Never
# -*- coding: utf-8 -*- from odoo import tools from odoo import models, fields, api import base64 from io import BytesIO from pdf417 import encode, render_image, render_svg class ReportInvoiceHUB(models.AbstractModel): _name = 'report.hr_invoicing.report_invoice_hub' _description = 'HUB invoice report' @api.model def _get_report_values(self, docids, data=None): docids = docids or data.get('context').get('data').get('ids') lang = data and data['form'].get('lang', False) or 'en_US' docs = self.env['account.invoice'].browse(docids).with_context(lang=lang) return { 'doc_ids': docs.ids, 'doc_model': 'account.invoice', 'docs': docs, 'report_type': 'qweb-pdf', 'get_barcode_src': self._get_barcode_src, 'lang': lang, } def _get_barcode_src(self, invoice_id): invoice = self.env['account.invoice'].browse(invoice_id) barcode_text = invoice._create_barcode_text() image = render_image(encode(barcode_text, columns=9, security_level=4)) # Pillow Image object buffered = BytesIO() image.save(buffered, format="JPEG") img_str = base64.b64encode(buffered.getvalue()) return "data:image/jpeg;base64,{0}".format(img_str.decode()) class ReportInvoiceHUBura(models.AbstractModel): _name = 'report.hr_invoicing.report_invoice_hub_ura' _description = 'HUB invoice report - ura' @api.model def _get_report_values(self, docids, data=None): report = self.env['ir.actions.report']._get_report_from_name('hr_invoicing.report_invoice_hub_ura') return { 'doc_ids': docids, 'doc_model': report.model, 'docs': self.env[report.model].browse(docids), 'report_type': 'qweb-pdf', 'get_barcode_src': self._get_barcode_src, } def _get_barcode_src(self, invoice_id): invoice = self.env['account.invoice'].browse(invoice_id) barcode_text = invoice._create_barcode_text() image = render_image(encode(barcode_text, columns=9, security_level=4)) # Pillow Image object buffered = BytesIO() image.save(buffered, format="JPEG") img_str = base64.b64encode(buffered.getvalue()) return "data:image/jpeg;base64,{0}".format(img_str.decode())