testTradeReports.py 53.1 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
  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,
241
              start_date=DateTime(2006, 2, 2, 10),
Aurel's avatar
Aurel committed
242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263
              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
    # 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)

392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480


    # This is exactly the same as above, by at_date is as 02/02/2006
    # so we check that first sale_order with start_date=DateTime(2006, 2, 2, 10)
    # is counted, i.e. at_date is inclusive.
    request['from_date'] = DateTime(2005, 2, 2)
    request['at_date'] = DateTime(2006, 2, 2)
    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))

    # test columns values
    line = data_line_list[0]
    self.assertEqual(line.column_id_list, ['client',
                    'product',
                    'Amount 2005',
                    'Quantity 2005',
                    'Quantity Unit 2005',
                    'Amount 2006',
                    'Quantity 2006',
                    'Quantity Unit 2006',
                    'total amount',
                    'total quantity'])

    # 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': '',
                 'Quantity Unit 2006': 'G',
                 'client': None,
                 'product': 'product_A',
                 'total amount': 33.0,
                 'total quantity': 11.0}
    self.checkLineProperties(data_line_list[1],**d)

    # Product two for first organisation
    d = {'Amount 2005': 0,
                 'Amount 2006': 42.0,
                 'Quantity 2005': 0,
                 'Quantity 2006': 7.0,
                 'Quantity Unit 2005': '',
                 'Quantity Unit 2006': 'Kg',
                 'client': None,
                 'product': 'product_B',
                 'total amount': 42.0,
                 'total quantity': 7.0}
    self.checkLineProperties(data_line_list[2],**d)
    # 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)




481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500
    #
    # 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))
501

Aurel's avatar
Aurel committed
502 503 504 505 506 507 508 509 510 511 512
    # 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}
513
    self.checkLineProperties(data_line_list[0],**d)
514

Aurel's avatar
Aurel committed
515 516 517 518 519 520
    # 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
521
                 'Quantity Unit 2006': 'G',
Aurel's avatar
Aurel committed
522 523 524 525
                 'client': None,
                 'product': 'product_A',
                 'total amount': 15.0,
                 'total quantity': 5.0}
526
    self.checkLineProperties(data_line_list[1],**d)
527

Aurel's avatar
Aurel committed
528 529 530 531 532 533
    # 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
534
                 'Quantity Unit 2006': 'Kg',
Aurel's avatar
Aurel committed
535 536 537 538
                 'client': None,
                 'product': 'product_B',
                 'total amount': 6.0,
                 'total quantity': 1.0}
539
    self.checkLineProperties(data_line_list[2],**d)
540

Aurel's avatar
Aurel committed
541 542
    # stat line
    d = {'Amount 2005': None,
543
                 'Amount 2006': 21.0,
Aurel's avatar
Aurel committed
544 545 546 547 548 549
                 'Quantity 2005': None,
                 'Quantity 2006': None,
                 'Quantity Unit 2005': None,
                 'Quantity Unit 2006': None,
                 'client': 'Total',
                 'product': None,
550
                 'total amount': 21.0,
Aurel's avatar
Aurel committed
551 552
                 'total quantity': None}
    self.checkLineProperties(stat_line_list[0],**d)
553 554


Aurel's avatar
Aurel committed
555 556 557 558 559 560
    #
    # 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',]
561
    request['section_category'] = 'group/g2'
562 563 564 565
    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
566 567
    report_section_list = self.getReportSectionList(self.sale_order_module,
                                                    'OrderModule_viewOrderReport')
568
    self.assertEqual(1, len(report_section_list))
Aurel's avatar
Aurel committed
569 570 571 572

    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()]
573 574
    self.assertEqual(3, len(data_line_list))
    self.assertEqual(1, len(stat_line_list))
575
    # First organisation
Aurel's avatar
Aurel committed
576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591
    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
592 593
                 'Quantity Unit 2006': 'G',
                 'Quantity Unit 2007': 'G',
Aurel's avatar
Aurel committed
594 595 596 597 598 599 600 601 602 603
                 '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
604
                 'Quantity Unit 2006': 'Kg',
Aurel's avatar
Aurel committed
605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622
                 '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)
623

624
    # weekly aggregation level
625
    # first for g2
626 627 628 629 630
    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']
631 632 633 634
    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()
635 636
    report_section_list = self.getReportSectionList(self.sale_order_module,
                                                    'OrderModule_viewOrderReport')
637
    self.assertEqual(1, len(report_section_list))
638 639
    line_list = self.getListBoxLineList(report_section_list[0])
    data_line_list = [l for l in line_list if l.isDataLine()]
640
    self.assertEqual(1, len(data_line_list))
641 642 643 644 645 646 647 648 649

    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})
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
    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],
680 681 682 683 684 685 686 687
                   **{'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})

688
    self.assertTrue(line_list[-1].isStatLine())
689
    self.checkLineProperties(line_list[-1],
690
                   **{'Amount 2006-05': None,
691 692 693 694 695
                      'Amount 2006-06': None,
                      'Amount 2006-07': None,
                      'Amount 2006-08': 5*3 + 6,
                      'Amount 2006-09': None,
                      'client': 'Total',
696 697 698
                      'total amount': 5*3 + 6})


699

Aurel's avatar
Aurel committed
700

701 702 703 704 705 706
    # 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"
707
    request['section_category'] = 'group/g2'
708 709 710 711
    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()
712 713
    report_section_list = self.getReportSectionList(self.sale_order_module,
                                                    'OrderModule_viewOrderReport')
714
    self.assertEqual(1, len(report_section_list))
715 716 717 718

    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()]
719 720
    self.assertEqual(3, len(data_line_list))
    self.assertEqual(1, len(stat_line_list))
721
    # First organisation
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
    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)
769

770
    # section category set, with no matching organisations
771 772 773
    request['simulation_state'] = ['draft',]
    request['aggregation_level'] = "year"
    request['group_by'] = "both"
774
    request['section_category'] = 'group/g3'
775 776 777 778
    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()
779 780
    report_section_list = self.getReportSectionList(self.sale_order_module,
                                                    'OrderModule_viewOrderReport')
781
    self.assertEqual(1, len(report_section_list))
782 783 784 785

    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()]
786 787
    self.assertEqual(0, len(data_line_list))
    self.assertEqual(1, len(stat_line_list))
788 789 790 791 792 793 794 795 796 797 798 799
    # 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)
800

Romain Courteaud's avatar
Romain Courteaud committed
801 802 803 804 805 806 807 808 809
  def testStockReport(self):
    """
    Stock report.
    """
    # Create inventories
    first = self._makeOneInventory(
              title='Inventory 1',
              simulation_state='delivered',
              destination_value=self.organisation_module.Organisation_1,
810
              source_value=self.organisation_module.Organisation_3,
Romain Courteaud's avatar
Romain Courteaud committed
811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857
              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,
858
                                portal_type='Inventory Cell',
Romain Courteaud's avatar
Romain Courteaud committed
859 860 861 862 863 864 865
                                *cell_key)
      cell.edit(mapped_value_property_list=['inventory'],
                inventory=66,
                predicate_category_list=cell_key,
                variation_category_list=cell_key)
    fifth.deliver()

866 867 868 869 870 871 872 873 874 875
    # 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
876 877 878 879 880 881 882
    self.tic()

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

Romain Courteaud's avatar
Romain Courteaud committed
885 886 887 888 889
    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()]
890
    self.assertEqual(0, len(data_line_list))
Romain Courteaud's avatar
Romain Courteaud committed
891 892 893 894
    ################################
    # Middle date
    ################################
    request.form['at_date'] = DateTime(2006, 4, 4)
895
    request.form['node_category'] = 'site/demo_site_A'
896

Romain Courteaud's avatar
Romain Courteaud committed
897 898 899 900 901
    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()]
902
    self.assertEqual(1, len(data_line_list))
903

Romain Courteaud's avatar
Romain Courteaud committed
904 905
    # test columns values
    line = data_line_list[0]
Julien Muchembled's avatar
Julien Muchembled committed
906 907 908 909 910
    self.assertEqual(line.column_id_list, ['resource_title',
                                           'resource_reference',
                                           'variation_category_item_list',
                                           'inventory',
                                           'quantity_unit'])
Romain Courteaud's avatar
Romain Courteaud committed
911 912 913 914
    self.checkLineProperties(
                   data_line_list[0],
                   resource_title='product_A',
                   resource_reference='ref 2',
Julien Muchembled's avatar
Julien Muchembled committed
915
                   variation_category_item_list=[],
Romain Courteaud's avatar
Romain Courteaud committed
916
                   inventory=11,
Aurel's avatar
Aurel committed
917
                   quantity_unit='G')
Romain Courteaud's avatar
Romain Courteaud committed
918 919 920 921 922

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

Romain Courteaud's avatar
Romain Courteaud committed
925 926 927 928 929
    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()]
930
    self.assertEqual(4, len(data_line_list))
931

Romain Courteaud's avatar
Romain Courteaud committed
932 933 934 935
    self.checkLineProperties(
                   data_line_list[0],
                   resource_title='product_B',
                   resource_reference='ref 1',
Julien Muchembled's avatar
Julien Muchembled committed
936
                   variation_category_item_list=[],
Romain Courteaud's avatar
Romain Courteaud committed
937
                   inventory=33,
Aurel's avatar
Aurel committed
938
                   quantity_unit='Kg')
Romain Courteaud's avatar
Romain Courteaud committed
939 940 941 942
    self.checkLineProperties(
                   data_line_list[1],
                   resource_title='product_A',
                   resource_reference='ref 2',
Julien Muchembled's avatar
Julien Muchembled committed
943
                   variation_category_item_list=[],
Romain Courteaud's avatar
Romain Courteaud committed
944
                   inventory=22,
Aurel's avatar
Aurel committed
945
                   quantity_unit='G')
Romain Courteaud's avatar
Romain Courteaud committed
946 947 948 949
    self.checkLineProperties(
                   data_line_list[2],
                   resource_title='variated product',
                   resource_reference='ref 3',
Julien Muchembled's avatar
Julien Muchembled committed
950
                   variation_category_item_list=['colour1'],
Romain Courteaud's avatar
Romain Courteaud committed
951 952 953 954 955 956
                   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
957
                   variation_category_item_list=['colour2'],
Romain Courteaud's avatar
Romain Courteaud committed
958 959
                   inventory=66,
                   quantity_unit='')
960

961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016
  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,
1017
                                portal_type='Inventory Cell',
1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041
                                *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)
1042
    request.form['node_category'] = 'site/demo_site_A'
1043 1044 1045 1046 1047 1048 1049
    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()]
1050

1051
    self.assertEqual(2, len(data_line_list))
1052

1053 1054 1055 1056
    self.checkLineProperties(
                   data_line_list[0],
                   resource_title='product_B',
                   resource_reference='ref 1',
Julien Muchembled's avatar
Julien Muchembled committed
1057
                   variation_category_item_list=[],
1058 1059 1060 1061 1062 1063
                   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
1064
                   variation_category_item_list=[],
1065 1066 1067 1068 1069 1070
                   inventory=0,
                   quantity_unit='G')
    ################################
    # Don't Display Negative Stock
    ################################
    request.form['at_date'] = DateTime(2008, 4, 4)
1071
    request.form['node_category'] = 'site/demo_site_A'
1072 1073
    request.form['positive_stock'] = 0
    request.form['negative_stock'] = 1
1074

1075 1076 1077 1078 1079 1080
    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()]
1081

1082
    self.assertEqual(3, len(data_line_list))
1083 1084 1085 1086
    self.checkLineProperties(
                   data_line_list[0],
                   resource_title='product_A',
                   resource_reference='ref 2',
Julien Muchembled's avatar
Julien Muchembled committed
1087
                   variation_category_item_list=[],
1088 1089 1090 1091 1092 1093
                   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
1094
                   variation_category_item_list=['colour1'],
1095 1096 1097 1098 1099 1100
                   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
1101
                   variation_category_item_list=['colour2'],
1102 1103 1104 1105 1106 1107
                   inventory=66,
                   quantity_unit='')
    ################################
    # Don't Display Zero Stock
    ################################
    request.form['at_date'] = DateTime(2008, 4, 4)
1108
    request.form['node_category'] = 'site/demo_site_A'
1109 1110 1111 1112 1113 1114 1115 1116 1117
    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()]
1118

1119
    self.assertEqual(3, len(data_line_list))
1120 1121 1122 1123
    self.checkLineProperties(
                   data_line_list[0],
                   resource_title='product_B',
                   resource_reference='ref 1',
Julien Muchembled's avatar
Julien Muchembled committed
1124
                   variation_category_item_list=[],
1125 1126 1127 1128 1129 1130
                   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
1131
                   variation_category_item_list=['colour1'],
1132 1133 1134 1135 1136 1137
                   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
1138
                   variation_category_item_list=['colour2'],
1139 1140
                   inventory=66,
                   quantity_unit='')
1141 1142


1143 1144 1145 1146 1147
    ################################
    # Don't Display Positive Stock
    # And Negative Stock
    ################################
    request.form['at_date'] = DateTime(2008, 4, 4)
1148
    request.form['node_category'] = 'site/demo_site_A'
1149 1150 1151 1152 1153 1154 1155 1156 1157
    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()]
1158

1159
    self.assertEqual(1, len(data_line_list))
1160 1161 1162 1163
    self.checkLineProperties(
                   data_line_list[0],
                   resource_title='product_A',
                   resource_reference='ref 2',
Julien Muchembled's avatar
Julien Muchembled committed
1164
                   variation_category_item_list=[],
1165 1166 1167 1168 1169 1170
                   inventory=0,
                   quantity_unit='G')
    ########################################
    # Don't Display Positive And Zero Stock
    ########################################
    request.form['at_date'] = DateTime(2008, 4, 4)
1171
    request.form['node_category'] = 'site/demo_site_A'
1172 1173 1174 1175 1176 1177 1178 1179 1180
    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()]
1181

1182
    self.assertEqual(1, len(data_line_list))
1183 1184 1185 1186
    self.checkLineProperties(
                   data_line_list[0],
                   resource_title='product_B',
                   resource_reference='ref 1',
Julien Muchembled's avatar
Julien Muchembled committed
1187
                   variation_category_item_list=[],
1188 1189 1190 1191 1192 1193
                   inventory=-33,
                   quantity_unit='Kg')
    ########################################
    # Don't Display Negative And Zero Stock
    ########################################
    request.form['at_date'] = DateTime(2008, 4, 4)
1194
    request.form['node_category'] = 'site/demo_site_A'
1195 1196 1197 1198 1199 1200 1201 1202 1203
    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()]
1204

1205
    self.assertEqual(2, len(data_line_list))
1206 1207 1208 1209
    self.checkLineProperties(
                   data_line_list[0],
                   resource_title='variated product',
                   resource_reference='ref 3',
Julien Muchembled's avatar
Julien Muchembled committed
1210
                   variation_category_item_list=['colour1'],
1211 1212 1213 1214 1215 1216
                   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
1217
                   variation_category_item_list=['colour2'],
1218 1219 1220 1221 1222 1223
                   inventory=66,
                   quantity_unit='')
    ################################################
    # Don't Display Positive,Negative And Zero Stock
    ################################################
    request.form['at_date'] = DateTime(2008, 4, 4)
1224
    request.form['node_category'] = 'site/demo_site_A'
1225 1226 1227 1228 1229 1230 1231
    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
1232

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

1235
    self.assertEqual(0, len(data_line_list))
1236

1237

1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275
  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
              )
1276

1277 1278 1279
    # call the report first, it will set selection
    report_html = \
        self.portal.sale_order_module.Folder_generateWorkflowReport()
1280
    self.assertFalse('Site Error' in report_html)
1281 1282 1283 1284 1285

    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()]
1286
    self.assertEqual(5, len(data_line_list))
1287 1288
    order_workflow_name = 'Sale Order - Order Workflow'
    causality_workflow_name = 'Sale Order - Causality Workflow'
1289
    self.checkLineProperties(data_line_list[2],
1290
                             translated_portal_type=order_workflow_name)
1291
    self.checkLineProperties(data_line_list[3],
1292 1293 1294
                             translated_portal_type='',
                             state='Cancelled',
                             count=1)
1295
    self.checkLineProperties(data_line_list[4],
1296 1297 1298
                             translated_portal_type='',
                             state='Draft',
                             count=2)
1299
    self.checkLineProperties(data_line_list[0],
1300
                             translated_portal_type=causality_workflow_name)
1301
    self.checkLineProperties(data_line_list[1],
1302 1303 1304
                             translated_portal_type='',
                             state='Draft',
                             count=3)
1305 1306


Romain Courteaud's avatar
Romain Courteaud committed
1307 1308 1309 1310 1311
def test_suite():
  suite = unittest.TestSuite()
  suite.addTest(unittest.makeSuite(TestTradeReports))
  return suite