def _get_pdf417_code(self): for picking_id in self: res = [] if picking_id.pe_guide_number and picking_id.pe_is_eguide: res.append(picking_id.company_id.partner_id.doc_number) res.append('09') res.append(picking_id.pe_guide_number.split("-")[0] or '') res.append(picking_id.pe_guide_number.split("-")[1] or '') # res.append(str(picking_id.amount_tax)) # res.append(str(picking_id.amount_total)) res.append(str(picking_id.pe_date_issue)) res.append(picking_id.partner_id.doc_type or "-") res.append(picking_id.partner_id.doc_number or "-") res.append(picking_id.pe_digest or "") res.append(picking_id.pe_signature or "") res.append("") pdf417_string = '|'.join(res) data_bytes = compact_bytes(to_bytes(pdf417_string, 'utf-8')) code_words = encode_high(data_bytes, 10, 5) rows = list(chunks(code_words, 10)) codes = list(encode_rows(rows, 10, 5)) image = render_image(codes, scale=2, ratio=2, padding=7) tmpf = BytesIO() image.save(tmpf, 'png') # tmpf.seek(0) picking_id.sunat_pdf417_code = encodestring(tmpf.getvalue())
def _get_pdf417_code(self): for invoice_id in self: res = [] if invoice_id.name and invoice_id.journal_id.is_cpe: res.append(invoice_id.company_id.partner_id.doc_number) res.append(invoice_id.journal_id.pe_invoice_code or '') res.append(invoice_id.name.split("-")[0] or '') res.append(invoice_id.name.split("-")[1] or '') res.append(str(invoice_id.amount_tax)) res.append(str(invoice_id.amount_total)) res.append(str(invoice_id.invoice_date)) res.append(invoice_id.partner_id.doc_type or "-") res.append(invoice_id.partner_id.doc_number or "-") res.append(invoice_id.pe_digest or "") res.append(invoice_id.pe_signature or "") res.append("") pdf417_string = '|'.join(res) data_bytes = compact_bytes(to_bytes(pdf417_string, 'utf-8')) code_words = encode_high(data_bytes, 10, 5) rows = list(chunks(code_words, 10)) codes = list(encode_rows(rows, 10, 5)) image = render_image(codes, scale=2, ratio=2, padding=7) # tmpf = tempfile.TemporaryFile(mode="r+") tmpf = BytesIO() image.save(tmpf, 'png') # tmpf.seek(0) invoice_id.sunat_pdf417_code = encodestring(tmpf.getvalue())
def encode(data, columns=6, security_level=2, encoding=DEFAULT_ENCODING): if columns < 1 or columns > 30: raise ValueError("'columns' must be between 1 and 30. Given: %r" % columns) if security_level < 0 or security_level > 8: raise ValueError( "'security_level' must be between 1 and 8. Given: %r" % security_level) num_cols = columns # Nomenclature # Prepare input data_bytes = to_bytes(data, encoding) # Convert data to code words and split into rows code_words = encode_high(data_bytes, num_cols, security_level) rows = list(chunks(code_words, num_cols)) return list(encode_rows(rows, num_cols, security_level))
def compact_bytes(data): """Encodes data into code words using the Byte compaction mode.""" compacted_chunks = (_compact_chunk(chunk) for chunk in chunks(data, size=6)) return chain(*compacted_chunks)
def compact_text(data): """Encodes data into code words using the Text compaction mode.""" interim_codes = compact_text_interim(data) return (_compact_chunk(chunk) for chunk in chunks(interim_codes, 2))