testTaskReporting.py 14.5 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
from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5ReportTestCase
from Products.ERP5Type.tests.utils import reindex
import transaction
from DateTime import DateTime
34
from Products.ERP5.tests.utils import newSimulationExpectedFailure
35 36 37 38 39 40 41 42 43

class TestTaskReporting(ERP5ReportTestCase):
  """Test Task Reporting
  """
  def getTitle(self):
    return "Task Reporting"

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

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

Julien Muchembled's avatar
wip  
Julien Muchembled committed
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
  def getRule(self, **kw):
    return self.portal.portal_rules.searchFolder(
          sort_on='version', sort_order='descending', **kw)[0].getObject()

  def createBusinessProcess(self):
    module = self.portal.business_process_module
    id = self.__class__.__name__
    try:
      business_process = module[id]
    except KeyError:
      default = module.erp5_default_business_process
      business_process = module.newContent(id, default.getPortalType(),
                                           specialise_value=default)
      delivery_path, = default.getTradeModelPathValueList(
          trade_phase='default/delivery')
      business_process.newContent(portal_type=delivery_path.getPortalType(),
                                  reference=delivery_path.getReference(),
                                  trade_phase=delivery_path.getTradePhase())
    return business_process.getRelativeUrl()

78 79 80
  def afterSetUp(self):
    """Setup the fixture.
    """
Julien Muchembled's avatar
wip  
Julien Muchembled committed
81 82 83 84 85
    for rule_id in ('default_order_rule',
                    'default_delivery_rule',
                    'default_delivering_rule'):
      rule = self.getRule(reference=rule_id)
      if rule.getValidationState() != 'validated':
86 87
        rule.validate()

Julien Muchembled's avatar
wip  
Julien Muchembled committed
88 89
    self.business_process = self.createBusinessProcess()

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 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178
    # 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',
          quantity_unit='unit'
          )
    if not module.has_key('consulting'):
      product = module.newContent(
          portal_type='Product',
          id='consulting',
          title='Consulting',
          reference='ref 2',
          quantity_unit='unit'
          )

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

  def beforeTearDown(self):
    """Remove all documents.
    """
    transaction.abort()
Julien Muchembled's avatar
wip  
Julien Muchembled committed
179
    portal = self.portal
180 181 182 183 184 185 186 187 188
    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()))
    transaction.commit()
    self.tic()

189
  @newSimulationExpectedFailure
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 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 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351
  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
    report_section_list = self.getReportSectionList(
        self.portal.project_module.Project_1,
        'Project_viewMonthlyReport')
    self.assertEquals(1, len(report_section_list))

    line_list = self.getListBoxLineList(report_section_list[0])
    data_line_list = [l for l in line_list if l.isDataLine()]
    self.assertEquals(2, len(data_line_list))
    self.checkLineProperties(data_line_list[0],
                   **{'person_module/Person_1': 3.0,
                      })
    self.checkLineProperties(data_line_list[1],
                   **{'person_module/Person_1': 3.0,
                      })

    request = self.portal.REQUEST
    request.form['from_date'] = DateTime('2009/07/01')
    request.form['at_date'] = DateTime('2009/07/30')
    request.form['report_depth'] = 5
    report_section_list = self.getReportSectionList(
        self.portal.project_module.Project_1,
        'Project_viewMonthlyReport')
    self.assertEquals(1, len(report_section_list))

    # We should have this result
    # month             Person1
    # 2009-07             3
    #   Project1/Line1    3
    line_list = self.getListBoxLineList(report_section_list[0])
    data_line_list = [l for l in line_list if l.isDataLine()]
    self.assertEquals(2, len(data_line_list))
    self.checkLineProperties(data_line_list[0],
                   **{'person_module/Person_1': 3.0,
                      })
    self.checkLineProperties(data_line_list[1],
                   **{'person_module/Person_1': 3.0,
                      })
    # 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
    #   Project1/Line1    3         0
    #   Project1/Line2    0         6.5
    # 2009-08             23        6.5
    #   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')
    self.assertEquals(1, len(report_section_list))

    line_list = self.getListBoxLineList(report_section_list[0])
    data_line_list = [l for l in line_list if l.isDataLine()]
    self.assertEquals(7, len(data_line_list))
    self.checkLineProperties(data_line_list[0],
                   **{'person_module/Person_1': 3.0,
                      'person_module/Person_2': 6.5,
                      })
    self.checkLineProperties(data_line_list[1],
                   **{'person_module/Person_1': 3.0,
                      'person_module/Person_2': None,
                      })
    self.checkLineProperties(data_line_list[2],
                   **{'person_module/Person_1': None,
                      'person_module/Person_2': 6.5,
                      })
    self.checkLineProperties(data_line_list[3],
                   **{'person_module/Person_1': 23,
                      'person_module/Person_2': 6.5,
                      })
    self.checkLineProperties(data_line_list[4],
                   **{'person_module/Person_1': 11,
                      'person_module/Person_2': None,
                      })
    self.checkLineProperties(data_line_list[5],
                   **{'person_module/Person_1': 12,
                      'person_module/Person_2': 6.5,
                      })
    self.checkLineProperties(data_line_list[6],
                   **{'person_module/Person_1': None,
                      'person_module/Person_2': None,
                      })
352 353 354 355 356

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