Skip to content

Commit

Permalink
[FIX] hr_holidays_accrual_advanced: wizard crash
Browse files Browse the repository at this point in the history
  • Loading branch information
alexey-pelykh authored and OCA-git-bot committed Jul 30, 2019
1 parent 29ad35e commit 0ee5cbb
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 14 deletions.
2 changes: 1 addition & 1 deletion hr_holidays_accrual_advanced/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

{
'name': 'Advanced Accrual Allocation',
'version': '12.0.1.0.1',
'version': '12.0.1.0.2',
'category': 'Human Resources',
'website': 'https://github.com/OCA/hr',
'author':
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def setUp(self):
self.SudoCalculator = self.Calculator.sudo()
self.ResourceCalendar = self.env['resource.calendar']
self.SudoResourceCalendar = self.ResourceCalendar.sudo()
self.Calculator = self.env['hr.leave.allocation.accrual.calculator']

def test_allocation_1(self):
leave_type = self.SudoLeaveType.create({
Expand Down Expand Up @@ -750,3 +751,37 @@ def test_allocation_24(self):
lambda x: x.days_accrued,
accruements
)), 30.0)

def test_calculator(self):
leave_type = self.SudoLeaveType.create({
'name': 'Leave Type',
'allocation_type': 'fixed',
})
employee = self.SudoEmployee.create({
'name': 'Employee',
})
allocation = self.SudoLeaveAllocation.create({
'holiday_type': 'employee',
'employee_id': employee.id,
'holiday_status_id': leave_type.id,
'state': 'validate',
'accrual': True,
'date_from': (
self.now - relativedelta(years=3)
),
'date_to': (
self.now - relativedelta(years=1)
),
})

calculator = self.Calculator.with_context({
'active_id': allocation.id,
}).new()
calculator._onchange()
self.assertEqual(calculator.accrued, 0.0)
self.assertEqual(calculator.balance, 0.0)

calculator.date = self.today
calculator._onchange()
self.assertEqual(calculator.accrued, 40.0)
self.assertEqual(calculator.balance, 40.0)
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,16 @@ class HrLeaveAllocationAccrualBalanceCalculator(models.TransientModel):
'date',
)
def _onchange(self):
self._recalculate()

@api.multi
def _recalculate(self):
self.ensure_one()
CalculatorAccruement = self.env[
'hr.leave.allocation.accrual.calculator.accruement'
]
accruement_ids = CalculatorAccruement

if not self.date:
self.write({
self.update({
'accrued': 0.0,
'balance': 0.0,
'accruement_ids': [(5, False, False)],
'accruement_ids': accruement_ids,
})
return

Expand All @@ -83,16 +83,15 @@ def _recalculate(self):
)

balance = 0.0
accruement_ids = [(5, False, False)]
for accruement in accruements:
balance += accruement.days_accrued
accruement_ids.append((0, 0, {
accruement_ids |= CalculatorAccruement.new({
'days_accrued': accruement.days_accrued,
'accrued_on': accruement.accrued_on,
'reason': accruement.reason,
}))
})

self.write({
self.update({
'accrued': accrued,
'balance': balance,
'accruement_ids': accruement_ids,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,7 @@
<record id="action_hr_leave_allocation_as_of_date" model="ir.actions.act_window">
<field name="name">Accrual Balance Calculator</field>
<field name="res_model">hr.leave.allocation.accrual.calculator</field>
<field name="view_type">form</field>
<field name="view_mode">form</field>
<field name="view_id" ref="hr_leave_allocation_accrual_calculator"/>
<field name="target">new</field>
</record>

Expand Down

0 comments on commit 0ee5cbb

Please sign in to comment.