-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP][14.0][IMP] account_invoice_batches: report intermediary service #426
base: 14.0
Are you sure you want to change the base?
[WIP][14.0][IMP] account_invoice_batches: report intermediary service #426
Conversation
@@ -14,6 +14,7 @@ | |||
"l10n_es_facturae", | |||
"account_invoice_report_service", | |||
"sale_order_invoicing_grouping_criteria", | |||
"account_move_service", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We cannot make this dependent, we have to allow having batches without move service.
report_service = self.company_id.report_service_id | ||
if invoices_pdf.filtered(lambda x: x.partner_id.service_intermediary): | ||
if not self.company_id.report_intermediary_service_id: | ||
raise UserError( | ||
_( | ||
"The report for service intermediary partners is not " | ||
"defined in the configuration settings. Please go to " | ||
"the billing configuration and specify which report " | ||
"will be used." | ||
) | ||
) | ||
report_intermediary = self.company_id.report_intermediary_service_id | ||
pdf_streams = [] | ||
for invoice in invoices_pdf: | ||
if invoice.partner_id.service_intermediary: | ||
if not report_intermediary: | ||
raise UserError( | ||
_( | ||
"The report for service intermediary partners is not " | ||
"defined in the configuration settings. Please go to " | ||
"the billing configuration and specify which report " | ||
"will be used." | ||
) | ||
) | ||
report = report_intermediary | ||
else: | ||
report = report_service | ||
|
||
pdf_content, _p = report._render_qweb_pdf([invoice.id]) | ||
pdf_stream = io.BytesIO(pdf_content) | ||
pdf_streams.append(pdf_stream) | ||
|
||
if pdf_streams: | ||
merged_pdf_stream = io.BytesIO() | ||
pdf_merger = PdfFileReader(pdf_content) | ||
for pdf_stream in pdf_streams: | ||
pdf_merger.append(pdf_stream) | ||
pdf_merger.write(merged_pdf_stream) | ||
pdf_merger.close() | ||
|
||
return { | ||
"type": "ir.actions.report", | ||
"report_type": "qweb-pdf", | ||
"data": {"pdf_content": merged_pdf_stream.getvalue()}, | ||
"report_name": "Merged_Invoices", | ||
"name": _("Merged Invoices"), | ||
} | ||
else: | ||
raise UserError(_("No PDFs were generated for the selected invoices.")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very messy code, copy pasted, please, try to use functions and reuse code. The original code was very clean with a few branches with little code. Please clean the code
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Chek the comments please
No description provided.