Skip to content

Commit

Permalink
Merge pull request #1 from sunflowerit/8.0-hr_timesheet_holiday-creat…
Browse files Browse the repository at this point in the history
…e_holiday_request-fixes

8.0 hr timesheet holiday create holiday request fixes
  • Loading branch information
hbrunn committed May 17, 2018
2 parents 425613e + 7fc3a04 commit dfea68a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
2 changes: 1 addition & 1 deletion hr_timesheet_holiday/models/hr_timesheet_sheet.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def _timesheet_approved(self):
holiday2hours[holiday] += line.unit_amount
for holiday, hours in holiday2hours.iteritems():
request = self.env['hr.holidays'].sudo(this.user_id).create({
'name': '%s: %s' % (this.name, holiday.name),
'name': '%s: %s' % (this.display_name, holiday.name),
'user_id': this.user_id.id,
'date_from': this.date_from,
'date_to': this.date_to,
Expand Down
31 changes: 27 additions & 4 deletions hr_timesheet_holiday/tests/test_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
# © 2016 Sunflower IT (http://sunflowerweb.nl)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
import time
from openerp.tools import float_round
from openerp.tests.common import TransactionCase
from openerp.exceptions import ValidationError

Expand Down Expand Up @@ -67,6 +66,8 @@ def test_analytic(self):
manager = self.env.ref('hr.employee_fp')
employee = self.env.ref('hr.employee_qdp')
employee.write(employee.default_get(['product_id', 'journal_id']))

# create timesheet line with 6.0 hours of sick leave
line = self.env['hr.analytic.timesheet'].sudo(
employee.user_id,
).default_get([
Expand All @@ -82,6 +83,8 @@ def test_analytic(self):
name='/',
unit_amount=6,
)

# create and confirm a timesheet with the 6.0 hours line
sheet = self.env['hr_timesheet_sheet.sheet'].sudo(
employee.user_id
).create({
Expand All @@ -91,14 +94,34 @@ def test_analytic(self):
'timesheet_ids': [(0, 0, line)],
})
sheet.signal_workflow('confirm')
self.assertEqual(sheet.state, 'confirm')

# fully approve timesheet
leaves_taken_before = self.account.holiday_status_ids.sudo(
employee.user_id
).leaves_taken
sheet.sudo(manager.user_id).signal_workflow('done')
self.assertEqual(sheet.state, 'done')

# assert that total leave has increases
leaves_taken_after = self.account.holiday_status_ids.sudo(
employee.user_id
).leaves_taken
self.assertEqual(
float_round(leaves_taken_before + 6.0 / 7.0, 2),
float_round(leaves_taken_after, 2),
self.assertAlmostEqual(
leaves_taken_before + 6.0 / 7.0,
leaves_taken_after,
2
)

# resubmit timesheet with 8.0 hours of leave
# sheet.create_workflow()
# self.assertEquals(sheet.state, 'draft')
# sheet.timesheet_ids.write(dict(unit_amount=8))
# sheet.signal_workflow('confirm')
# sheet.signal_workflow('done')
# self.assertEqual(sheet.state, 'done')
# self.assertAlmostEqual(
# leaves_taken_before + 8.0 / 7.0,
# leaves_taken_after,
# 2
# )

0 comments on commit dfea68a

Please sign in to comment.