Skip to content

Commit

Permalink
Add test for fsm_order
Browse files Browse the repository at this point in the history
  • Loading branch information
kittiu committed Jul 6, 2019
1 parent 5bdfbe7 commit de29008
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
1 change: 1 addition & 0 deletions fieldservice/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
from . import test_fsm_location
from . import test_fsm_person
from . import test_fsm_team
from . import test_fsm_order
62 changes: 62 additions & 0 deletions fieldservice/tests/test_fsm_order.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Copyright (C) 2019 - TODAY, Open Source Integrators
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from datetime import datetime, timedelta
from odoo import fields
from odoo.tests.common import TransactionCase, Form


class FSMOrder(TransactionCase):

def setUp(self):
super(FSMOrder, self).setUp()
self.Order = self.env['fsm.order']
self.test_location = self.env.ref('fieldservice.test_location')

def test_fsm_order(self):
""" Test creating new workorders, and test following functions,
- _compute_duration() in hrs
- _compute_request_late()
- Set scheduled_date_start using request_early w/o time
- scheduled_date_end = scheduled_date_start + duration (hrs)
"""
# Create an Orders
view_id = ('fieldservice.fsm_order_form')
hours_diff = 100
with Form(self.Order, view=view_id) as f:
f.location_id = self.test_location
f.date_start = fields.Datetime.today()
f.date_end = f.date_start + timedelta(hours=hours_diff)
f.request_early = fields.Datetime.today()
order = f.save()
# Test _compute_duration
self.assertEqual(order.duration, hours_diff)
# Test _compute_request_late()
priority_vs_late_days = {'0': 3, '1': 2, '2': 1, '3': 1/3}
for priority, late_days in priority_vs_late_days.items():
order.priority = priority
order.request_late = False
order._compute_request_late()
self.assertEqual(order.request_late,
order.request_early + timedelta(days=late_days))
# Test set scheduled_date_start using request_early w/o time
self.assertEqual(order.scheduled_date_start,
order.request_early.replace(minute=0, second=0))
# Test scheduled_date_end = scheduled_date_start + duration (hrs)
# Set date start
order.scheduled_date_start = \
order.scheduled_date_start.replace(hour=0, minute=0, second=0)
# Set duration
duration = 10
order.scheduled_duration = duration
# Check date end
self.assertEqual(
order.scheduled_date_end,
order.scheduled_date_start + timedelta(hours=duration))
# Set new date end
order.scheduled_date_end = \
order.scheduled_date_end.replace(hour=1, minute=1, second=1)
# Check date start
self.assertEqual(
order.scheduled_date_start,
order.scheduled_date_end - timedelta(hours=order.duration))

0 comments on commit de29008

Please sign in to comment.