Skip to content
5 changes: 0 additions & 5 deletions addons/hr/models/hr_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,11 +195,6 @@ def _get_hr_responsible_domain(self):
'An employee cannot have multiple active versions sharing the same effective date.',
)

_check_wage_positive = models.Constraint(
'CHECK(wage >= 0)',
'The wage must be a positive value.',
)

@api.depends('employee_id.company_id')
def _compute_company_id(self):
for version in self:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<t t-name="hr.ButtonNewContract">
<span class="w-100 d-flex justify-content-end">
<button class="btn btn-link p-0 o_field_widget text-end w-auto" t-on-click="onClickNewContractBtn"
t-ref="datetime-picker-target-new-contract" t-if="props.record.data.contract_date_start">New Contract</button>
t-ref="datetime-picker-target-new-contract">New Contract</button>
</span>
</t>
</template>
38 changes: 17 additions & 21 deletions addons/hr/tests/test_hr_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -520,27 +520,6 @@ def test_multi_edit_other_and_contract_date_sync(self):
self.assertEqual(version.job_id.id, jobB.id)
self.assertEqual(version.contract_date_end, date(2020, 9, 30))

def test_delete_version(self):
employee = self.env['hr.employee'].create({
'name': 'John Doe',
'date_version': '2020-01-01',
})
v1 = employee.version_id
v2 = employee.create_version({
'date_version': '2021-01-01',
})
v3 = employee.create_version({
'date_version': '2022-01-01',
})
self.assertEqual(employee.current_version_id, v3)

v3.unlink()
self.assertEqual(employee.current_version_id, v2)
v1.unlink()
self.assertEqual(employee.current_version_id, v2)
with self.assertRaises(ValidationError):
v2.unlink()

def test_multi_edit_multi_employees_no_contract(self):
"""
Test the multi-edit when there is one version per employee, without contract
Expand Down Expand Up @@ -697,3 +676,20 @@ def test_hr_version_fields_tracking(self):
fields_without_tracking,
f"The following hr.version fields should have tracking=True: {fields_without_tracking}",
)

def test_delete_hr_version(self):
employee = self.env['hr.employee'].create(
{
'name': 'John Doe',
'date_version': '2024-01-01',
}
)

version1 = employee.version_id
version2 = employee.create_version({
'date_version': '2025-01-01',
})

version1.unlink()
with self.assertRaises(ValidationError):
version2.unlink()
2 changes: 1 addition & 1 deletion addons/hr/views/hr_employee_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@
<span invisible="not contract_date_start">to</span>
<field name="contract_date_end" string="End Date" placeholder="Indefinite"
class="o_hr_narrow_field ms-3" invisible="not contract_date_start"/>
<widget name="button_new_contract"/>
<widget name="button_new_contract" invisible="not contract_date_start"/>
</div>
<label for="wage"/>
<div class="o_row" name="wage">
Expand Down
5 changes: 3 additions & 2 deletions addons/hr_holidays/models/hr_leave_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,14 +272,15 @@ def _search_max_leaves(self, operator, value):
return [('id', 'in', valid_leaves)]

def _search_virtual_remaining_leaves(self, operator, value):
def is_valid(leave_type):
return not leave_type.requires_allocation or op(leave_type.virtual_remaining_leaves, value)
op = PY_OPERATORS.get(operator)
if not op:
return NotImplemented
if operator != 'in':
value = float(value)
leave_types = self.env['hr.leave.type'].search([])

def is_valid(leave_type):
return not leave_type.requires_allocation or op(leave_type.virtual_remaining_leaves, value)
return [('id', 'in', leave_types.filtered(is_valid).ids)]

@api.depends_context('employee_id', 'default_employee_id', 'leave_date_from', 'default_date_from')
Expand Down
56 changes: 56 additions & 0 deletions addons/hr_holidays/tests/test_hr_leave_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,59 @@ def test_users_tz_shift_back(self):
).search([('has_valid_allocation', '=', True)], limit=1)

self.assertFalse(leave_types, "Got valid leaves outside vaild period")

def test_search_virtual_remaining_leaves(self):
employee = self.env['hr.employee'].create({'name': 'Test Employee'})
leave_type_1 = self.env['hr.leave.type'].create({
'name': 'Test Leave 1',
'requires_allocation': True,
})
leave_type_2 = self.env['hr.leave.type'].create({
'name': 'Test Leave 2',
'requires_allocation': False,
})

self.env['hr.leave.allocation'].sudo().create({
'state': 'confirm',
'holiday_status_id': leave_type_1.id,
'employee_id': employee.id,
'number_of_days': 4,
'date_from': '2025-01-01',
'date_to': '2025-12-31',
}).action_approve()

result = (
self.env["hr.leave.type"]
.with_context(employee_id=employee.id)
.search([("virtual_remaining_leaves", ">", 0)])
)
self.assertIn(
leave_type_1, result, "Leave Type 1 should be in the result as it has remaining leaves",
)
self.assertIn(
leave_type_2, result, "Leave Type 2 should be in the result since it does not require allocation",
)

result = (
self.env["hr.leave.type"]
.with_context(employee_id=employee.id)
.search([("virtual_remaining_leaves", "=", 0)])
)
self.assertNotIn(
leave_type_1, result, "Leave Type 1 should not be in the result as it has remaining leaves != 0",
)
self.assertIn(
leave_type_2, result, "Leave Type 2 should be in the result since it does not require allocation",
)

result = (
self.env["hr.leave.type"]
.with_context(employee_id=employee.id)
.search([("virtual_remaining_leaves", ">", 4)])
)
self.assertNotIn(
leave_type_1, result, "Leave Type 1 should not be in the result",
)
self.assertIn(
leave_type_2, result, "Leave Type 2 should be in the result since it does not require allocation",
)
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,5 @@
</search>
</field>
</record>

</odoo>