-
-
Notifications
You must be signed in to change notification settings - Fork 776
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
Conversation
This comment has been minimized.
This comment has been minimized.
e462def
to
bd1e716
Compare
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.
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) |
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.
Just wondering one thing, with this change, you may be substituting recursively... Maybe you should make:
return super(IrActionReport, substitution_report).render(res_ids)
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.
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)
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.
@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?
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. |
c10e81b
to
133d289
Compare
ba07ee9
to
25fb2a0
Compare
@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. |
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.
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.
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.
In standard modules, many report calls are hard-coded by their xml ID. An example, the print quotation action in the sale module.
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.
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.
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) |
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.
No need to pass parameters to the super()
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.
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) |
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.
No need to specify the <field name="name"> ...
since you are inheriting. Also report_dispatch_base
is probably some leftover from old 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.
The name is required even in the case of inheritance.
good catch for the leftover.
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.
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: |
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.
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?
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.
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.
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.
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
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.
LGTM. Code review
self.ensure_one() | ||
action_report = self | ||
substitution_report = action_report | ||
while substitution_report: |
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.
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
@astirpe Could you update your review? |
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.
For me it's good, just a nitpicking and a comment about the recursion issue.
It is not blocking
) | ||
|
||
@api.multi | ||
def _get_substitution_report(self, model, active_ids): |
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.
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.
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.
I added a check for the substitution infinite loop when creating the rules. can you check it please.
This addon give the possibility to substitute a report action by another based on some criteria.
caa970b
to
2eb9253
Compare
Looks like all comments have been handled here. /ocabot merge, please |
Hey, thanks for contributing! Proceeding to merge this for you. |
Congratulations, your PR was merged at 983ac31. Thanks a lot for contributing to OCA. ❤️ |
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.