mirror of
https://github.com/bringout/oca-ocb-accounting.git
synced 2026-04-23 17:02:07 +02:00
19.0 vanilla
This commit is contained in:
parent
ba20ce7443
commit
768b70e05e
2357 changed files with 1057103 additions and 712486 deletions
|
|
@ -1,14 +1,14 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
import base64
|
||||
import io
|
||||
|
||||
from PyPDF2 import PdfFileReader, PdfFileWriter
|
||||
import re
|
||||
|
||||
from odoo.addons.account.tests.common import AccountTestInvoicingCommon
|
||||
from odoo.exceptions import RedirectWarning
|
||||
from odoo.tools import pdf
|
||||
from odoo.tests import tagged
|
||||
from odoo.tools import file_open
|
||||
from odoo.tools import file_open, mute_logger
|
||||
from odoo.tools.pdf import PdfFileReader, PdfFileWriter
|
||||
|
||||
|
||||
@tagged('post_install', '-at_install')
|
||||
|
|
@ -44,6 +44,8 @@ class TestIrActionsReport(AccountTestInvoicingCommon):
|
|||
test_record_report = self.env['ir.actions.report'].with_context(force_report_rendering=True)._render_qweb_pdf('account.action_account_original_vendor_bill', res_ids=in_invoice_1.id)
|
||||
self.assertTrue(test_record_report, "The PDF should have been generated")
|
||||
|
||||
# Document synchronization being enabled, avoid a warning when computing the number of page of the corrupted pdf.
|
||||
@mute_logger('odoo.addons.documents.models.documents_document')
|
||||
def test_download_with_encrypted_pdf(self):
|
||||
"""
|
||||
Same as test_download_one_corrupted_pdf
|
||||
|
|
@ -57,17 +59,20 @@ class TestIrActionsReport(AccountTestInvoicingCommon):
|
|||
for page_num in range(pdf_reader.getNumPages()):
|
||||
pdf_writer.addPage(pdf_reader.getPage(page_num))
|
||||
# Encrypt the PDF
|
||||
pdf_writer.encrypt('', use_128bit=True)
|
||||
pdf_writer.encrypt('')
|
||||
# Get the binary
|
||||
output_buffer = io.BytesIO()
|
||||
pdf_writer.write(output_buffer)
|
||||
encrypted_file = output_buffer.getvalue()
|
||||
|
||||
# we need to change the encryption value from 4 to 5 to simulate an encryption not used by PyPDF2
|
||||
encrypt_start = encrypted_file.find(b'/Encrypt')
|
||||
encrypt_end = encrypted_file.find(b'>>', encrypt_start)
|
||||
encrypt_version = encrypted_file[encrypt_start: encrypt_end]
|
||||
encrypted_file = encrypted_file.replace(encrypt_version, encrypt_version.replace(b'4', b'5'))
|
||||
# corrupt encryption: point the /Encrypt xref as a non-encrypt
|
||||
# (but valid otherwise pypdf skips it)
|
||||
encrypted_file, n = re.subn(
|
||||
b'/Encrypt (?P<index>\\d+) (?P<gen>\\d+) R',
|
||||
b'/Encrypt 1 \\g<gen> R',
|
||||
encrypted_file,
|
||||
)
|
||||
self.assertEqual(n, 1, "should have updated the /Encrypt entry")
|
||||
|
||||
in_invoice_1 = self.env['account.move'].create({
|
||||
'move_type': 'in_invoice',
|
||||
|
|
@ -76,7 +81,7 @@ class TestIrActionsReport(AccountTestInvoicingCommon):
|
|||
})
|
||||
|
||||
in_invoice_1.message_main_attachment_id = self.env['ir.attachment'].create({
|
||||
'datas': base64.b64encode(encrypted_file),
|
||||
'raw': encrypted_file,
|
||||
'name': attach_name,
|
||||
'mimetype': 'application/pdf',
|
||||
'res_model': 'account.move',
|
||||
|
|
@ -88,7 +93,7 @@ class TestIrActionsReport(AccountTestInvoicingCommon):
|
|||
in_invoice_2 = in_invoice_1.copy()
|
||||
|
||||
in_invoice_2.message_main_attachment_id = self.env['ir.attachment'].create({
|
||||
'datas': base64.b64encode(self.file),
|
||||
'raw': self.file,
|
||||
'name': attach_name,
|
||||
'mimetype': 'application/pdf',
|
||||
'res_model': 'account.move',
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue