Ejemplo n.º 1
0
    def test_status_field(self):
        self.assertEqual(AssetStatus.name_from_id(self.third_asset.status), "used")
        url = "/assets/dc/search?status=%s" % AssetStatus.used.id
        content = self.client.get(url)
        self.assertEqual(content.status_code, 200)

        rows_from_table = content.context_data["bob_page"].object_list
        self.assertEqual(len(rows_from_table), 1)

        # Test if search form find correct data
        self.assertItemsEqual([AssetStatus.name_from_id(asset.status) for asset in rows_from_table], ["used"])
        self.assertEqual(rows_from_table[0].sn, "1236-1236-1236-1236")
Ejemplo n.º 2
0
    def test_status_field(self):
        self.assertEqual(AssetStatus.name_from_id(self.third_asset.status),
                         'used')
        url = '/assets/dc/search?status=%s' % AssetStatus.used.id
        content = self.client.get(url)
        self.assertEqual(content.status_code, 200)

        rows_from_table = content.context_data['bob_page'].object_list
        self.assertEqual(len(rows_from_table), 1)

        # Test if search form find correct data
        self.assertItemsEqual([
            AssetStatus.name_from_id(asset.status, )
            for asset in rows_from_table
        ], ['used'])
        self.assertEqual(rows_from_table[0].sn, '1236-1236-1236-1236')
Ejemplo n.º 3
0
    def test_display_data_in_table(self):
        get_search_page = self.client.get('/assets/dc/search')
        self.assertEqual(get_search_page.status_code, 200)

        # Test if data from database are displayed in correct row.
        first_table_row = get_search_page.context_data['bob_page'][0]
        self.assertEqual(self.asset, first_table_row)
        self.assertItemsEqual(
            [
                first_table_row.barcode,
                first_table_row.invoice_no,
                first_table_row.order_no,
                unicode(first_table_row.invoice_date),
                first_table_row.sn,
                AssetType.name_from_id(first_table_row.type),
                AssetStatus.name_from_id(first_table_row.status),
                first_table_row.model.name,
                first_table_row.warehouse.name,
            ],
            [
                u'123456789',
                u'Invoice #1',
                u'Order #1',
                u'2001-01-01',
                u'0000-0000-0000-0000',
                u'Model1',
                'data_center',
                'new',
                'Warehouse',
            ]
        )
Ejemplo n.º 4
0
    def test_display_data_in_table(self):
        get_search_page = self.client.get('/assets/dc/search')
        self.assertEqual(get_search_page.status_code, 200)

        # Test if data from database are displayed in correct row.
        first_table_row = get_search_page.context_data['bob_page'][0]
        self.assertEqual(self.asset, first_table_row)
        self.assertItemsEqual([
            first_table_row.barcode,
            first_table_row.invoice_no,
            first_table_row.order_no,
            unicode(first_table_row.invoice_date),
            first_table_row.sn,
            AssetType.name_from_id(first_table_row.type),
            AssetStatus.name_from_id(first_table_row.status),
            first_table_row.model.name,
            first_table_row.warehouse.name,
        ], [
            u'123456789',
            u'Invoice #1',
            u'Order #1',
            u'2001-01-01',
            u'0000-0000-0000-0000',
            u'Model1',
            'data_center',
            'new',
            'Warehouse',
        ])
Ejemplo n.º 5
0
    def prepare(self, mode):
        queryset = Asset.objects
        if mode:
            queryset = queryset.filter(type=mode)
        queryset = queryset.select_related('model', 'category').values(
            'model__category__name',
            'model__name',
            'status',
        ).annotate(
            num=Count('status')
        ).order_by('model__category__name')

        for item in queryset:
            parent = item['model__category__name'] or 'Without category'
            name = item['model__name']
            node = self.report.add(
                name=name,
                parent=parent,
            )
            self.report.add(
                name=AssetStatus.from_id(item['status']),
                parent=node,
                count=item['num'],
                unique=False
            )
Ejemplo n.º 6
0
class Transition(Named, TimeTrackable, WithConcurrentGetOrCreate):
    slug = models.SlugField(max_length=100, unique=True, blank=False)
    from_status = models.PositiveSmallIntegerField(
        verbose_name=_("from"),
        choices=AssetStatus(),
        null=True,
        blank=True,
    )
    to_status = models.PositiveSmallIntegerField(
        verbose_name=_("to"),
        choices=AssetStatus(),
    )
    actions = models.ManyToManyField(Action)
    required_report = models.BooleanField(default=False)

    @property
    def actions_names(self, *args, **kwargs):
        return [action.name for action in self.actions.all()]