mirror of
https://github.com/bringout/oca-ocb-accounting.git
synced 2026-04-23 12:22: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,17 +1,8 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from collections import OrderedDict
|
||||
from zlib import error as zlib_error
|
||||
try:
|
||||
from PyPDF2.errors import PdfReadError
|
||||
except ImportError:
|
||||
from PyPDF2.utils import PdfReadError
|
||||
|
||||
try:
|
||||
from PyPDF2.errors import DependencyError
|
||||
except ImportError:
|
||||
DependencyError = NotImplementedError
|
||||
|
||||
from odoo import api, models, _
|
||||
from odoo import api, fields, models, _
|
||||
from odoo.exceptions import UserError
|
||||
from odoo.tools import pdf
|
||||
|
||||
|
|
@ -19,6 +10,11 @@ from odoo.tools import pdf
|
|||
class IrActionsReport(models.Model):
|
||||
_inherit = 'ir.actions.report'
|
||||
|
||||
is_invoice_report = fields.Boolean(
|
||||
string="Invoice report",
|
||||
copy=True,
|
||||
)
|
||||
|
||||
def _render_qweb_pdf_prepare_streams(self, report_ref, data, res_ids=None):
|
||||
# Custom behavior for 'account.report_original_vendor_bill'.
|
||||
if self._get_report(report_ref).report_name != 'account.report_original_vendor_bill':
|
||||
|
|
@ -31,14 +27,14 @@ class IrActionsReport(models.Model):
|
|||
|
||||
collected_streams = OrderedDict()
|
||||
for invoice in invoices:
|
||||
attachment = invoice.message_main_attachment_id
|
||||
attachment = self._prepare_local_attachments(invoice.message_main_attachment_id)
|
||||
if attachment:
|
||||
stream = pdf.to_pdf_stream(attachment)
|
||||
if stream:
|
||||
record = self.env[attachment.res_model].browse(attachment.res_id)
|
||||
try:
|
||||
stream = pdf.add_banner(stream, record.name, logo=True)
|
||||
except (ValueError, PdfReadError, TypeError, zlib_error, NotImplementedError, DependencyError, ArithmeticError):
|
||||
stream = pdf.add_banner(stream, record.name or '', logo=True)
|
||||
except (ValueError, pdf.PdfReadError, TypeError, zlib_error, NotImplementedError, pdf.DependencyError, ArithmeticError):
|
||||
record._message_log(body=_(
|
||||
"There was an error when trying to add the banner to the original PDF.\n"
|
||||
"Please make sure the source file is valid."
|
||||
|
|
@ -50,9 +46,21 @@ class IrActionsReport(models.Model):
|
|||
return collected_streams
|
||||
|
||||
def _is_invoice_report(self, report_ref):
|
||||
return self._get_report(report_ref).report_name in ('account.report_invoice_with_payments', 'account.report_invoice')
|
||||
report = self._get_report(report_ref)
|
||||
return (report.is_invoice_report and report.model == 'account.move') or report.report_name == 'account.report_invoice'
|
||||
|
||||
def _render_qweb_pdf(self, report_ref, res_ids=None, data=None):
|
||||
def _get_splitted_report(self, report_ref, content, report_type):
|
||||
if report_type == 'html':
|
||||
report = self._get_report(report_ref)
|
||||
bodies, res_ids, *_unused = self._prepare_html(content, report_model=report.model)
|
||||
return {res_id: str(body).encode() for res_id, body in zip(res_ids, bodies)}
|
||||
elif report_type == 'pdf':
|
||||
pdf_dict = {res_id: stream['stream'].getvalue() for res_id, stream in content.items()}
|
||||
for stream in content.values():
|
||||
stream['stream'].close()
|
||||
return pdf_dict
|
||||
|
||||
def _pre_render_qweb_pdf(self, report_ref, res_ids=None, data=None):
|
||||
# Check for reports only available for invoices.
|
||||
# + append context data with the display_name_in_footer parameter
|
||||
if self._is_invoice_report(report_ref):
|
||||
|
|
@ -63,7 +71,7 @@ class IrActionsReport(models.Model):
|
|||
if any(x.move_type == 'entry' for x in invoices):
|
||||
raise UserError(_("Only invoices could be printed."))
|
||||
|
||||
return super()._render_qweb_pdf(report_ref, res_ids=res_ids, data=data)
|
||||
return super()._pre_render_qweb_pdf(report_ref, res_ids=res_ids, data=data)
|
||||
|
||||
@api.ondelete(at_uninstall=False)
|
||||
def _unlink_except_master_tags(self):
|
||||
|
|
@ -80,3 +88,9 @@ class IrActionsReport(models.Model):
|
|||
master_report = self.env.ref(f"account.{master_xmlid}", raise_if_not_found=False)
|
||||
if master_report and master_report in self:
|
||||
raise UserError(_("You cannot delete this report (%s), it is used by the accounting PDF generation engine.", master_report.name))
|
||||
|
||||
def _get_rendering_context(self, report, docids, data):
|
||||
data = super()._get_rendering_context(report, docids, data)
|
||||
if self.env.context.get('proforma_invoice'):
|
||||
data['proforma'] = True
|
||||
return data
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue