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

16.0 [IMP] maintenance_timesheet: use create_multi in account.analytic.line #390

Merged

Conversation

IT-Ideas
Copy link

No description provided.

@IT-Ideas IT-Ideas changed the title [IMP] maintenance_timesheet: use create_multi in account.analytic.line 16.0 [IMP] maintenance_timesheet: use create_multi in account.analytic.line Mar 11, 2024
@pedrobaeza pedrobaeza added this to the 16.0 milestone Mar 11, 2024
@IT-Ideas IT-Ideas force-pushed the 16.0-maintenance_timsheet-create_multi-lst branch from 1bb5732 to 45bee4a Compare March 11, 2024 10:49
@IT-Ideas
Copy link
Author

@pedrobaeza what do you think?

Comment on lines 21 to 27
maintenance_request_ids = [
vals.get("maintenance_request_id")
for vals in vals_list
if vals.get("maintenance_request_id")
]
self._check_requests_done(maintenance_request_ids)
return super().create(vals_list)
Copy link
Member

Choose a reason for hiding this comment

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

Please don't complicate API with 2 methods with just an extra s (very easy to be typo error), and don't complicate logic. It's easier this way:

Suggested change
maintenance_request_ids = [
vals.get("maintenance_request_id")
for vals in vals_list
if vals.get("maintenance_request_id")
]
self._check_requests_done(maintenance_request_ids)
return super().create(vals_list)
for vals in vals_list:
if vals.get("maintenance_request_id"):
self._check_requests_done(vals["maintenance_request_id"])
return super().create(vals_list)

Copy link
Author

@IT-Ideas IT-Ideas Mar 11, 2024

Choose a reason for hiding this comment

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

Hello @pedrobaeza , the problem to me is really that https://github.com/OCA/maintenance/pull/390/files#diff-ce85fd70c56eb1115afe99031137572f69d8b227218faad2d9119f9d5fcde50dR55 will make a distinct select for each record... The create_multi has been made in order to prevent those situations so I personally find that 'just' making a loop around the previous implementation is a bit sad...

I would rather change the name in order to avoid typo issue and keep my implementation. What name would you propose?

Copy link

Choose a reason for hiding this comment

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

@IT-Ideas We could keep the same method and document that it could be called with a single id or with a list of ids...

Comment on lines 21 to 27
maintenance_request_ids = [
vals.get("maintenance_request_id")
for vals in vals_list
if vals.get("maintenance_request_id")
]
self._check_requests_done(maintenance_request_ids)
return super().create(vals_list)
Copy link

Choose a reason for hiding this comment

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

@IT-Ideas We could keep the same method and document that it could be called with a single id or with a list of ids...

Comment on lines 44 to 47
def _check_request_done(self, request_id):
"""
Editing a timesheet related to a finished request is forbidden.
"""
Copy link

Choose a reason for hiding this comment

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

Suggested change
def _check_request_done(self, request_id):
"""
Editing a timesheet related to a finished request is forbidden.
"""
def _check_request_done(self, request_id: int | list[int]):
"""
Editing a timesheet related to a finished request is forbidden.
"""
request_ids = [request_id] if isinstance(request_id, int) else request_id

Comment on lines 48 to 47
self._check_requests_done([request_id])

def _check_requests_done(self, request_ids):
"""
Editing a timesheet related to a finished request is forbidden.
"""
Copy link

Choose a reason for hiding this comment

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

Suggested change
self._check_requests_done([request_id])
def _check_requests_done(self, request_ids):
"""
Editing a timesheet related to a finished request is forbidden.
"""

@IT-Ideas IT-Ideas force-pushed the 16.0-maintenance_timsheet-create_multi-lst branch from 45bee4a to 55a4bf4 Compare March 11, 2024 13:59
Copy link
Member

@pedrobaeza pedrobaeza left a comment

Choose a reason for hiding this comment

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

OK, the polymorphic option is not my best option (due to the argument variable name), but I don't block this more.

Copy link

@lmignon lmignon left a comment

Choose a reason for hiding this comment

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

As of the polymorphic approach is documented, it's the bet solution to take benefit of perf improvement without introducing duplicate code. The other option would be to keep only one method taking a list of ids as arg and update the existing call to the method accordingly...

@pedrobaeza
Copy link
Member

/ocabot merge patch

@OCA-git-bot
Copy link
Contributor

What a great day to merge this nice PR. Let's do it!
Prepared branch 16.0-ocabot-merge-pr-390-by-pedrobaeza-bump-patch, awaiting test results.

@OCA-git-bot OCA-git-bot merged commit 9fd56c0 into OCA:16.0 Mar 11, 2024
7 checks passed
@OCA-git-bot
Copy link
Contributor

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

@lmignon lmignon deleted the 16.0-maintenance_timsheet-create_multi-lst branch March 11, 2024 16:48
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