示例#1
0
    def test_validate_confirm(self, warning):
        wo = self.create_workorder()
        wo.identifier = 123
        wo.approve()
        sellable = self.create_sellable()
        self.create_storable(product=sellable.product)

        editor = WorkOrderPackageSendEditor(self.store)

        self.assertFalse(editor.validate_confirm())
        warning.assert_called_once_with(
            u"You need to select at least one work order")
示例#2
0
    def test_create_return_from_execution(self, localnow):
        current_branch = api.get_current_branch(self.store)
        current_branch.can_execute_foreign_work_orders = True
        localnow.return_value = localdatetime(2013, 1, 1)
        destination_branch = self.create_branch()
        workorders_ids = set()

        for i in xrange(10):
            wo = self.create_workorder(description=u"Equipment %d" % i)
            wo.client = self.create_client()
            wo.identifier = 666 + i
            wo.open_date = localdatetime(2013, 1, 1)

            # Only the 3 finished and with their original branches set to the
            # destination_branch will appear on the list
            if i < 3:
                wo.approve()
            elif 3 <= i < 6:
                wo.approve()
                wo.work()
                wo.add_sellable(self.create_sellable())
                wo.finish()
            elif 6 <= i < 9:
                wo.approve()
                wo.work()
                wo.add_sellable(self.create_sellable())
                wo.finish()
                wo.branch = destination_branch
                workorders_ids.add(wo.id)

        editor = WorkOrderPackageSendEditor(self.store)

        self.assertInvalid(editor, ['destination_branch'])
        self.assertEqual(len(editor.workorders), 0)
        editor.destination_branch.update(destination_branch)
        self.assertValid(editor, ['destination_branch'])

        self.assertEqual(workorders_ids,
                         set([wo_.id for wo_ in editor.workorders]))

        self.assertEqual(editor.model.package_items.count(), 0)
        # Only these 2 will be sent
        for wo in [editor.workorders[0], editor.workorders[1]]:
            wo.will_send = True
            # Mimic 'cell-edited' emission
            editor.workorders.emit('cell_edited', wo, 'will_send')

        self.assertNotSensitive(editor.main_dialog, ['ok_button'])
        self.assertInvalid(editor, ['identifier'])
        editor.identifier.update(u'123321')
        self.assertValid(editor, ['identifier'])
        self.assertSensitive(editor.main_dialog, ['ok_button'])

        self.check_editor(
            editor, 'editor-workorderpackagesend-return-from-execution-create')

        with mock.patch.object(editor.model, 'send') as send:
            self.click(editor.main_dialog.ok_button)
            self.assertEqual(send.call_count, 1)
            self.assertEqual(editor.model.package_items.count(), 2)
示例#3
0
    def testCreate(self, localnow):
        localnow.return_value = localdatetime(2013, 1, 1)
        destination_branch = self.create_branch()
        workorders_ids = set()

        for i in xrange(10):
            wo = self.create_workorder(u"Equipment %d" % i)
            wo.client = self.create_client()
            wo.identifier = 666 + i
            wo.open_date = localdatetime(2013, 1, 1)

            # Only the first 6 will appear on the list. Half of them as
            # approved and half of them as finished.
            if i < 3:
                wo.approve()
                workorders_ids.add(wo.id)
            elif i < 6:
                wo.approve()
                wo.start()
                wo.add_sellable(self.create_sellable())
                wo.finish()
                workorders_ids.add(wo.id)

        editor = WorkOrderPackageSendEditor(self.store)
        self.assertEqual(workorders_ids,
                         set([wo.id for wo in editor.workorders]))

        self.assertEqual(editor.model.package_items.count(), 0)
        # Only these 2 will be sent
        for wo in [editor.workorders[0], editor.workorders[1]]:
            wo.will_send = True
            # Mimic 'cell-edited' emission
            editor.workorders.emit('cell_edited', wo, 'will_send')
        self.assertEqual(editor.model.package_items.count(), 2)

        self.assertNotSensitive(editor.main_dialog, ['ok_button'])
        self.assertInvalid(editor, ['identifier', 'destination_branch'])
        editor.identifier.update(u'123321')
        editor.destination_branch.update(destination_branch)
        self.assertValid(editor, ['identifier', 'destination_branch'])
        self.assertSensitive(editor.main_dialog, ['ok_button'])

        self.check_editor(editor, 'editor-workorderpackagesend-create')

        with mock.patch.object(editor.model, 'send') as send:
            self.click(editor.main_dialog.ok_button)
            send.assert_called_once()