Skip to content
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

[FIX] account: select generated pdf streams from invoices without attachments #160670

Conversation

mizosoft
Copy link
Contributor

@mizosoft mizosoft commented Apr 5, 2024

Issue

Report creation for multiple invoices fails (e.g. with <AttributeError: "NoneType" object has no attribute "getvalue">)
when some, but not all, of the invoices across the selection have a previously generated report
as an attachment, and the 'Reload from attachment' option is enabled for the report action.

Steps

  • Enable 'Reload from attachment' from Settings -> Techical -> Actions -> Reports -> invoices.
  • Create 3 invoices without any previous reports as attachments.
  • Select the middle invoice and generate a report (Print -> Invoices). An attachment will be created
    for the invoice.
  • Select the 3 invoices then generate a report (Print -> Invoices).

Cause

When "Reload from attachment" is enabled, the algorithm for creating aggregate reports for a number
of invoices selects only those that don't have an attachment to generate a pdf for. These are copied
into a separate list "res_ids_wo_stream". When the pdfs streams are generated, they're put back into
the return value "collected_streams. However, this was done from the original ids list "res_ids" rather
than the selected one, which resulted in an indexing issue.

opw-3827700
Closes #157975

@robodoo
Copy link
Contributor

robodoo commented Apr 5, 2024

@C3POdoo C3POdoo requested review from a team, clbr-odoo, rco-odoo and HydrionBurst and removed request for a team April 5, 2024 11:48
@mizosoft mizosoft force-pushed the 16.0-opw-3827700-reload_from_attachment_misbehaviour-mohu branch from 9e44b56 to 1d65467 Compare April 5, 2024 11:51
@C3POdoo C3POdoo added the OE the report is linked to a support ticket (opw-...) label Apr 5, 2024
@mizosoft mizosoft force-pushed the 16.0-opw-3827700-reload_from_attachment_misbehaviour-mohu branch from 1d65467 to 6759c9b Compare April 5, 2024 13:12
@mizosoft mizosoft marked this pull request as draft April 5, 2024 13:26
@mizosoft mizosoft force-pushed the 16.0-opw-3827700-reload_from_attachment_misbehaviour-mohu branch from 6759c9b to a15ec77 Compare April 5, 2024 14:45
Copy link
Contributor

@nle-odoo nle-odoo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good to me

addons/account/tests/test_ir_actions_report.py Outdated Show resolved Hide resolved
@mizosoft mizosoft force-pushed the 16.0-opw-3827700-reload_from_attachment_misbehaviour-mohu branch 3 times, most recently from f56dfcc to 4bb5f24 Compare April 10, 2024 09:54
@mizosoft mizosoft marked this pull request as ready for review April 10, 2024 09:55
@mizosoft mizosoft changed the title [FIX] account: reload from attachment misbehaviour [FIX] account: select generated pdf streams from invoices without attachments Apr 10, 2024
@C3POdoo C3POdoo requested review from a team April 10, 2024 10:05
@mizosoft mizosoft force-pushed the 16.0-opw-3827700-reload_from_attachment_misbehaviour-mohu branch from 5fecf05 to 10bb54d Compare April 17, 2024 13:07
Copy link
Contributor

@william-andre william-andre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Always better to use recordsets instead of lists of records.
Since it's a test, I'll 🙈 but try to remember that in the future 😉
(Same for the creation, better to do it in batch)

@robodoo r+

}) for i in range(50)] # Make this a multipage invoice.
})

self.assert_invoice_creation([first_invoice, second_invoice, third_invoice], second_invoice)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
self.assert_invoice_creation([first_invoice, second_invoice, third_invoice], second_invoice)
self.assert_invoice_creation((first_invoice + second_invoice + third_invoice), second_invoice)

Comment on lines +196 to +197
self.assertTrue(
invoice_to_report.id in [invoice.id for invoice in invoices], "Invoice to report must be in invoices list")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
self.assertTrue(
invoice_to_report.id in [invoice.id for invoice in invoices], "Invoice to report must be in invoices list")
self.assertIn(invoice_to_report, invoices, "Invoice to report must be in invoices list")

Comment on lines +200 to +201
for invoice in invoices:
invoice.action_post()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
for invoice in invoices:
invoice.action_post()
invoices.action_post()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Neat!

Comment on lines +217 to +218
aggregate_report_content, content_type = reports._render_qweb_pdf(invoices_report_ref,
res_ids=[invoice.id for invoice in invoices])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
aggregate_report_content, content_type = reports._render_qweb_pdf(invoices_report_ref,
res_ids=[invoice.id for invoice in invoices])
aggregate_report_content, content_type = reports._render_qweb_pdf(invoices_report_ref,
res_ids=invoices.ids)

@mizosoft
Copy link
Contributor Author

Neat suggestions. I'll keep that in mind, thank you!

robodoo pushed a commit that referenced this pull request Apr 17, 2024
…achments

Issue
-----

Report creation for multiple invoices fails (e.g. with <AttributeError: "NoneType" object has no attribute "getvalue">)
when some, but not all, of the invoices across the selection have a previously generated report
as an attachment, and the 'Reload from attachment' option is enabled for the report action.

Steps
-----

 - Enable 'Reload from attachment' from Settings -> Techical -> Actions -> Reports -> invoices.
 - Create 3 invoices without any previous reports as attachments.
 - Select the middle invoice and generate a report (Print -> Invoices). An attachment will be created
   for the invoice.
 - Select the 3 invoices then generate a report (Print -> Invoices).

Cause
-----

When "Reload from attachment" is enabled, the algorithm for creating aggregate reports for a number
of invoices selects only those that don't have an attachment to generate a pdf for. These are copied
into a separate list "res_ids_wo_stream". When the pdfs streams are generated, they're put back into
the return value "collected_streams. However, this was done from the original ids list "res_ids" rather
than the selected one, which resulted in an indexing issue.

opw-3827700
Closes #157975

closes #160670

Signed-off-by: William André (wan) <wan@odoo.com>
@robodoo robodoo closed this Apr 17, 2024
@fw-bot
Copy link
Contributor

fw-bot commented Apr 21, 2024

@mizosoft @william-andre this pull request has forward-port PRs awaiting action (not merged or closed):

1 similar comment
@fw-bot
Copy link
Contributor

fw-bot commented Apr 22, 2024

@mizosoft @william-andre this pull request has forward-port PRs awaiting action (not merged or closed):

mizosoft added a commit to odoo-dev/odoo that referenced this pull request Apr 22, 2024
Issue
-----

Make `test_ir_actions_report.py` configure the invoices report to create attachments
if it is not configured to do so. Previously (in odoo#160670) it was assumed that this is
the case, so the test failed otherwise. Also, the portion of the test concerned with
\odoo#160670 is moved to `base` instead of `account`.
@fw-bot
Copy link
Contributor

fw-bot commented Apr 23, 2024

@mizosoft @william-andre this pull request has forward-port PRs awaiting action (not merged or closed):

5 similar comments
@fw-bot
Copy link
Contributor

fw-bot commented Apr 24, 2024

@mizosoft @william-andre this pull request has forward-port PRs awaiting action (not merged or closed):

@fw-bot
Copy link
Contributor

fw-bot commented Apr 25, 2024

@mizosoft @william-andre this pull request has forward-port PRs awaiting action (not merged or closed):

@fw-bot
Copy link
Contributor

fw-bot commented Apr 26, 2024

@mizosoft @william-andre this pull request has forward-port PRs awaiting action (not merged or closed):

@fw-bot
Copy link
Contributor

fw-bot commented Apr 27, 2024

@mizosoft @william-andre this pull request has forward-port PRs awaiting action (not merged or closed):

@fw-bot
Copy link
Contributor

fw-bot commented Apr 29, 2024

@mizosoft @william-andre this pull request has forward-port PRs awaiting action (not merged or closed):

mizosoft added a commit to odoo-dev/odoo that referenced this pull request May 7, 2024
Issue
-----

Make `test_ir_actions_report.py` configure the invoices report to create attachments
if it is not configured to do so. Previously (in odoo#160670) it was assumed that this is
the case, so the test failed otherwise. Also, the portion of the test concerned with
\odoo#160670 is moved to `base` instead of `account`.
mizosoft added a commit to odoo-dev/odoo that referenced this pull request May 16, 2024
Issue
-----

Make `test_ir_actions_report.py` configure the invoices report to create attachments
if it is not configured to do so. Previously (in odoo#160670) it was assumed that this is
the case, so the test failed otherwise. Also, the portion of the test concerned with
\odoo#160670 is moved to `base` instead of `account`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
OE the report is linked to a support ticket (opw-...)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants