testTradeReports.py 49.7 KB
Newer Older
Romain Courteaud's avatar
Romain Courteaud committed
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 29 30 31
#############################################################################
#
# Copyright  2008 Nexedi SA Contributors. All Rights Reserved.
#              Romain Courteaud <romain@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.
#
##############################################################################

"""Tests Standards ERP5 Trade Reports
"""
import unittest
32
from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5ReportTestCase
Romain Courteaud's avatar
Romain Courteaud committed
33 34 35 36
from Products.ERP5Type.tests.utils import reindex
from AccessControl.SecurityManagement import newSecurityManager
from DateTime import DateTime

37
class TestTradeReports(ERP5ReportTestCase):
Romain Courteaud's avatar
Romain Courteaud committed
38 39 40 41 42 43 44
  """Test Trade reports
  """
  def getTitle(self):
    return "Trade Reports"

  def getBusinessTemplateList(self):
    """Returns list of BT to be installed."""
45
    return ('erp5_core_proxy_field_legacy',
46
            'erp5_base', 'erp5_pdm', 'erp5_trade', 'erp5_pdm', )
Romain Courteaud's avatar
Romain Courteaud committed
47 48 49 50 51 52 53 54 55

  def login(self):
    """login with Manager roles."""
    uf = self.getPortal().acl_users
    uf._doAddUser('manager', 'manager', ['Manager', 'Assignee', 'Assignor',
                               'Associate', 'Auditor', 'Author'], [])
    user = uf.getUserById('manager').__of__(uf)
    newSecurityManager(None, user)

56 57 58 59 60 61 62
  def loginAsUser(self):
    """login as user, without Manager role"""
    uf = self.getPortal().acl_users
    uf._doAddUser('user', 'user', ['Assignee', 'Assignor',
                               'Associate', 'Auditor', 'Author'], [])
    user = uf.getUserById('manager').__of__(uf)
    newSecurityManager(None, user)
Aurel's avatar
Aurel committed
63 64

  def afterSetUp(self):
Romain Courteaud's avatar
Romain Courteaud committed
65 66 67 68 69
    """Setup the fixture.
    """
    self.portal = self.getPortal()
    self.organisation_module = self.portal.organisation_module
    self.inventory_module = self.portal.inventory_module
Aurel's avatar
Aurel committed
70
    self.sale_order_module = self.portal.sale_order_module
Romain Courteaud's avatar
Romain Courteaud committed
71 72
    self.product_module = self.portal.product_module
    self.portal_categories = self.portal.portal_categories
73

Romain Courteaud's avatar
Romain Courteaud committed
74 75
    # Create site category
    for site_id in ('demo_site_A', 'demo_site_B',):
76
      if not self.portal_categories['site'].has_key(site_id):
Romain Courteaud's avatar
Romain Courteaud committed
77 78 79 80 81 82 83
        self.portal_categories.site.newContent(
                                  portal_type='Category',
                                  title=site_id,
                                  reference=site_id,
                                  id=site_id)
    # Colour categories
    for colour_id in ('colour1', 'colour2',):
84
      if not self.portal_categories['colour'].has_key(colour_id):
Romain Courteaud's avatar
Romain Courteaud committed
85 86 87 88 89 90
        self.portal_categories.colour.newContent(
                                  portal_type='Category',
                                  title=colour_id,
                                  reference=colour_id,
                                  id=colour_id)

Aurel's avatar
Aurel committed
91
    # create group categories
92
    for group_id in ('g1', 'g2', 'g3'):
Aurel's avatar
Aurel committed
93 94 95 96 97 98
      if not self.portal_categories['group'].has_key(group_id):
        self.portal_categories.group.newContent(
                                  portal_type='Category',
                                  title=group_id,
                                  reference=group_id,
                                  id=group_id)
99
    # create organisations (with no organisation member of g3)
100
    if not self.organisation_module.has_key('Organisation_1'):
Romain Courteaud's avatar
Romain Courteaud committed
101 102 103 104 105
      org = self.portal.organisation_module.newContent(
                              portal_type='Organisation',
                              reference='Organisation_1',
                              title='Organisation_1',
                              id='Organisation_1',
Aurel's avatar
Aurel committed
106
                              group='g1',
Romain Courteaud's avatar
Romain Courteaud committed
107
                              site='demo_site_A')
108
    if not self.organisation_module.has_key('Organisation_2'):
Romain Courteaud's avatar
Romain Courteaud committed
109 110 111 112 113
      org = self.portal.organisation_module.newContent(
                              portal_type='Organisation',
                              reference='Organisation_2',
                              title='Organisation_2',
                              id='Organisation_2',
Aurel's avatar
Aurel committed
114
                              group='g2',
Romain Courteaud's avatar
Romain Courteaud committed
115
                              site='demo_site_B')
116 117 118 119 120 121 122
    # no group no site
    if not self.organisation_module.has_key('Organisation_3'):
      org = self.portal.organisation_module.newContent(
                              portal_type='Organisation',
                              reference='Organisation_3',
                              title='Organisation_3',
                              id='Organisation_3',)
123

Aurel's avatar
Aurel committed
124 125
    # create unit categories
    for unit_id in ('kg', 'g',):
126
      if not self.portal_categories['quantity_unit'].has_key(unit_id):
Aurel's avatar
Aurel committed
127 128
        self.portal_categories.quantity_unit.newContent(
                                  portal_type='Category',
Aurel's avatar
Aurel committed
129
                                  title=unit_id.title(),
Aurel's avatar
Aurel committed
130 131
                                  reference=unit_id,
                                  id=unit_id)
132

133
    # Create resources
Romain Courteaud's avatar
Romain Courteaud committed
134
    module = self.portal.product_module
135
    if not module.has_key('product_B'):
Romain Courteaud's avatar
Romain Courteaud committed
136 137 138 139 140
      product = module.newContent(
          portal_type='Product',
          id='product_B',
          title='product_B',
          reference='ref 1',
Aurel's avatar
Aurel committed
141
          quantity_unit='kg'
Romain Courteaud's avatar
Romain Courteaud committed
142
          )
143
    if not module.has_key('product_A'):
Romain Courteaud's avatar
Romain Courteaud committed
144 145 146 147 148
      product = module.newContent(
          portal_type='Product',
          id='product_A',
          title='product_A',
          reference='ref 2',
Aurel's avatar
Aurel committed
149
          quantity_unit='g'
Romain Courteaud's avatar
Romain Courteaud committed
150
          )
151
    if not module.has_key('product_C'):
Romain Courteaud's avatar
Romain Courteaud committed
152 153 154 155 156 157 158 159
      product = module.newContent(
          portal_type='Product',
          id='product_C',
          title='variated product',
          reference='ref 3',
          variation_base_category_list=['colour'],
          colour_list=['colour1', 'colour2'],
          )
160 161 162 163 164 165 166 167
    if not self.portal.service_module.has_key('service_a'):
      self.portal.service_module.newContent(
          portal_type='Service',
          id='service_a',
          title='Service A',
          reference='ref sA',
          )

Romain Courteaud's avatar
Romain Courteaud committed
168 169
    # and all this available to catalog
    self.tic()
170
    self.loginAsUser()
Romain Courteaud's avatar
Romain Courteaud committed
171

Aurel's avatar
Aurel committed
172
  def beforeTearDown(self):
Romain Courteaud's avatar
Romain Courteaud committed
173 174
    """Remove all documents.
    """
175
    self.abort()
Romain Courteaud's avatar
Romain Courteaud committed
176 177 178 179 180 181 182 183 184 185 186

    self.organisation_module.manage_delObjects(
                      list(self.organisation_module.objectIds()))
    self.product_module.manage_delObjects(
                      list(self.product_module.objectIds()))
    self.portal_categories.site.manage_delObjects(
        [x for x in self.portal_categories['site'].objectIds()])
    self.portal_categories.colour.manage_delObjects(
        [x for x in self.portal_categories['colour'].objectIds()])
    self.inventory_module.manage_delObjects(
                      list(self.inventory_module.objectIds()))
187 188
    self.sale_order_module.manage_delObjects(
                      list(self.sale_order_module.objectIds()))
189

Romain Courteaud's avatar
Romain Courteaud committed
190 191
    self.tic()

192 193
  @reindex
  def _makeOneInventory(self, simulation_state='draft',
Romain Courteaud's avatar
Romain Courteaud committed
194 195 196 197 198 199 200 201 202 203
                        resource=None, quantity=None, **kw):
    """Creates an inventory.
    """
    inventory = self.inventory_module.newContent(portal_type='Inventory', **kw)
    inventory_line = inventory.newContent(portal_type='Inventory Line',
                                          resource=resource,
                                          inventory=quantity)

    if simulation_state == 'delivered':
      inventory.deliver()
204

Romain Courteaud's avatar
Romain Courteaud committed
205
    # sanity check
206
    self.assertEqual(simulation_state, inventory.getSimulationState())
Romain Courteaud's avatar
Romain Courteaud committed
207 208
    return inventory

Aurel's avatar
Aurel committed
209 210 211 212 213 214 215 216 217 218 219
  @reindex
  def _makeOneSaleOrder(self, resource_dict={}, cancel=False, **kw):
    """
    Create a sale order
    """
    sale_order = self.sale_order_module.newContent(portal_type="Sale Order", **kw)
    for product, values in resource_dict.iteritems():
      sale_order_line = sale_order.newContent(portal_type="Sale Order Line",
                                              resource=product,
                                              quantity=values["quantity"],
                                              price=values["price"])
220

221
    self.assertEqual(sale_order.getSimulationState(), 'draft')
Aurel's avatar
Aurel committed
222 223
    if cancel:
      sale_order.cancel()
224
      self.assertEqual(sale_order.getSimulationState(), 'cancelled')
225

Aurel's avatar
Aurel committed
226
    return sale_order
227

Aurel's avatar
Aurel committed
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
  def testSaleOrderReport(self):
    """
    Sale order report.
    """
    # Create sales orders
    first = self._makeOneSaleOrder(
              title='SO 1',
              destination_value=self.organisation_module.Organisation_1,
              destination_section_value=self.organisation_module.Organisation_1,
              destination_decision_value=self.organisation_module.Organisation_1,
              source_value=self.organisation_module.Organisation_2,
              source_section_value=self.organisation_module.Organisation_2,
              source_decision_value=self.organisation_module.Organisation_2,
              start_date=DateTime(2006, 2, 2),
              resource_dict = {'product_module/product_A':{"quantity":11, "price":3},
                               'product_module/product_B':{"quantity":7, "price":6},}
              )
    second = self._makeOneSaleOrder(
              title='SO 2',
              destination_value=self.organisation_module.Organisation_1,
              destination_section_value=self.organisation_module.Organisation_1,
              destination_decision_value=self.organisation_module.Organisation_1,
              source_value=self.organisation_module.Organisation_2,
              source_section_value=self.organisation_module.Organisation_2,
              source_decision_value=self.organisation_module.Organisation_2,
              start_date=DateTime(2007, 2, 2),
              resource_dict = {'product_module/product_A':{"quantity":3, "price":3},}
              )
    third = self._makeOneSaleOrder(
              title='SO 3',
              destination_value=self.organisation_module.Organisation_2,
              destination_section_value=self.organisation_module.Organisation_2,
              destination_decision_value=self.organisation_module.Organisation_2,
              source_value=self.organisation_module.Organisation_1,
              source_section_value=self.organisation_module.Organisation_1,
              source_decision_value=self.organisation_module.Organisation_1,
264
              start_date=DateTime(2006, 2, 22),
Aurel's avatar
Aurel committed
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
              resource_dict = {'product_module/product_A':{"quantity":5, "price":3},
                               'product_module/product_B':{"quantity":1, "price":6},}
              )
    fourth = self._makeOneSaleOrder(
              title='SO 4',
              destination_value=self.organisation_module.Organisation_1,
              destination_section_value=self.organisation_module.Organisation_1,
              destination_decision_value=self.organisation_module.Organisation_1,
              source_value=self.organisation_module.Organisation_2,
              source_section_value=self.organisation_module.Organisation_2,
              source_decision_value=self.organisation_module.Organisation_2,
              start_date=DateTime(2007, 2, 2),
              resource_dict = {'product_module/product_A':{"quantity":17, "price":3},
                               'product_module/product_B':{"quantity":13, "price":6},},
              cancel=True
              )

    self.tic()


    request = self.portal.REQUEST
    #
    # Before 2006
    #
    request['from_date'] = DateTime(2004, 1, 1)
    request['at_date'] = DateTime(2005, 1, 1)
    request['aggregation_level'] = "year"
    request['group_by'] = "both"
    request['simulation_state'] = ['cancelled', 'draft']
294 295 296 297 298 299
    request['section_category'] = 'group/g2'

    parameter_dict, stat_columns, selection_columns = self.sale_order_module.OrderModule_getOrderReportParameterDict()
    active_process = self.sale_order_module.OrderModule_activateGetOrderStatList(tag="unit_test", **parameter_dict)
    request['active_process'] = active_process.getPath()
    self.tic()
Aurel's avatar
Aurel committed
300 301
    report_section_list = self.getReportSectionList(self.sale_order_module,
                                                    'OrderModule_viewOrderReport')
302
    self.assertEqual(1, len(report_section_list))
Aurel's avatar
Aurel committed
303 304 305

    line_list = self.getListBoxLineList(report_section_list[0])
    data_line_list = [l for l in line_list if l.isDataLine()]
306
    self.assertEqual(0, len(data_line_list))
Aurel's avatar
Aurel committed
307 308

    #
309
    # Year 2005 + 2006, first document for g2
Aurel's avatar
Aurel committed
310 311 312
    #
    request['from_date'] = DateTime(2005, 2, 2)
    request['at_date'] = DateTime("2006-12-31")
313 314 315 316
    parameter_dict, stat_columns, selection_columns = self.sale_order_module.OrderModule_getOrderReportParameterDict()
    active_process = self.sale_order_module.OrderModule_activateGetOrderStatList(tag="unit_test", **parameter_dict)
    request['active_process'] = active_process.getPath()
    self.tic()
Aurel's avatar
Aurel committed
317 318 319

    report_section_list = self.getReportSectionList(self.sale_order_module,
                                                    'OrderModule_viewOrderReport')
320
    self.assertEqual(1, len(report_section_list))
Aurel's avatar
Aurel committed
321 322 323 324

    line_list = self.getListBoxLineList(report_section_list[0])
    data_line_list = [l for l in line_list if l.isDataLine()]
    stat_line_list = [l for l in line_list if l.isStatLine()]
325
    self.assertEqual(3, len(data_line_list))
326
    self.assertEqual(1, len(stat_line_list))
Aurel's avatar
Aurel committed
327 328 329

    # test columns values
    line = data_line_list[0]
330
    self.assertEqual(line.column_id_list, ['client',
Aurel's avatar
Aurel committed
331 332 333 334 335 336 337 338 339
                    'product',
                    'Amount 2005',
                    'Quantity 2005',
                    'Quantity Unit 2005',
                    'Amount 2006',
                    'Quantity 2006',
                    'Quantity Unit 2006',
                    'total amount',
                    'total quantity'])
340

Aurel's avatar
Aurel committed
341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359
    # First Organisation
    d =  {'Amount 2005': 0,
                 'Amount 2006': 75.0,
                 'Quantity 2005': None,
                 'Quantity 2006': None,
                 'Quantity Unit 2005': None,
                 'Quantity Unit 2006': None,
                 'client': 'Organisation_1',
                 'product': None,
                 'total amount': 75.0,
                 'total quantity': None}
    self.checkLineProperties(data_line_list[0],**d)

    # Product one for first organisation
    d={'Amount 2005': 0,
                 'Amount 2006': 33.0,
                 'Quantity 2005': 0,
                 'Quantity 2006': 11.0,
                 'Quantity Unit 2005': '',
Aurel's avatar
Aurel committed
360
                 'Quantity Unit 2006': 'G',
Aurel's avatar
Aurel committed
361 362 363 364 365
                 'client': None,
                 'product': 'product_A',
                 'total amount': 33.0,
                 'total quantity': 11.0}
    self.checkLineProperties(data_line_list[1],**d)
366

Aurel's avatar
Aurel committed
367 368 369 370 371 372
    # Product two for first organisation
    d = {'Amount 2005': 0,
                 'Amount 2006': 42.0,
                 'Quantity 2005': 0,
                 'Quantity 2006': 7.0,
                 'Quantity Unit 2005': '',
Aurel's avatar
Aurel committed
373
                 'Quantity Unit 2006': 'Kg',
Aurel's avatar
Aurel committed
374 375 376 377 378
                 'client': None,
                 'product': 'product_B',
                 'total amount': 42.0,
                 'total quantity': 7.0}
    self.checkLineProperties(data_line_list[2],**d)
379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411
    # stat line
    d = {'Amount 2005': None,
                 'Amount 2006': 75.0,
                 'Quantity 2005': None,
                 'Quantity 2006': None,
                 'Quantity Unit 2005': None,
                 'Quantity Unit 2006': None,
                 'client': 'Total',
                 'product': None,
                 'total amount': 75.0,
                 'total quantity': None}
    self.checkLineProperties(stat_line_list[0],**d)

    #
    # Year 2005 + 2006, first document for g1
    #
    request['from_date'] = DateTime(2005, 2, 2)
    request['at_date'] = DateTime("2006-12-31")
    request['section_category'] = 'group/g1'
    parameter_dict, stat_columns, selection_columns = self.sale_order_module.OrderModule_getOrderReportParameterDict()
    active_process = self.sale_order_module.OrderModule_activateGetOrderStatList(tag="unit_test", **parameter_dict)
    request['active_process'] = active_process.getPath()
    self.tic()

    report_section_list = self.getReportSectionList(self.sale_order_module,
                                                    'OrderModule_viewOrderReport')
    self.assertEqual(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()]
    stat_line_list = [l for l in line_list if l.isStatLine()]
    self.assertEqual(3, len(data_line_list))
    self.assertEqual(1, len(stat_line_list))
412

Aurel's avatar
Aurel committed
413 414 415 416 417 418 419 420 421 422 423
    # Second organisation
    d = {'Amount 2005': 0,
                 'Amount 2006': 21.0,
                 'Quantity 2005': None,
                 'Quantity 2006': None,
                 'Quantity Unit 2005': None,
                 'Quantity Unit 2006': None,
                 'client': 'Organisation_2',
                 'product': None,
                 'total amount': 21.0,
                 'total quantity': None}
424
    self.checkLineProperties(data_line_list[0],**d)
425

Aurel's avatar
Aurel committed
426 427 428 429 430 431
    # Product one for second organisation
    d = {'Amount 2005': 0,
                 'Amount 2006': 15.0,
                 'Quantity 2005': 0,
                 'Quantity 2006': 5.0,
                 'Quantity Unit 2005': '',
Aurel's avatar
Aurel committed
432
                 'Quantity Unit 2006': 'G',
Aurel's avatar
Aurel committed
433 434 435 436
                 'client': None,
                 'product': 'product_A',
                 'total amount': 15.0,
                 'total quantity': 5.0}
437
    self.checkLineProperties(data_line_list[1],**d)
438

Aurel's avatar
Aurel committed
439 440 441 442 443 444
    # Product two for second organisation
    d = {'Amount 2005': 0,
                 'Amount 2006': 6.0,
                 'Quantity 2005': 0,
                 'Quantity 2006': 1.0,
                 'Quantity Unit 2005': '',
Aurel's avatar
Aurel committed
445
                 'Quantity Unit 2006': 'Kg',
Aurel's avatar
Aurel committed
446 447 448 449
                 'client': None,
                 'product': 'product_B',
                 'total amount': 6.0,
                 'total quantity': 1.0}
450
    self.checkLineProperties(data_line_list[2],**d)
451

Aurel's avatar
Aurel committed
452 453
    # stat line
    d = {'Amount 2005': None,
454
                 'Amount 2006': 21.0,
Aurel's avatar
Aurel committed
455 456 457 458 459 460
                 'Quantity 2005': None,
                 'Quantity 2006': None,
                 'Quantity Unit 2005': None,
                 'Quantity Unit 2006': None,
                 'client': 'Total',
                 'product': None,
461
                 'total amount': 21.0,
Aurel's avatar
Aurel committed
462 463
                 'total quantity': None}
    self.checkLineProperties(stat_line_list[0],**d)
464 465


Aurel's avatar
Aurel committed
466 467 468 469 470 471
    #
    # Year 2006 + 2007, only draft documents and one group
    #
    request['from_date'] = DateTime(2006, 2, 2)
    request['at_date'] = DateTime(2007, 12, 31)
    request['simulation_state'] = ['draft',]
472
    request['section_category'] = 'group/g2'
473 474 475 476
    parameter_dict, stat_columns, selection_columns = self.sale_order_module.OrderModule_getOrderReportParameterDict()
    active_process = self.sale_order_module.OrderModule_activateGetOrderStatList(tag="unit_test", **parameter_dict)
    request['active_process'] = active_process.getPath()
    self.tic()
Aurel's avatar
Aurel committed
477 478
    report_section_list = self.getReportSectionList(self.sale_order_module,
                                                    'OrderModule_viewOrderReport')
479
    self.assertEqual(1, len(report_section_list))
Aurel's avatar
Aurel committed
480 481 482 483

    line_list = self.getListBoxLineList(report_section_list[0])
    data_line_list = [l for l in line_list if l.isDataLine()]
    stat_line_list = [l for l in line_list if l.isStatLine()]
484 485
    self.assertEqual(3, len(data_line_list))
    self.assertEqual(1, len(stat_line_list))
486
    # First organisation
Aurel's avatar
Aurel committed
487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502
    d = {'Amount 2006': 75.0,
                 'Amount 2007': 9.0,
                 'Quantity 2006': None,
                 'Quantity 2007': None,
                 'Quantity Unit 2006': None,
                 'Quantity Unit 2007': None,
                 'client': 'Organisation_1',
                 'product': None,
                 'total amount': 84.0,
                 'total quantity': None}
    self.checkLineProperties(data_line_list[0],**d)
    # Product one for organisation
    d = {'Amount 2006': 33.0,
                 'Amount 2007': 9.0,
                 'Quantity 2006': 11.0,
                 'Quantity 2007': 3.0,
Aurel's avatar
Aurel committed
503 504
                 'Quantity Unit 2006': 'G',
                 'Quantity Unit 2007': 'G',
Aurel's avatar
Aurel committed
505 506 507 508 509 510 511 512 513 514
                 'client': None,
                 'product': 'product_A',
                 'total amount': 42.0,
                 'total quantity': 14.0}
    # Product two for organisation
    self.checkLineProperties(data_line_list[1],**d)
    d = {'Amount 2006': 42.0,
                 'Amount 2007': 0,
                 'Quantity 2006': 7.0,
                 'Quantity 2007': 0,
Aurel's avatar
Aurel committed
515
                 'Quantity Unit 2006': 'Kg',
Aurel's avatar
Aurel committed
516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533
                 'Quantity Unit 2007': '',
                 'client': None,
                 'product': 'product_B',
                 'total amount': 42.0,
                 'total quantity': 7.0}
    self.checkLineProperties(data_line_list[2],**d)
    # stat line
    d = {'Amount 2006': 75.0,
                 'Amount 2007': 9.0,
                 'Quantity 2006': None,
                 'Quantity 2007': None,
                 'Quantity Unit 2006': None,
                 'Quantity Unit 2007': None,
                 'client': 'Total',
                 'product': None,
                 'total amount': 84.0,
                 'total quantity': None}
    self.checkLineProperties(stat_line_list[0],**d)
534

535
    # weekly aggregation level
536
    # first for g2
537 538 539 540 541
    request['from_date'] = DateTime(2006, 2, 1)
    request['at_date'] = DateTime(2006, 2, 28)
    request['aggregation_level'] = "week"
    request['group_by'] = "client"
    request['simulation_state'] = ['cancelled', 'draft']
542 543 544 545
    parameter_dict, stat_columns, selection_columns = self.sale_order_module.OrderModule_getOrderReportParameterDict()
    active_process = self.sale_order_module.OrderModule_activateGetOrderStatList(tag="unit_test", **parameter_dict)
    request['active_process'] = active_process.getPath()
    self.tic()
546 547
    report_section_list = self.getReportSectionList(self.sale_order_module,
                                                    'OrderModule_viewOrderReport')
548
    self.assertEqual(1, len(report_section_list))
549 550
    line_list = self.getListBoxLineList(report_section_list[0])
    data_line_list = [l for l in line_list if l.isDataLine()]
551
    self.assertEqual(1, len(data_line_list))
552 553 554 555 556 557 558 559 560

    self.checkLineProperties(data_line_list[0],
                   **{'Amount 2006-05': 11*3 + 7*6,
                      'Amount 2006-06': 0,
                      'Amount 2006-07': 0,
                      'Amount 2006-08': 0,
                      'Amount 2006-09': 0,
                      'client': 'Organisation_1',
                      'total amount': 3*11 + 7*6})
561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590
    self.assertTrue(line_list[-1].isStatLine())
    self.checkLineProperties(line_list[-1],
                   **{'Amount 2006-05': 11*3 + 7*6,
                      'Amount 2006-06': None,
                      'Amount 2006-07': None,
                      'Amount 2006-08': None,
                      'Amount 2006-09': None,
                      'client': 'Total',
                      'total amount': 3*11 + 7*6})

    # weekly aggregation level
    # first for g2
    request['from_date'] = DateTime(2006, 2, 1)
    request['at_date'] = DateTime(2006, 2, 28)
    request['aggregation_level'] = "week"
    request['group_by'] = "client"
    request['simulation_state'] = ['cancelled', 'draft']
    request['section_category'] = 'group/g1'
    parameter_dict, stat_columns, selection_columns = self.sale_order_module.OrderModule_getOrderReportParameterDict()
    active_process = self.sale_order_module.OrderModule_activateGetOrderStatList(tag="unit_test", **parameter_dict)
    request['active_process'] = active_process.getPath()
    self.tic()
    report_section_list = self.getReportSectionList(self.sale_order_module,
                                                    'OrderModule_viewOrderReport')
    self.assertEqual(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.assertEqual(1, len(data_line_list))

    self.checkLineProperties(data_line_list[0],
591 592 593 594 595 596 597 598
                   **{'Amount 2006-05': 0,
                      'Amount 2006-06': 0,
                      'Amount 2006-07': 0,
                      'Amount 2006-08': 5*3 + 6,
                      'Amount 2006-09': 0,
                      'client': 'Organisation_2',
                      'total amount': 5*3 + 6})

599
    self.assertTrue(line_list[-1].isStatLine())
600
    self.checkLineProperties(line_list[-1],
601
                   **{'Amount 2006-05': None,
602 603 604 605 606
                      'Amount 2006-06': None,
                      'Amount 2006-07': None,
                      'Amount 2006-08': 5*3 + 6,
                      'Amount 2006-09': None,
                      'client': 'Total',
607 608 609
                      'total amount': 5*3 + 6})


610

Aurel's avatar
Aurel committed
611

612 613 614 615 616 617
    # dates not specified -> they should be guessed
    request['from_date'] = None
    request['at_date'] = None
    request['simulation_state'] = ['draft',]
    request['aggregation_level'] = "year"
    request['group_by'] = "both"
618
    request['section_category'] = 'group/g2'
619 620 621 622
    parameter_dict, stat_columns, selection_columns = self.sale_order_module.OrderModule_getOrderReportParameterDict()
    active_process = self.sale_order_module.OrderModule_activateGetOrderStatList(tag="unit_test", **parameter_dict)
    request['active_process'] = active_process.getPath()
    self.tic()
623 624
    report_section_list = self.getReportSectionList(self.sale_order_module,
                                                    'OrderModule_viewOrderReport')
625
    self.assertEqual(1, len(report_section_list))
626 627 628 629

    line_list = self.getListBoxLineList(report_section_list[0])
    data_line_list = [l for l in line_list if l.isDataLine()]
    stat_line_list = [l for l in line_list if l.isStatLine()]
630 631
    self.assertEqual(3, len(data_line_list))
    self.assertEqual(1, len(stat_line_list))
632
    # First organisation
633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679
    d = {'Amount 2006': 75.0,
                 'Amount 2007': 9.0,
                 'Quantity 2006': None,
                 'Quantity 2007': None,
                 'Quantity Unit 2006': None,
                 'Quantity Unit 2007': None,
                 'client': 'Organisation_1',
                 'product': None,
                 'total amount': 84.0,
                 'total quantity': None}
    self.checkLineProperties(data_line_list[0],**d)
    # Product one for organisation
    d = {'Amount 2006': 33.0,
                 'Amount 2007': 9.0,
                 'Quantity 2006': 11.0,
                 'Quantity 2007': 3.0,
                 'Quantity Unit 2006': 'G',
                 'Quantity Unit 2007': 'G',
                 'client': None,
                 'product': 'product_A',
                 'total amount': 42.0,
                 'total quantity': 14.0}
    # Product two for organisation
    self.checkLineProperties(data_line_list[1],**d)
    d = {'Amount 2006': 42.0,
                 'Amount 2007': 0,
                 'Quantity 2006': 7.0,
                 'Quantity 2007': 0,
                 'Quantity Unit 2006': 'Kg',
                 'Quantity Unit 2007': '',
                 'client': None,
                 'product': 'product_B',
                 'total amount': 42.0,
                 'total quantity': 7.0}
    self.checkLineProperties(data_line_list[2],**d)
    # stat line
    d = {'Amount 2006': 75.0,
                 'Amount 2007': 9.0,
                 'Quantity 2006': None,
                 'Quantity 2007': None,
                 'Quantity Unit 2006': None,
                 'Quantity Unit 2007': None,
                 'client': 'Total',
                 'product': None,
                 'total amount': 84.0,
                 'total quantity': None}
    self.checkLineProperties(stat_line_list[0],**d)
680

681
    # section category set, with no matching organisations
682 683 684
    request['simulation_state'] = ['draft',]
    request['aggregation_level'] = "year"
    request['group_by'] = "both"
685
    request['section_category'] = 'group/g3'
686 687 688 689
    parameter_dict, stat_columns, selection_columns = self.sale_order_module.OrderModule_getOrderReportParameterDict()
    active_process = self.sale_order_module.OrderModule_activateGetOrderStatList(tag="unit_test", **parameter_dict)
    request['active_process'] = active_process.getPath()
    self.tic()
690 691
    report_section_list = self.getReportSectionList(self.sale_order_module,
                                                    'OrderModule_viewOrderReport')
692
    self.assertEqual(1, len(report_section_list))
693 694 695 696

    line_list = self.getListBoxLineList(report_section_list[0])
    data_line_list = [l for l in line_list if l.isDataLine()]
    stat_line_list = [l for l in line_list if l.isStatLine()]
697 698
    self.assertEqual(0, len(data_line_list))
    self.assertEqual(1, len(stat_line_list))
699 700 701 702 703 704 705 706 707 708 709 710
    # stat line
    d = {'Amount 2006': None,
                 'Amount 2007': None,
                 'Quantity 2006': None,
                 'Quantity 2007': None,
                 'Quantity Unit 2006': None,
                 'Quantity Unit 2007': None,
                 'client': 'Total',
                 'product': None,
                 'total amount': None,
                 'total quantity': None}
    self.checkLineProperties(stat_line_list[0],**d)
711

Romain Courteaud's avatar
Romain Courteaud committed
712 713 714 715 716 717 718 719 720
  def testStockReport(self):
    """
    Stock report.
    """
    # Create inventories
    first = self._makeOneInventory(
              title='Inventory 1',
              simulation_state='delivered',
              destination_value=self.organisation_module.Organisation_1,
721
              source_value=self.organisation_module.Organisation_3,
Romain Courteaud's avatar
Romain Courteaud committed
722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768
              start_date=DateTime(2006, 2, 2),
              resource='product_module/product_A',
              quantity=11,
              )

    second = self._makeOneInventory(
              title='Inventory 2',
              simulation_state='delivered',
              destination_value=self.organisation_module.Organisation_1,
              start_date=DateTime(2007, 2, 2),
              resource='product_module/product_A',
              quantity=22,
              )

    third = self._makeOneInventory(
              title='Inventory 3',
              simulation_state='delivered',
              destination_value=self.organisation_module.Organisation_1,
              start_date=DateTime(2007, 2, 2),
              resource='product_module/product_B',
              quantity=33,
              )

    fourth = self._makeOneInventory(
              title='Inventory 4',
              simulation_state='delivered',
              destination_value=self.organisation_module.Organisation_2,
              start_date=DateTime(2007, 2, 2),
              resource='product_module/product_B',
              quantity=44,
              )

    fifth = self._makeOneInventory(
              title='Inventory 5',
              destination_value=self.organisation_module.Organisation_1,
              start_date=DateTime(2007, 2, 2),
              resource='product_module/product_C',
              quantity=55,
              )
    fifth_line = fifth.contentValues(portal_type='Inventory Line')[0]
    fifth_line.edit(
        variation_category_list=['colour/colour1', 'colour/colour2'],
        )
    base_id = 'movement'
    cell_key_list = list(fifth_line.getCellKeyList(base_id=base_id))
    for cell_key in cell_key_list:
      cell = fifth_line.newCell(base_id=base_id,
769
                                portal_type='Inventory Cell',
Romain Courteaud's avatar
Romain Courteaud committed
770 771 772 773 774 775 776
                                *cell_key)
      cell.edit(mapped_value_property_list=['inventory'],
                inventory=66,
                predicate_category_list=cell_key,
                variation_category_list=cell_key)
    fifth.deliver()

777 778 779 780 781 782 783 784 785 786
    # services are ignored
    self._makeOneInventory(
              title='Inventory 6',
              simulation_state='delivered',
              destination_value=self.organisation_module.Organisation_1,
              start_date=DateTime(2007, 2, 2),
              resource='service_module/service_a',
              quantity=11,
              )

Romain Courteaud's avatar
Romain Courteaud committed
787 788 789 790 791 792 793
    self.tic()

    request = self.portal.REQUEST
    ################################
    # Old date
    ################################
    request.form['at_date'] = DateTime(2005, 1, 1)
794
    request.form['node_category'] = 'site/demo_site_A'
795

Romain Courteaud's avatar
Romain Courteaud committed
796 797 798 799 800
    line_list = self.portal.inventory_module.Base_viewStockReportBySite.listbox.\
        get_value('default',
                  render_format='list', REQUEST=request)

    data_line_list = [l for l in line_list if l.isDataLine()]
801
    self.assertEqual(0, len(data_line_list))
Romain Courteaud's avatar
Romain Courteaud committed
802 803 804 805
    ################################
    # Middle date
    ################################
    request.form['at_date'] = DateTime(2006, 4, 4)
806
    request.form['node_category'] = 'site/demo_site_A'
807

Romain Courteaud's avatar
Romain Courteaud committed
808 809 810 811 812
    line_list = self.portal.inventory_module.Base_viewStockReportBySite.listbox.\
        get_value('default',
                  render_format='list', REQUEST=self.portal.REQUEST)

    data_line_list = [l for l in line_list if l.isDataLine()]
813
    self.assertEqual(1, len(data_line_list))
814

Romain Courteaud's avatar
Romain Courteaud committed
815 816
    # test columns values
    line = data_line_list[0]
Julien Muchembled's avatar
Julien Muchembled committed
817 818 819 820 821
    self.assertEqual(line.column_id_list, ['resource_title',
                                           'resource_reference',
                                           'variation_category_item_list',
                                           'inventory',
                                           'quantity_unit'])
Romain Courteaud's avatar
Romain Courteaud committed
822 823 824 825
    self.checkLineProperties(
                   data_line_list[0],
                   resource_title='product_A',
                   resource_reference='ref 2',
Julien Muchembled's avatar
Julien Muchembled committed
826
                   variation_category_item_list=[],
Romain Courteaud's avatar
Romain Courteaud committed
827
                   inventory=11,
Aurel's avatar
Aurel committed
828
                   quantity_unit='G')
Romain Courteaud's avatar
Romain Courteaud committed
829 830 831 832 833

    ################################
    # Futur date
    ################################
    request.form['at_date'] = DateTime(2008, 4, 4)
834
    request.form['node_category'] = 'site/demo_site_A'
835

Romain Courteaud's avatar
Romain Courteaud committed
836 837 838 839 840
    line_list = self.portal.inventory_module.Base_viewStockReportBySite.listbox.\
        get_value('default',
                  render_format='list', REQUEST=self.portal.REQUEST)

    data_line_list = [l for l in line_list if l.isDataLine()]
841
    self.assertEqual(4, len(data_line_list))
842

Romain Courteaud's avatar
Romain Courteaud committed
843 844 845 846
    self.checkLineProperties(
                   data_line_list[0],
                   resource_title='product_B',
                   resource_reference='ref 1',
Julien Muchembled's avatar
Julien Muchembled committed
847
                   variation_category_item_list=[],
Romain Courteaud's avatar
Romain Courteaud committed
848
                   inventory=33,
Aurel's avatar
Aurel committed
849
                   quantity_unit='Kg')
Romain Courteaud's avatar
Romain Courteaud committed
850 851 852 853
    self.checkLineProperties(
                   data_line_list[1],
                   resource_title='product_A',
                   resource_reference='ref 2',
Julien Muchembled's avatar
Julien Muchembled committed
854
                   variation_category_item_list=[],
Romain Courteaud's avatar
Romain Courteaud committed
855
                   inventory=22,
Aurel's avatar
Aurel committed
856
                   quantity_unit='G')
Romain Courteaud's avatar
Romain Courteaud committed
857 858 859 860
    self.checkLineProperties(
                   data_line_list[2],
                   resource_title='variated product',
                   resource_reference='ref 3',
Julien Muchembled's avatar
Julien Muchembled committed
861
                   variation_category_item_list=['colour1'],
Romain Courteaud's avatar
Romain Courteaud committed
862 863 864 865 866 867
                   inventory=66,
                   quantity_unit='')
    self.checkLineProperties(
                   data_line_list[3],
                   resource_title='variated product',
                   resource_reference='ref 3',
Julien Muchembled's avatar
Julien Muchembled committed
868
                   variation_category_item_list=['colour2'],
Romain Courteaud's avatar
Romain Courteaud committed
869 870
                   inventory=66,
                   quantity_unit='')
871

872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927
  def testStockReportWithPositiveOrNegativeOrZeroStock(self):
    """
    Stock report.
    """
    # Create inventories
    first = self._makeOneInventory(
              title='Inventory 1',
              simulation_state='delivered',
              destination_value=self.organisation_module.Organisation_1,
              start_date=DateTime(2007, 2, 2),
              resource='product_module/product_A',
              quantity=22,
              )

    second = self._makeOneInventory(
              title='Inventory 2',
              simulation_state='delivered',
              destination_value=self.organisation_module.Organisation_1,
              start_date=DateTime(2007, 2, 2),
              resource='product_module/product_A',
              quantity=-22,
              )

    third = self._makeOneInventory(
              title='Inventory 3',
              simulation_state='delivered',
              destination_value=self.organisation_module.Organisation_1,
              start_date=DateTime(2007, 2, 2),
              resource='product_module/product_B',
              quantity=-33,
              )

    fourth = self._makeOneInventory(
              title='Inventory 4',
              simulation_state='delivered',
              destination_value=self.organisation_module.Organisation_2,
              start_date=DateTime(2007, 2, 2),
              resource='product_module/product_B',
              quantity=-44,
              )

    fifth = self._makeOneInventory(
              title='Inventory 5',
              destination_value=self.organisation_module.Organisation_1,
              start_date=DateTime(2007, 2, 2),
              resource='product_module/product_C',
              quantity=55,
              )
    fifth_line = fifth.contentValues(portal_type='Inventory Line')[0]
    fifth_line.edit(
        variation_category_list=['colour/colour1', 'colour/colour2'],
        )
    base_id = 'movement'
    cell_key_list = list(fifth_line.getCellKeyList(base_id=base_id))
    for cell_key in cell_key_list:
      cell = fifth_line.newCell(base_id=base_id,
928
                                portal_type='Inventory Cell',
929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952
                                *cell_key)
      cell.edit(mapped_value_property_list=['inventory'],
                inventory=66,
                predicate_category_list=cell_key,
                variation_category_list=cell_key)
    fifth.deliver()

    # services are ignored
    self._makeOneInventory(
              title='Inventory 6',
              simulation_state='delivered',
              destination_value=self.organisation_module.Organisation_1,
              start_date=DateTime(2007, 2, 2),
              resource='service_module/service_a',
              quantity=11,
              )

    self.tic()

    request = self.portal.REQUEST
    ################################
    # Don't Display Positive Stock
    ################################
    request.form['at_date'] = DateTime(2008, 4, 4)
953
    request.form['node_category'] = 'site/demo_site_A'
954 955 956 957 958 959 960
    request.form['positive_stock'] = 1
    line_list = \
      self.portal.inventory_module.Base_viewStockReportBySite.listbox.\
        get_value('default',
                  render_format='list', REQUEST=self.portal.REQUEST)

    data_line_list = [l for l in line_list if l.isDataLine()]
961

962
    self.assertEqual(2, len(data_line_list))
963

964 965 966 967
    self.checkLineProperties(
                   data_line_list[0],
                   resource_title='product_B',
                   resource_reference='ref 1',
Julien Muchembled's avatar
Julien Muchembled committed
968
                   variation_category_item_list=[],
969 970 971 972 973 974
                   inventory=-33,
                   quantity_unit='Kg')
    self.checkLineProperties(
                   data_line_list[1],
                   resource_title='product_A',
                   resource_reference='ref 2',
Julien Muchembled's avatar
Julien Muchembled committed
975
                   variation_category_item_list=[],
976 977 978 979 980 981
                   inventory=0,
                   quantity_unit='G')
    ################################
    # Don't Display Negative Stock
    ################################
    request.form['at_date'] = DateTime(2008, 4, 4)
982
    request.form['node_category'] = 'site/demo_site_A'
983 984
    request.form['positive_stock'] = 0
    request.form['negative_stock'] = 1
985

986 987 988 989 990 991
    line_list = \
      self.portal.inventory_module.Base_viewStockReportBySite.listbox.\
        get_value('default',
                  render_format='list', REQUEST=self.portal.REQUEST)

    data_line_list = [l for l in line_list if l.isDataLine()]
992

993
    self.assertEqual(3, len(data_line_list))
994 995 996 997
    self.checkLineProperties(
                   data_line_list[0],
                   resource_title='product_A',
                   resource_reference='ref 2',
Julien Muchembled's avatar
Julien Muchembled committed
998
                   variation_category_item_list=[],
999 1000 1001 1002 1003 1004
                   inventory=0,
                   quantity_unit='G')
    self.checkLineProperties(
                   data_line_list[1],
                   resource_title='variated product',
                   resource_reference='ref 3',
Julien Muchembled's avatar
Julien Muchembled committed
1005
                   variation_category_item_list=['colour1'],
1006 1007 1008 1009 1010 1011
                   inventory=66,
                   quantity_unit='')
    self.checkLineProperties(
                   data_line_list[2],
                   resource_title='variated product',
                   resource_reference='ref 3',
Julien Muchembled's avatar
Julien Muchembled committed
1012
                   variation_category_item_list=['colour2'],
1013 1014 1015 1016 1017 1018
                   inventory=66,
                   quantity_unit='')
    ################################
    # Don't Display Zero Stock
    ################################
    request.form['at_date'] = DateTime(2008, 4, 4)
1019
    request.form['node_category'] = 'site/demo_site_A'
1020 1021 1022 1023 1024 1025 1026 1027 1028
    request.form['positive_stock'] = 0
    request.form['negative_stock'] = 0
    request.form['zero_stock'] = 1
    line_list = \
      self.portal.inventory_module.Base_viewStockReportBySite.listbox.\
        get_value('default',
                  render_format='list', REQUEST=self.portal.REQUEST)

    data_line_list = [l for l in line_list if l.isDataLine()]
1029

1030
    self.assertEqual(3, len(data_line_list))
1031 1032 1033 1034
    self.checkLineProperties(
                   data_line_list[0],
                   resource_title='product_B',
                   resource_reference='ref 1',
Julien Muchembled's avatar
Julien Muchembled committed
1035
                   variation_category_item_list=[],
1036 1037 1038 1039 1040 1041
                   inventory=-33,
                   quantity_unit='Kg')
    self.checkLineProperties(
                   data_line_list[1],
                   resource_title='variated product',
                   resource_reference='ref 3',
Julien Muchembled's avatar
Julien Muchembled committed
1042
                   variation_category_item_list=['colour1'],
1043 1044 1045 1046 1047 1048
                   inventory=66,
                   quantity_unit='')
    self.checkLineProperties(
                   data_line_list[2],
                   resource_title='variated product',
                   resource_reference='ref 3',
Julien Muchembled's avatar
Julien Muchembled committed
1049
                   variation_category_item_list=['colour2'],
1050 1051
                   inventory=66,
                   quantity_unit='')
1052 1053


1054 1055 1056 1057 1058
    ################################
    # Don't Display Positive Stock
    # And Negative Stock
    ################################
    request.form['at_date'] = DateTime(2008, 4, 4)
1059
    request.form['node_category'] = 'site/demo_site_A'
1060 1061 1062 1063 1064 1065 1066 1067 1068
    request.form['positive_stock'] = 1
    request.form['negative_stock'] = 1
    request.form['zero_stock'] = 0
    line_list = \
      self.portal.inventory_module.Base_viewStockReportBySite.listbox.\
        get_value('default',
                  render_format='list', REQUEST=self.portal.REQUEST)

    data_line_list = [l for l in line_list if l.isDataLine()]
1069

1070
    self.assertEqual(1, len(data_line_list))
1071 1072 1073 1074
    self.checkLineProperties(
                   data_line_list[0],
                   resource_title='product_A',
                   resource_reference='ref 2',
Julien Muchembled's avatar
Julien Muchembled committed
1075
                   variation_category_item_list=[],
1076 1077 1078 1079 1080 1081
                   inventory=0,
                   quantity_unit='G')
    ########################################
    # Don't Display Positive And Zero Stock
    ########################################
    request.form['at_date'] = DateTime(2008, 4, 4)
1082
    request.form['node_category'] = 'site/demo_site_A'
1083 1084 1085 1086 1087 1088 1089 1090 1091
    request.form['positive_stock'] = 1
    request.form['negative_stock'] = 0
    request.form['zero_stock'] = 1
    line_list = \
      self.portal.inventory_module.Base_viewStockReportBySite.listbox.\
        get_value('default',
                  render_format='list', REQUEST=self.portal.REQUEST)

    data_line_list = [l for l in line_list if l.isDataLine()]
1092

1093
    self.assertEqual(1, len(data_line_list))
1094 1095 1096 1097
    self.checkLineProperties(
                   data_line_list[0],
                   resource_title='product_B',
                   resource_reference='ref 1',
Julien Muchembled's avatar
Julien Muchembled committed
1098
                   variation_category_item_list=[],
1099 1100 1101 1102 1103 1104
                   inventory=-33,
                   quantity_unit='Kg')
    ########################################
    # Don't Display Negative And Zero Stock
    ########################################
    request.form['at_date'] = DateTime(2008, 4, 4)
1105
    request.form['node_category'] = 'site/demo_site_A'
1106 1107 1108 1109 1110 1111 1112 1113 1114
    request.form['positive_stock'] = 0
    request.form['negative_stock'] = 1
    request.form['zero_stock'] = 1
    line_list = \
      self.portal.inventory_module.Base_viewStockReportBySite.listbox.\
        get_value('default',
                  render_format='list', REQUEST=self.portal.REQUEST)

    data_line_list = [l for l in line_list if l.isDataLine()]
1115

1116
    self.assertEqual(2, len(data_line_list))
1117 1118 1119 1120
    self.checkLineProperties(
                   data_line_list[0],
                   resource_title='variated product',
                   resource_reference='ref 3',
Julien Muchembled's avatar
Julien Muchembled committed
1121
                   variation_category_item_list=['colour1'],
1122 1123 1124 1125 1126 1127
                   inventory=66,
                   quantity_unit='')
    self.checkLineProperties(
                   data_line_list[1],
                   resource_title='variated product',
                   resource_reference='ref 3',
Julien Muchembled's avatar
Julien Muchembled committed
1128
                   variation_category_item_list=['colour2'],
1129 1130 1131 1132 1133 1134
                   inventory=66,
                   quantity_unit='')
    ################################################
    # Don't Display Positive,Negative And Zero Stock
    ################################################
    request.form['at_date'] = DateTime(2008, 4, 4)
1135
    request.form['node_category'] = 'site/demo_site_A'
1136 1137 1138 1139 1140 1141 1142
    request.form['positive_stock'] = 1
    request.form['negative_stock'] = 1
    request.form['zero_stock'] = 1
    line_list = \
      self.portal.inventory_module.Base_viewStockReportBySite.listbox.\
        get_value('default',
                  render_format='list', REQUEST=self.portal.REQUEST)
Romain Courteaud's avatar
Romain Courteaud committed
1143

1144
    data_line_list = [l for l in line_list if l.isDataLine()]
1145

1146
    self.assertEqual(0, len(data_line_list))
1147

1148

1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186
  def test_Folder_generateWorkflowReport(self):
    # Create sales orders
    first = self._makeOneSaleOrder(
              title='SO 1',
              destination_value=self.organisation_module.Organisation_1,
              destination_section_value=self.organisation_module.Organisation_1,
              destination_decision_value=self.organisation_module.Organisation_1,
              source_value=self.organisation_module.Organisation_2,
              source_section_value=self.organisation_module.Organisation_2,
              source_decision_value=self.organisation_module.Organisation_2,
              start_date=DateTime(2006, 2, 2),
              resource_dict = {'product_module/product_A':{"quantity":11, "price":3},
                               'product_module/product_B':{"quantity":7, "price":6},}
              )
    second = self._makeOneSaleOrder(
              title='SO 2',
              destination_value=self.organisation_module.Organisation_1,
              destination_section_value=self.organisation_module.Organisation_1,
              destination_decision_value=self.organisation_module.Organisation_1,
              source_value=self.organisation_module.Organisation_2,
              source_section_value=self.organisation_module.Organisation_2,
              source_decision_value=self.organisation_module.Organisation_2,
              start_date=DateTime(2007, 2, 2),
              resource_dict = {'product_module/product_A':{"quantity":3, "price":3},}
              )
    third = self._makeOneSaleOrder(
              title='SO 4',
              destination_value=self.organisation_module.Organisation_1,
              destination_section_value=self.organisation_module.Organisation_1,
              destination_decision_value=self.organisation_module.Organisation_1,
              source_value=self.organisation_module.Organisation_2,
              source_section_value=self.organisation_module.Organisation_2,
              source_decision_value=self.organisation_module.Organisation_2,
              start_date=DateTime(2007, 2, 2),
              resource_dict = {'product_module/product_A':{"quantity":17, "price":3},
                               'product_module/product_B':{"quantity":13, "price":6},},
              cancel=True
              )
1187

1188 1189 1190
    # call the report first, it will set selection
    report_html = \
        self.portal.sale_order_module.Folder_generateWorkflowReport()
1191
    self.assertFalse('Site Error' in report_html)
1192 1193 1194 1195 1196

    line_list = self.portal.sale_order_module.Folder_viewWorkflowReport.listbox.\
        get_value('default',
                  render_format='list', REQUEST=self.portal.REQUEST)
    data_line_list = [l for l in line_list if l.isDataLine()]
1197
    self.assertEqual(5, len(data_line_list))
1198 1199
    order_workflow_name = 'Sale Order - Order Workflow'
    causality_workflow_name = 'Sale Order - Causality Workflow'
1200
    self.checkLineProperties(data_line_list[2],
1201
                             translated_portal_type=order_workflow_name)
1202
    self.checkLineProperties(data_line_list[3],
1203 1204 1205
                             translated_portal_type='',
                             state='Cancelled',
                             count=1)
1206
    self.checkLineProperties(data_line_list[4],
1207 1208 1209
                             translated_portal_type='',
                             state='Draft',
                             count=2)
1210
    self.checkLineProperties(data_line_list[0],
1211
                             translated_portal_type=causality_workflow_name)
1212
    self.checkLineProperties(data_line_list[1],
1213 1214 1215
                             translated_portal_type='',
                             state='Draft',
                             count=3)
1216 1217


Romain Courteaud's avatar
Romain Courteaud committed
1218 1219 1220 1221 1222
def test_suite():
  suite = unittest.TestSuite()
  suite.addTest(unittest.makeSuite(TestTradeReports))
  return suite