Exemplo n.º 1
0
    def init_relation_models(self):
        self.receiver = self.receiver_suite.create_test_receiver()
        self.receiver_id = self.receiver.id
        self.point_1 = self.pointsale_suite.create_test_pointsale(name=u"ШШК", address=u"наб. Челны", is_central=True)
        self.point_1_id = self.point_1.id
        self.point_2 = self.pointsale_suite.create_test_pointsale(
            name=u"Одиссей", address=u"Наб. Челны, ул. Беляева, 75"
        )
        self.point_2_id = self.point_2.id
        self.point_3 = self.pointsale_suite.create_test_pointsale(
            name=u"Форт Диалог", address=u"Наб. Челны, Московский пр., 15"
        )
        self.point_3_id = self.point_3.id

        self.application_suite = ApplicationSuite(self.client, self.application)
        self.good_id = self.application_suite.good(u"XXL", "77", "114", 105.0, 86.0)
        self.good_2_id = self.application_suite.good(u"Машинка", None, None, 24.0, 21.0)
        self.good_3_id = self.application_suite.good(u"ЗОЖ", "4", "105", None, 9.5)
        self.good_4_id = self.application_suite.good(u"Мельница", None, None, 15.0, None)

        self.COUNT_GOOD_1 = 10
        self.COUNT_GOOD_4 = 5
        self.COUNT_GOOD_2 = 7

        self.items = [
            {GOOD_ATTR: self.good_id, COUNT_ATTR: self.COUNT_GOOD_1},
            {GOOD_ATTR: self.good_4_id, COUNT_ATTR: self.COUNT_GOOD_4},
        ]

        self.items_2 = [{GOOD_ATTR: self.good_2_id, COUNT_ATTR: self.COUNT_GOOD_2}]
Exemplo n.º 2
0
    def set_up(self):
        self.pointsale_suite = PointSaleSuite(self.client, self.application)
        self.inventory_suite = InventorySuite(self.client, self.application)
        self.application_suite = ApplicationSuite(self.client, self.application)

        with self.application.app_context():
            self.number_1 = Generator.generate_int()
            self.number_2 = Generator.generate_int()
            self.pointsale_id = self.pointsale_suite.create_test_pointsale("", "").id
            self.good_id_1 = self.application_suite.good(u"ЛТД", '1', '101', 8, 5.5)
            self.good_id_2 = self.application_suite.good(u"Вечерние Челны", '4', '402', 12.0, 9.7)
            self.good_id_3 = self.application_suite.good(u"WinX", '25', '107', 147.0, 123.0)
            self.good_id_4 = self.application_suite.good(u"Трансформеры", '4', '7', 120.0, 97.0)
Exemplo n.º 3
0
class InventoryTest(BaseTestCase):

    def set_up(self):
        self.pointsale_suite = PointSaleSuite(self.client, self.application)
        self.inventory_suite = InventorySuite(self.client, self.application)
        self.application_suite = ApplicationSuite(self.client, self.application)

        with self.application.app_context():
            self.number_1 = Generator.generate_int()
            self.number_2 = Generator.generate_int()
            self.pointsale_id = self.pointsale_suite.create_test_pointsale("", "").id
            self.good_id_1 = self.application_suite.good(u"ЛТД", '1', '101', 8, 5.5)
            self.good_id_2 = self.application_suite.good(u"Вечерние Челны", '4', '402', 12.0, 9.7)
            self.good_id_3 = self.application_suite.good(u"WinX", '25', '107', 147.0, 123.0)
            self.good_id_4 = self.application_suite.good(u"Трансформеры", '4', '7', 120.0, 97.0)

    def get_pointsaleitem(self, pointsale_id, good_id):
        return PointSaleItem.query.filter(
            PointSaleItem.pointsale_id == pointsale_id,
            PointSaleItem.good_id == good_id).one()

    def get_inventoryitem(self, inventory_id, good_id):
        return InventoryItems.query.filter(
            InventoryItems.inventory_id == inventory_id,
            InventoryItems.good_id == good_id).one()

    def test_(self):
        #Кол-ва товара в накладную
        count_after_1 = 100
        count_after_2 = 67
        with self.application.app_context():
            response = self.inventory_suite.create_inventory(self.pointsale_id, self.number_1)

            self.assertEqual(response.status_code, 200)
            data = self._deserialize(response.data)
            inventory_id_1 = data['id']

            self.assertEqual(InventoryItems.query.filter(
                InventoryItems.inventory_id == inventory_id_1
            ).count(), 0)

            response = self.inventory_suite.inventory_status(inventory_id_1, IN_PROG)
            self.assertEqual(response.status_code, 200)

            self.assertEqual(InventoryItems.query.filter(
                InventoryItems.inventory_id == inventory_id_1
            ).count(), 0)

            items = [
                {COUNT_AFTER_ATTR: count_after_1, GOOD_ATTR: {GOOD_ID_ATTR: self.good_id_1}},
                {COUNT_AFTER_ATTR: count_after_2, GOOD_ATTR: {GOOD_ID_ATTR: self.good_id_2}}
            ]

            response = self.inventory_suite.update_inventory(inventory_id_1, items=items)
            self.assertEqual(response.status_code, 200)

            self.assertEqual(InventoryItems.query.filter(
                InventoryItems.inventory_id == inventory_id_1
            ).count(), 2)
            self.assertEqual(PointSaleItem.query.filter(
                PointSaleItem.pointsale_id == self.pointsale_id
            ).count(), 0)

            response = self.inventory_suite.inventory_status(inventory_id_1, VALIDATED)
            self.assertEqual(response.status_code, 200)

            self.assertEqual(InventoryItems.query.filter(
                InventoryItems.inventory_id == inventory_id_1
            ).count(), 2)
            self.assertEqual(PointSaleItem.query.filter(
                PointSaleItem.pointsale_id == self.pointsale_id
            ).count(), 2)
            pointsaleitem_1 = self.get_pointsaleitem(self.pointsale_id, self.good_id_1)
            pointsaleitem_2 = self.get_pointsaleitem(self.pointsale_id, self.good_id_2)
            self.assertEqual(pointsaleitem_1.count, count_after_1)
            self.assertEqual(pointsaleitem_2.count, count_after_2)


            response = self.inventory_suite.create_inventory(self.pointsale_id, self.number_2)
            self.assertEqual(response.status_code, 200)
            data = self._deserialize(response.data)
            inventory_id_2 = data['id']

            self.assertEqual(InventoryItems.query.filter(
                InventoryItems.inventory_id == inventory_id_2
            ).count(), 2)

            inventory_item_1 = self.get_inventoryitem(inventory_id_2, self.good_id_1)
            inventory_item_2 = self.get_inventoryitem(inventory_id_2, self.good_id_2)

            self.assertEqual(inventory_item_1.count_before, count_after_1)
            self.assertEqual(inventory_item_2.count_before, count_after_2)

            self.assertEqual(inventory_item_1.count_after, count_after_1)
            self.assertEqual(inventory_item_2.count_after, count_after_2)