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

report_xlsx: fix report context propagation on records #259

Merged
merged 1 commit into from
Oct 21, 2019

Conversation

simahawk
Copy link

@simahawk simahawk commented Dec 4, 2018

Without this change If you return a custom action that sets a custom context -> you lose it -> if your report depends on it... it's broken 😭

@adrienpeiffer @sbidoul this fixes XLS export on mis.report.instance 😉

Fixes #326

@simahawk simahawk changed the title report_xlsx: fix report context propagation on records [WIP] report_xlsx: fix report context propagation on records Dec 4, 2018
@simahawk
Copy link
Author

simahawk commented Dec 4, 2018

digging into this issue turns out that if you don't pass data in the action you return, you won't get anything into data in the controller 🤔

@sbidoul
Copy link
Member

sbidoul commented Dec 4, 2018

@simahawk
Copy link
Author

simahawk commented Dec 4, 2018

@sbidoul but that code has been migrated already to v11 since there's not get_action.
Anyway, the issue is not there. What you have in mis_builder now is:

return {
            'name': 'MIS report instance XLSX report',
            'model': 'mis.report.instance',
            'type': 'ir.actions.report',
            'report_name': 'mis_builder.mis_report_instance_xlsx',
            'report_type': 'xlsx',
            'report_file': 'mis_report_instance',
            'context': context,
        }

and this does not work.
If I apply this patch, it does not work neither, unless I change the dict above like:

[...]
            'context': context,
            'data': {'__make_report_controller_work__': 1},

by adding data key. However, its content doesn't matter...

@sbidoul
Copy link
Member

sbidoul commented Apr 28, 2019

@simahawk is this still WIP?

@sbidoul sbidoul added the bug label Apr 28, 2019
@sbidoul sbidoul added this to the 11.0 milestone Apr 28, 2019
@simahawk
Copy link
Author

@sbidoul I'm not working on this since ages 😅
Actually I was waiting for feedback, especially on the fact that we have to add a fake data dict anyhow to make it work 🤷‍♂️

@sbidoul
Copy link
Member

sbidoul commented Apr 29, 2019

All I can say is the fake data dict is needed to propagate the context for pdf reports too. So at least the hack is consistent ;) Why it is so is beyond me...

@simahawk
Copy link
Author

Why it is so is beyond me...

It's because the controller relies on the automatic conversion of the params in the request and if the param is not in the request they ignore it completely 🤦‍♂️

@simahawk
Copy link
Author

ok then I'll update this PR w/ a mention in the docs

@sbidoul
Copy link
Member

sbidoul commented Apr 29, 2019

@simahawk I just debugged a bit, and I think the context is actually lost here:

return report_model.with_context({
'active_model': self.model
}).create_xlsx_report(docids, data)

So replacing that with with_context(active_model=self.model) (plus the data hack in the report action), it seems to work.

@simahawk
Copy link
Author

I removed context manipulation and fixed up the places where the context was replaced instead of updated. I cannot test it now, I'll see if someone else can.

Copy link
Member

@jffernandez jffernandez left a comment

Choose a reason for hiding this comment

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

I think that to fix the context propagation only is needed one change, with that it works.
See inline comments.
Thank you for your PR!

report_xlsx/controllers/main.py Outdated Show resolved Hide resolved
report_xlsx/models/ir_report.py Outdated Show resolved Hide resolved
report_xlsx_helper/controllers/main.py Outdated Show resolved Hide resolved
report_xlsx/report/report_xlsx.py Show resolved Hide resolved
Copy link
Member

@sbidoul sbidoul left a comment

Choose a reason for hiding this comment

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

@simahawk if you'd have 2 minutes to revert the **context changes which are not really necessary?

For the rest I tested and the fix works fine. Thanks!

@simahawk simahawk changed the title [WIP] report_xlsx: fix report context propagation on records report_xlsx: fix report context propagation on records Oct 21, 2019
@simahawk
Copy link
Author

I changed "blindly" what have you asked for, no time to test, sorry guys :/

@sbidoul
Copy link
Member

sbidoul commented Oct 21, 2019

Thanks!

/ocabot merge patch

fixes #326

@OCA-git-bot
Copy link
Contributor

Hey, thanks for contributing! Proceeding to merge this for you.
Prepared branch 11.0-ocabot-merge-pr-259-by-sbidoul-bump-patch, awaiting test results.

OCA-git-bot added a commit that referenced this pull request Oct 21, 2019
Signed-off-by sbidoul
@OCA-git-bot OCA-git-bot merged commit 4a1398c into OCA:11.0 Oct 21, 2019
@OCA-git-bot
Copy link
Contributor

Congratulations, your PR was merged at 532e84e. Thanks a lot for contributing to OCA. ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants