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

[11.0][IMP] hr_timesheet_sheet: fix amount calculation issues + code simplification #207

Merged
merged 6 commits into from
Mar 25, 2019
Merged

[11.0][IMP] hr_timesheet_sheet: fix amount calculation issues + code simplification #207

merged 6 commits into from
Mar 25, 2019

Conversation

astirpe
Copy link
Member

@astirpe astirpe commented Mar 13, 2019

This PR fixes the amount calculation issues (see #206) regarding the decrease of the amount of hours from the summary tab.
The idea is that decreasing the amount from the summary tab should not directly decrease the amounts of time for existing projects and/or tasks, to avoid potential loose of relevant information. In case it's needed, it's up to the end user to manually adjust the amounts or merge lines in the details tab.
This is basically achieved by removing the def _diff_amount_timesheets() method.

The proposed solution also causes a code reduction (simplified code) including the following:

  • Removed count_timesheets field
  • Simplified code for def onchange_unit_amount()
  • Makes use of field sheet.timesheet_ids in place of self.env['account.analytic.line'].search()

This PR implicitly allows negative amounts: two lines are removed from def onchange_unit_amount(), the same way as it is done in #201.

This PR also fixes method def _default_employee() in a multicompany environment, filtering the default employee by company.

Fixes #198

Fixes #209

Copy link
Contributor

@MiquelRForgeFlow MiquelRForgeFlow left a comment

Choose a reason for hiding this comment

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

This PR implicitly includes a fix for the negative amounts. The solution is a bit alternative to #201.

That's not a fix for the negative amounts. It's just the removal of the non negative amounts condition as in #201. And then, why do you propose an alternative? What's wrong with the #201? Now, will reviewers need to choose between two PRs? I don't understand. I think you could propose here only the other changes (the ones solving your issue #206) instead of doing also commits that enter in conflict with #201. If you want changes, then request changes in my PR, but don't open alternative PRs regarding a same topic (negative amounts). Also, I could be happy to include the solution of your issue in #201, it's easy.

hr_timesheet_sheet/models/hr_timesheet_sheet.py Outdated Show resolved Hide resolved
@astirpe
Copy link
Member Author

astirpe commented Mar 13, 2019

@mreficent While simplifying that method, I just deleted the same 2 lines you already deleted in your PR. That was necessary because of the design of this PR, the reason is already explained above: this PR fixes the decreasing of the amounts, and decreasing by setting negative amounts is also part of the cases fixed by this PR. Nobody is complaining about your PR #201 which remains valid.

@MiquelRForgeFlow
Copy link
Contributor

@astirpe ok, I will check

@astirpe
Copy link
Member Author

astirpe commented Mar 14, 2019

Commit b5d1a7a should fix the issue mentioned in #207 (comment)

Copy link
Member

@nikul-serpentcs nikul-serpentcs left a comment

Choose a reason for hiding this comment

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

Minor change

hr_timesheet_sheet/__manifest__.py Show resolved Hide resolved
Copy link
Contributor

@MiquelRForgeFlow MiquelRForgeFlow left a comment

Choose a reason for hiding this comment

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

Review completed. Good changes. 👍

But please, answer my question above

@MiquelRForgeFlow
Copy link
Contributor

@alexey-pelykh could you review this?

@astirpe
Copy link
Member Author

astirpe commented Mar 19, 2019

Commit [FIX] Allow to delete all lines + better tab sync contains a fix for issue #198. The fix is better than the one proposed in #203.

The proposed solution consists in splitting and fixing the onchange method of the date fields and the timesheet_ids.

As a consequence of fixing the onchange methods, another wrong behavior is fixed: when deleting lines in the Details tab, the Summary tab is automatically updated (it was not updated before this commit).

Supersedes #203.

@astirpe
Copy link
Member Author

astirpe commented Mar 19, 2019

Commit 455d280 fixes the onchange of field employee_id (fixes #209).

The proposed fix restores the state 'New' for the timesheet sheet, like it was in standard Odoo 10.0 (see line).

Restoring the state 'New' is necessary to impede the onchange of date_start, date_end and employee_id being triggered when the status is "Draft". In facts performing the onchange when the status is "Draft" will cause the timesheet lines being deleted from database (this must be avoided!).

@astirpe
Copy link
Member Author

astirpe commented Mar 19, 2019

Squashed and rebased

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.

Did the code review, yet no functional test yet

hr_timesheet_sheet/models/hr_employee.py Outdated Show resolved Hide resolved
hr_timesheet_sheet/models/hr_timesheet_sheet.py Outdated Show resolved Hide resolved
hr_timesheet_sheet/models/hr_timesheet_sheet.py Outdated Show resolved Hide resolved
hr_timesheet_sheet/models/hr_timesheet_sheet.py Outdated Show resolved Hide resolved
hr_timesheet_sheet/models/hr_timesheet_sheet.py Outdated Show resolved Hide resolved
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.

Code LGTM, yet I'm already scared how this going to be ported to v12

@alexey-pelykh
Copy link
Contributor

@astirpe please squash the code review commit as fixup into other commit

@astirpe
Copy link
Member Author

astirpe commented Mar 20, 2019

@alexey-pelykh I can do the porting to V12, I think I'm now confident enough with this module.

@alexey-pelykh
Copy link
Contributor

@astirpe That would be much appreciated!

[IMP] Fix amount calculation issues

[IMP] Better warning message when onchange_unit_amount() fails

[IMP] Performance

[FIX] Allow to delete all lines + better tab sync

[IMP] Coverage

[REM] Remove useless lines of code

[IMP] Code simplification

[IMP] Code review
[FIX] Make employee_id readonly when timesheet sheet is approved

[FIX] Onchange employee_id
@astirpe
Copy link
Member Author

astirpe commented Mar 20, 2019

Porting to V12: #211

@astirpe
Copy link
Member Author

astirpe commented Mar 21, 2019

I need also 412a801 to make customization easier

@astirpe
Copy link
Member Author

astirpe commented Mar 21, 2019

And 4dc6093 makes the list view more readable.

@astirpe
Copy link
Member Author

astirpe commented Mar 21, 2019

Commit b2c5b30 simplifies the code and I think also with performance benefits

@astirpe
Copy link
Member Author

astirpe commented Mar 22, 2019

Commit 66a2455 fixes the following issue.

  1. Be sure that admin user belongs to company: YourCompany.
  2. Create CompanyB.
  3. Create UserB, belonging to CompanyB.
  4. Create EmployeeB, belonging to CompanyB and linked to UserB.
  5. Login as admin and create a new timesheet sheet. Do not save yet.
  6. Change employee to EmployeeB.

Company is not updated: it stays YourCompany (not ok).
It is not possible to change the Company because it's a readonly field.
Save. Error is displayed: "The Company in the Timesheet Sheet and in the Employee must be the same".

@alexey-pelykh
Copy link
Contributor

@astirpe do you plan other changes in this PR?

@astirpe
Copy link
Member Author

astirpe commented Mar 22, 2019

@alexey-pelykh No. I would be happy to stop it here. 😉

@alexey-pelykh
Copy link
Contributor

@nikul-serpentcs please re-review

Copy link
Member

@nikul-serpentcs nikul-serpentcs left a comment

Choose a reason for hiding this comment

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

Only Code review LGTM 👍

@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). 🤖

@alexey-pelykh
Copy link
Contributor

@pedrobaeza please take a look at this PR

@pedrobaeza
Copy link
Member

Merging blindly on my side due to previous approvals.

@pedrobaeza pedrobaeza merged commit bbace75 into OCA:11.0 Mar 25, 2019
@astirpe astirpe deleted the 11_fix_hr_timesheet_sheet2 branch March 25, 2019 08:49
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.

6 participants