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][IMP] hr_holidays_leave_auto_approve: Auto-approve for everyone #663

Merged
merged 1 commit into from Nov 19, 2019

Conversation

jarroyomorales
Copy link

PR related to the discussion in #610 .
Added a new boolean field for leave types auto_approve_all which makes all leave requests of that type be automatically approved by the odoo bot.

cc @alexey-pelykh @vmelnych @neilmitchell-goodson

Copy link
Contributor

@alexey-pelykh alexey-pelykh left a comment

Choose a reason for hiding this comment

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

LGTM

@jarroyomorales jarroyomorales force-pushed the 12.0-approve-all branch 2 times, most recently from 8c4d92a to edc3464 Compare August 27, 2019 13:57
@OCA-git-bot
Copy link
Contributor

This PR has the approved label and has been created more than 5 days ago. It should therefore be ready to merge by a maintainer (or a PSC member if the concerned addon has no declared maintainer). 🤖

@astirpe
Copy link
Member

astirpe commented Sep 24, 2019

@CasVissers I'm sure you would be interested in this PR!

@jarroyomorales
Copy link
Author

@OCA/human-resources-maintainers Can this be merged?

@alexey-pelykh
Copy link
Contributor

One more review needed

@jarroyomorales
Copy link
Author

@alexey-pelykh Isnt 2 the minimum?

@alexey-pelykh
Copy link
Contributor

2 + 1 PCS

@jarroyomorales
Copy link
Author

Oh okay!

@gurneyalex
Copy link
Member

/ocabot merge

@OCA-git-bot
Copy link
Contributor

This PR looks fantastic, let's merge it!
Prepared branch 12.0-ocabot-merge-pr-663-by-gurneyalex-bump-no, awaiting test results.

OCA-git-bot added a commit that referenced this pull request Nov 19, 2019
Signed-off-by gurneyalex
@alexey-pelykh
Copy link
Contributor

I'd also propose for next migration or improvement make a setting field of "auto-approve policy" instead of 2 Boolean fields

@OCA-git-bot
Copy link
Contributor

@gurneyalex your merge command was aborted due to failed check(s), which you can inspect on this commit of 12.0-ocabot-merge-pr-663-by-gurneyalex-bump-no.

After fixing the problem, you can re-issue a merge command. Please refrain from merging manually as it will most probably make the target branch red.

@jarroyomorales
Copy link
Author

I'd also propose for next migration or improvement make a setting field of "auto-approve policy" instead of 2 Boolean fields

@alexey-pelykh It is a good idea, but then we wont be able to autoapprove some leaves and not autoapprove other types.

@alexey-pelykh
Copy link
Contributor

@jarroyomorales Setting per leave-type of course

@jarroyomorales
Copy link
Author

@alexey-pelykh Oh sorry, I thought you meant adding a field auto-approve policy to res.config.settings, my bad.
In that case I completely agree with you.

@alexey-pelykh
Copy link
Contributor

Do we want to introduce this approach in this PR?

@jarroyomorales
Copy link
Author

OK, I can try, a migration script will be needed too, am i right?

@alexey-pelykh
Copy link
Contributor

Yes, and I can help with that if needed

@jarroyomorales
Copy link
Author

@alexey-pelykh Can you review please? If it is okay i will go for the migration script

@alexey-pelykh
Copy link
Contributor

And please squash to 1 commit

@jarroyomorales
Copy link
Author

@alexey-pelykh Comments attended

values.get('holiday_status_id')
).auto_approve
)
auto_approve = leave_type.auto_approve_policy != 'no'
Copy link
Contributor

Choose a reason for hiding this comment

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

Extract as def _should_auto_approve method

Copy link
Author

Choose a reason for hiding this comment

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

Don't you think we can just delete the _get_auto_approve_on_creation() function? It is used to disable the creation message in case the leave can be auto approved, which I dont undersand why. IMHO it is not necessary to do that

Copy link
Contributor

Choose a reason for hiding this comment

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

If we're self-approving, we don't want message about user approved own request being sent to himself, BUT there can be other watchers by default. Probably if "only user will receive message" then don't send it, or exclude self from followers, something like that. We can address that as separate PR

@@ -12,6 +12,13 @@ def _check_approval_update(self, state):
return
return super()._check_approval_update(state)

@api.multi
def apply_auto_approve_policy(self):
Copy link
Contributor

Choose a reason for hiding this comment

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

Use _ to make this method non-RPC-callable

def apply_auto_approve_policy(self):
for record in self:
policy = record.holiday_status_id.auto_approve_policy
if (record.can_approve and policy == 'hr') or policy == 'all':
Copy link
Contributor

Choose a reason for hiding this comment

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

Reuse _should_auto_approve ?

if record._should_auto_approve():
    record.sudo().action_approve()

Copy link
Author

Choose a reason for hiding this comment

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

The whole function could be done in one line like this

self.filtered(lambda r: r._should_auto_approve()).sudo().action_approve()

but will we have possible future inheritance errors?

Copy link
Contributor

Choose a reason for hiding this comment

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

no, it would work normally

@alexey-pelykh
Copy link
Contributor

Direction is great, let's proceed to migration script as well 👍

@jarroyomorales
Copy link
Author

@alexey-pelykh Migration done and works as expected. I am keeping the auto_approve column for security.

values.get('holiday_status_id')
).auto_approve
)
auto_approve = leave_type.auto_approve_policy != 'no'
Copy link
Contributor

Choose a reason for hiding this comment

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

If we're self-approving, we don't want message about user approved own request being sent to himself, BUT there can be other watchers by default. Probably if "only user will receive message" then don't send it, or exclude self from followers, something like that. We can address that as separate PR

@alexey-pelykh
Copy link
Contributor

/ocabot merge

@OCA-git-bot
Copy link
Contributor

Hey, thanks for contributing! Proceeding to merge this for you.
Prepared branch 12.0-ocabot-merge-pr-663-by-alexey-pelykh-bump-no, awaiting test results.

OCA-git-bot added a commit that referenced this pull request Nov 19, 2019
Signed-off-by alexey-pelykh
@OCA-git-bot OCA-git-bot merged commit 44f2984 into OCA:12.0 Nov 19, 2019
@OCA-git-bot
Copy link
Contributor

Congratulations, your PR was merged at 5fd1d77. 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.

None yet

7 participants