testTaskReporting.py 13.4 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
#############################################################################
#
# Copyright  2008 Nexedi SA Contributors. All Rights Reserved.
#              Sebastien Robin <seb@nexedi.com>
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsability of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# garantees and support are strongly adviced to contract a Free Software
# Service Company
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################

29
import unittest
30 31 32 33 34 35 36
from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5ReportTestCase
from Products.ERP5Type.tests.utils import reindex
from DateTime import DateTime

class TestTaskReporting(ERP5ReportTestCase):
  """Test Task Reporting
  """
37 38 39
  business_process = \
      'business_process_module/erp5_default_task_business_process'

40 41 42 43 44
  def getTitle(self):
    return "Task Reporting"

  def getBusinessTemplateList(self):
    """Returns list of BT to be installed."""
45 46
    return ('erp5_core_proxy_field_legacy',
            'erp5_base','erp5_pdm', 'erp5_simulation', 'erp5_trade',
47
            'erp5_configurator_standard_trade_template',
48
            'erp5_project', 'erp5_simulation_test')
49 50 51 52

  @reindex
  def _makeOneTask(self, simulation_state='planned', **kw):
    """Create a task, support many options"""
Julien Muchembled's avatar
Julien Muchembled committed
53 54 55
    task = self.portal.task_module.newContent(portal_type='Task',
                                              specialise=self.business_process)
    task._edit(**kw)
56 57 58 59 60 61 62 63
    if simulation_state == 'planned':
      task.plan()
    if simulation_state == 'confirmed':
      task.confirm()

  def afterSetUp(self):
    """Setup the fixture.
    """
Julien Muchembled's avatar
Julien Muchembled committed
64 65 66 67 68
    for rule_id in ('default_order_rule',
                    'default_delivery_rule',
                    'default_delivering_rule'):
      rule = self.getRule(reference=rule_id)
      if rule.getValidationState() != 'validated':
69
        rule.validate()
Julien Muchembled's avatar
wip  
Julien Muchembled committed
70

71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
    # create organisations
    if not self.portal.organisation_module.has_key('Organisation_1'):
      org = self.portal.organisation_module.newContent(
                              portal_type='Organisation',
                              reference='Organisation_1',
                              title='Organisation_1',
                              id='Organisation_1')

    if not self.portal.organisation_module.has_key('Organisation_2'):
      org = self.portal.organisation_module.newContent(
                              portal_type='Organisation',
                              reference='Organisation_2',
                              title='Organisation_2',
                              id='Organisation_2')

    # create persons
    if not self.portal.organisation_module.has_key('Person_1'):
      org = self.portal.person_module.newContent(
                              portal_type='Person',
                              reference='Person_1',
                              title='Person_1',
                              id='Person_1')
    if not self.portal.organisation_module.has_key('Person_2'):
      org = self.portal.person_module.newContent(
                              portal_type='Person',
                              reference='Person_2',
                              title='Person_2',
                              id='Person_2')

    # create project
    if not self.portal.project_module.has_key('Project_1'):
      project = self.portal.project_module.newContent(
                              portal_type='Project',
                              reference='Project_1',
                              title='Project_1',
                              start_date=DateTime('2009/01/01'),
                              stop_date=DateTime('2009/12/31'),
                              id='Project_1')
      project.newContent(portal_type='Project Line',
                         id='Line_1',
                         title='Line_1')
      project.newContent(portal_type='Project Line',
                         id='Line_2',
                         title='Line_2')
    if not self.portal.organisation_module.has_key('Project_2'):
      project = self.portal.project_module.newContent(
                              portal_type='Project',
                              reference='Project_2',
                              title='Project_2',
                              start_date=DateTime('2009/01/01'),
                              stop_date=DateTime('2009/12/31'),
                              id='Project_2')

    # create unit categories
    for unit_id in ('day', 'hour',):
      if not self.portal.portal_categories['quantity_unit'].has_key(unit_id):
        self.portal.portal_categories.quantity_unit.newContent(
                                  portal_type='Category',
                                  title=unit_id.title(),
                                  reference=unit_id,
                                  id=unit_id)

    # Create resources
    module = self.portal.product_module
    if not module.has_key('development'):
      product = module.newContent(
          portal_type='Product',
          id='development',
          title='Development',
          reference='ref 1',
141
          quantity_unit='day'
142 143 144 145 146 147 148
          )
    if not module.has_key('consulting'):
      product = module.newContent(
          portal_type='Product',
          id='consulting',
          title='Consulting',
          reference='ref 2',
149
          quantity_unit='day'
150 151 152 153 154 155 156 157
          )

    # and all this available to catalog
    self.tic()

  def beforeTearDown(self):
    """Remove all documents.
    """
158
    self.abort()
Julien Muchembled's avatar
Julien Muchembled committed
159
    portal = self.portal
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189
    portal.task_module.manage_delObjects(
                      list(portal.task_module.objectIds()))
    portal.task_report_module.manage_delObjects(
                      list(portal.task_report_module.objectIds()))
    portal.portal_simulation.manage_delObjects(
                      list(portal.portal_simulation.objectIds()))
    self.tic()

  def testProjectMontlyReport(self):
    """
    Check monthly report available on project
    """
    # Create Tasks
    self._makeOneTask(
              title='Task 1',
              task_line_quantity=3,
              resource='product_module/development',
              source='person_module/Person_1',
              source_section='organisation_module/Organisation_1',
              destination='organisation_module/Organisation_2',
              destination_section='organisation_module/Organisation_2',
              source_project='project_module/Project_1/Line_1',
              start_date=DateTime('2009/07/23'),
              stop_date=DateTime('2009/07/26'),
              )

    request = self.portal.REQUEST
    request['from_date'] = DateTime('2009/07/01')
    request['at_date'] = DateTime('2009/07/31')
    request['report_depth'] = 5
190
    self.portal.REQUEST['simulation_state'] = ['planned', 'confirmed']
191 192 193
    report_section_list = self.getReportSectionList(
        self.portal.project_module.Project_1,
        'Project_viewMonthlyReport')
194
    self.assertEquals(2, len(report_section_list))
195 196 197 198 199 200

    line_list = self.getListBoxLineList(report_section_list[0])
    data_line_list = [l for l in line_list if l.isDataLine()]
    # We should have this result
    # month             Person1
    # 2009-07             3
201
    #  Project1
202
    #   Project1/Line1    3
203
    self.assertEquals(3, len(data_line_list))
204 205 206 207
    self.checkLineProperties(data_line_list[0],
                   **{'person_module/Person_1': 3.0,
                      })
    self.checkLineProperties(data_line_list[1],
208 209 210
                   **{'person_module/Person_1': None,
                      })
    self.checkLineProperties(data_line_list[2],
211 212
                   **{'person_module/Person_1': 3.0,
                      })
213

214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269
    # Create Tasks
    self._makeOneTask(
              title='Task 2',
              task_line_quantity=5,
              resource='product_module/development',
              source='person_module/Person_1',
              source_section='organisation_module/Organisation_1',
              destination='organisation_module/Organisation_2',
              destination_section='organisation_module/Organisation_2',
              source_project='project_module/Project_1/Line_2',
              start_date=DateTime('2009/08/02'),
              stop_date=DateTime('2009/08/07'),
              )
    self._makeOneTask(
              title='Task 3',
              task_line_quantity=7,
              resource='product_module/development',
              source='person_module/Person_1',
              source_section='organisation_module/Organisation_1',
              destination='organisation_module/Organisation_2',
              destination_section='organisation_module/Organisation_2',
              source_project='project_module/Project_1/Line_2',
              start_date=DateTime('2009/08/20'),
              stop_date=DateTime('2009/08/30'),
              simulation_state='confirmed',
              )
    self._makeOneTask(
              title='Task 4',
              task_line_quantity=11,
              resource='product_module/development',
              source='person_module/Person_1',
              source_section='organisation_module/Organisation_1',
              destination='organisation_module/Organisation_2',
              destination_section='organisation_module/Organisation_2',
              source_project='project_module/Project_1/Line_1',
              start_date=DateTime('2009/08/20'),
              stop_date=DateTime('2009/08/30'),
              simulation_state='confirmed',
              )
    # And also a task splitted between two months
    self._makeOneTask(
              title='Task 5',
              task_line_quantity=13,
              resource='product_module/development',
              source='person_module/Person_2',
              source_section='organisation_module/Organisation_1',
              destination='organisation_module/Organisation_2',
              destination_section='organisation_module/Organisation_2',
              source_project='project_module/Project_1/Line_2',
              start_date=DateTime('2009/07/01'),
              stop_date=DateTime('2009/08/31'),
              )

    # We should have this result
    # month             Person1  Person2
    # 2009-07             3         6.5
270
    #  Project1
271 272 273
    #   Project1/Line1    3         0
    #   Project1/Line2    0         6.5
    # 2009-08             23        6.5
274
    #  Project1
275 276 277 278 279 280 281 282 283 284 285
    #   Project1/Line2    11        0
    #   Project1/Line2    12        6.5
    # 2009-09             0         0
    request = self.portal.REQUEST
    request['from_date'] = DateTime('2009/07/01')
    request['at_date'] = DateTime('2009/09/30')
    request['report_depth'] = 5
    request.form['month_dict'] = None
    report_section_list = self.getReportSectionList(
        self.portal.project_module.Project_1,
        'Project_viewMonthlyReport')
286
    self.assertEquals(2, len(report_section_list))
287 288 289

    line_list = self.getListBoxLineList(report_section_list[0])
    data_line_list = [l for l in line_list if l.isDataLine()]
290
    self.assertEquals(9, len(data_line_list))
291 292 293 294 295
    self.checkLineProperties(data_line_list[0],
                   **{'person_module/Person_1': 3.0,
                      'person_module/Person_2': 6.5,
                      })
    self.checkLineProperties(data_line_list[1],
296
                   **{'person_module/Person_1': None,
297 298 299
                      'person_module/Person_2': None,
                      })
    self.checkLineProperties(data_line_list[2],
300 301 302 303
                   **{'person_module/Person_1': 3.0,
                      'person_module/Person_2': None,
                      })
    self.checkLineProperties(data_line_list[3],
304 305 306
                   **{'person_module/Person_1': None,
                      'person_module/Person_2': 6.5,
                      })
307
    self.checkLineProperties(data_line_list[4],
308 309 310
                   **{'person_module/Person_1': 23,
                      'person_module/Person_2': 6.5,
                      })
311 312 313 314 315
    self.checkLineProperties(data_line_list[5],
                   **{'person_module/Person_1': None,
                      'person_module/Person_2': None,
                      })
    self.checkLineProperties(data_line_list[6],
316 317 318
                   **{'person_module/Person_1': 11,
                      'person_module/Person_2': None,
                      })
319
    self.checkLineProperties(data_line_list[7],
320 321 322
                   **{'person_module/Person_1': 12,
                      'person_module/Person_2': 6.5,
                      })
323
    self.checkLineProperties(data_line_list[8],
324 325 326
                   **{'person_module/Person_1': None,
                      'person_module/Person_2': None,
                      })
327 328 329 330 331

def test_suite():
  suite = unittest.TestSuite()
  suite.addTest(unittest.makeSuite(TestTaskReporting))
  return suite