[18.0][REF] payroll: refactor start/end dates the month#246
Open
CristianoMafraJunior wants to merge 1 commit intoOCA:18.0from
Open
[18.0][REF] payroll: refactor start/end dates the month#246CristianoMafraJunior wants to merge 1 commit intoOCA:18.0from
CristianoMafraJunior wants to merge 1 commit intoOCA:18.0from
Conversation
Contributor
|
Hi @nimarosa, @appstogrow, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Root cause
The failing test was TestPayslipFlow.test_get_contracts_singleton in payroll/tests/test_payslip_flow.py.
This test was tweaking dates and creating a second contract for employee Sally using
Date.today(), assuming that would always be safe.In the current hr_contract implementation, there is a constraint
(_check_current_contract)that forbids an employee from having two overlapping contracts in active-like states (incoming/open/close), except when they are draft or cancel.Combined with the way Sally’s first contract is created in
common.py(always starting on the first day of the month), this meant that around certain dates (especially month/year boundaries) the two contracts’ periods could overlap, triggering:ValidationError: An employee can only have one contract at the same time. (Excluding Draft and Cancelled contracts).
Fix
Instead of relying on
Date.today()inside the test, we now build the scenario based on the actual dates of Sally’s first contract, which is created in TestPayslipBase:Retrieve Sally’s current contract:
first_contract = self.sally.contract_id.Close that contract with a non-overlapping, valid period:
date_end = first_contract.date_startfirst_contract.write({"date_end": end_date.strftime("%Y-%m-%d"), "state": "close"})Create the second contract starting the day after the first contract ends:
second_start = end_date + timedelta(days=1)self.Contract.create({... "date_start": second_start.strftime("%Y-%m-%d"), ...})With this:
There is no longer any overlap between Sally’s contracts.
The _check_current_contract constraint is satisfied.
The test still verifies the intended behavior —
_get_employee_contracts()returns exactly one valid contract for the employee — but now in a deterministic, date‑independent way.