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

[12.0][ADD] - New module: report substitute #307

Merged
merged 11 commits into from
Oct 21, 2019

Conversation

sbejaoui
Copy link
Contributor

@sbejaoui sbejaoui commented Jul 19, 2019

This module allows you to create substitution rules for report actions. A typical use case is to replace a standard report by alternative reports when some conditions are met. For instance, it allows to configure alternate reports for different companies.

@sbidoul

This comment has been minimized.

@sbejaoui sbejaoui changed the title [12.0][WIP] - New module: report substitute [12.0][ADD] - New module: report substitute Jul 22, 2019
Copy link
Member

@etobella etobella 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 you have a recursive issue.

However, it is really interesting!!!

self.model, res_ids
)
if substitution_report:
return substitution_report.render(res_ids)
Copy link
Member

Choose a reason for hiding this comment

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

Just wondering one thing, with this change, you may be substituting recursively... Maybe you should make:
return super(IrActionReport, substitution_report).render(res_ids)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes it is a desired behavior.
we return super only when there is no possible substitution. otherwise we continue the substitution recursively.

if substitution_report:
    return substitution_report.render(res_ids)
return super().render(res_ids, data)

Copy link
Member

@sbidoul sbidoul Jul 23, 2019

Choose a reason for hiding this comment

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

@etobella it's true that a user could create loops, and it might be nice to add a better error than a stack overflow if it happens. But that should not be an issue in practice, what do you think?

@sbidoul
Copy link
Member

sbidoul commented Jul 23, 2019

Last thing we'll add is an option to let the user decide what to do if there is no matching substitution: either raise an error, or fallback on the base report.

@sbejaoui sbejaoui force-pushed the 12.0-report_dispatch-sbj branch 2 times, most recently from c10e81b to 133d289 Compare July 25, 2019 11:23
report_substitute/models/ir_actions_report.py Outdated Show resolved Hide resolved
report_substitute/static/src/js/action_manager.js Outdated Show resolved Hide resolved
report_substitute/static/src/js/action_manager.js Outdated Show resolved Hide resolved
report_substitute/wizards/mail_compose_message.py Outdated Show resolved Hide resolved
report_substitute/wizards/mail_compose_message.py Outdated Show resolved Hide resolved
@sbidoul
Copy link
Member

sbidoul commented Aug 6, 2019

@sbejaoui can you check travis?

This module allows you to create substitution rules for report actions.
A typical use case is to replace a standard report by alternative reports
when some conditions are met. For instance, it allows to configure alternate
reports for different companies.
Copy link
Member

Choose a reason for hiding this comment

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

To manage alternative reports for different companies, I find the existing OCA module ir_actions_report_multi_company much easier for a non-technical user.

I would change this line in the readme: instead of mentioning reports for different companies, I would expect some other use case. A real case with some code examples would be here very appreciated.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In standard modules, many report calls are hard-coded by their xml ID. An example, the print quotation action in the sale module.

https://github.com/odoo/odoo/blob/48b3893b84cbd51f880548b38d036db5ebc1e256/addons/sale/models/sale.py#L489-L494

Adding an ir_rule to the report action will not resolve the use case here because this type of action will raise an access error for other companies if a company is set.

the alternative solutions that can be made in this case and that we avoid with this module:

  • override the print action to improve the way odoo get the report action.
  • override the report template to manage all the layout differences in the same template.

So the idea is to define some substitution rules on the standard report to return the desired one if some condition are met.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

IMO, with the domain widget used in the UI, the the substitution rules is easy to use for non-technical user

@api.multi
def render(self, res_ids, data=None):
substitution_report = self.get_substitution_report(res_ids)
return super(IrActionReport, substitution_report).render(res_ids, data)
Copy link
Member

Choose a reason for hiding this comment

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

No need to pass parameters to the super()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the super is called on a different object then self. have to be specified.

<odoo>

<record model="ir.ui.view" id="ir_actions_report_form_view">
<field name="name">ir.actions.report.form (in report_dispatch_base)
Copy link
Member

Choose a reason for hiding this comment

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

No need to specify the <field name="name"> ... since you are inheriting. Also report_dispatch_base is probably some leftover from old code.

Copy link
Contributor Author

@sbejaoui sbejaoui Aug 7, 2019

Choose a reason for hiding this comment

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

The name is required even in the case of inheritance.

good catch for the leftover.

Copy link
Member

Choose a reason for hiding this comment

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

If you don't specify the name, Odoo will automatically create one.

self.ensure_one()
action_report = self
substitution_report = action_report
while substitution_report:
Copy link
Member

Choose a reason for hiding this comment

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

With this while, the matching rule with higher value of the sequence will be executed instead of the previous matching rules. Is this the desired behavior?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The purpose of this while is to continue the substitution recursively. A substitution report can have a matching on a one of its substitution rules.

Copy link
Sponsor Contributor

Choose a reason for hiding this comment

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

With this while, the matching rule with higher value of the sequence will be executed instead of the previous matching rules. Is this the desired behavior?

@astirpe Due to this, it's ok https://github.com/OCA/reporting-engine/pull/307/files#diff-53c1b43ed6b9be73de53ef31d1261b38R11

Copy link
Sponsor Contributor

@rousseldenis rousseldenis left a comment

Choose a reason for hiding this comment

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

LGTM. Code review

self.ensure_one()
action_report = self
substitution_report = action_report
while substitution_report:
Copy link
Sponsor Contributor

Choose a reason for hiding this comment

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

With this while, the matching rule with higher value of the sequence will be executed instead of the previous matching rules. Is this the desired behavior?

@astirpe Due to this, it's ok https://github.com/OCA/reporting-engine/pull/307/files#diff-53c1b43ed6b9be73de53ef31d1261b38R11

@rousseldenis
Copy link
Sponsor Contributor

@astirpe Could you update your review?

Copy link
Member

@etobella etobella left a comment

Choose a reason for hiding this comment

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

For me it's good, just a nitpicking and a comment about the recursion issue.
It is not blocking

report_substitute/__manifest__.py Outdated Show resolved Hide resolved
)

@api.multi
def _get_substitution_report(self, model, active_ids):
Copy link
Member

Choose a reason for hiding this comment

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

Can you add a limit=1, increase every time and once it has reached 50 raise a Exception?
This way at least we know if we have recursion issue. What do you think?
It is not blocking.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added a check for the substitution infinite loop when creating the rules. can you check it please.

@sbidoul
Copy link
Member

sbidoul commented Oct 21, 2019

Looks like all comments have been handled here.

/ocabot merge, please

@OCA-git-bot
Copy link
Contributor

Hey, thanks for contributing! Proceeding to merge this for you.
Prepared branch 12.0-ocabot-merge-pr-307-by-sbidoul-bump-no, 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 2eb9253 into OCA:12.0 Oct 21, 2019
@OCA-git-bot
Copy link
Contributor

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

@sbidoul sbidoul deleted the 12.0-report_dispatch-sbj branch October 26, 2019 17:22
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.

None yet

6 participants