示例#1
0
文件: tests.py 项目: tbson/24ho
    def setUp(self):
        self.order = OrderUtils.seeding(1, True)
        self.order.status = Status.NEW

        self.staff = StaffUtils.seeding(1, True)

        OrderItemUtils.seeding(1, order=self.order)
        BolUtils.seeding(1, order=self.order)

        OrderUtils.force_cal(self.order)
示例#2
0
文件: views.py 项目: tbson/24ho
 def batch_update(self, request, pk=None):
     order = get_object_or_404(Order, pk=pk)
     value = request.data.get('value', 0)
     extra = request.data.get('extra', [])
     ids = extra.get('ids', [])
     field = extra.get('field', '')
     params = {}
     params[field] = value
     OrderItemUtils.batch_update(order, ids, params)
     return res({})
示例#3
0
文件: tests.py 项目: tbson/24ho
    def test_success(self):
        customer = CustomerUtils.seeding(1, True)
        customer.deposit_factor = 50
        customer.save()

        order = OrderUtils.seeding(1, True, customer=customer)
        OrderItemUtils.seeding(1, True, order=order)

        deposit_amount = OrderUtils.get_deposit_amount(order)
        vnd_total = OrderUtils.get_vnd_total(OrderBaseSr(order).data)
        self.assertEqual(OrderUtils.get_remain_after_deposit_amount(order),
                         int(vnd_total) - deposit_amount)
示例#4
0
文件: tests.py 项目: tbson/24ho
    def setUp(self):
        self.customer = CustomerUtils.seeding(1, True)
        self.staff = StaffUtils.seeding(1, True)

        self.order = OrderUtils.seeding(1, True, customer=self.customer)
        self.order.status = Status.NEW

        OrderItemUtils.seeding(1, True, order=self.order)

        self.bol = BolUtils.seeding(1, True, order=self.order)
        self.bol.mass = 5
        self.bol.save()

        OrderUtils.force_cal(self.order)
示例#5
0
文件: tests.py 项目: tbson/24ho
    def setUp(self):
        # Add order items
        order_items = OrderItemUtils.seeding(2)
        self.order = order_items[0].order
        self.order.status = Status.NEW
        self.order.save()

        # Add bol
        self.bol = BolUtils.seeding(1, True)
        self.bol1 = BolUtils.seeding(2, True)
        self.bol2 = BolUtils.seeding(3, True)

        self.bol.order = self.order
        self.bol1.order = self.order
        self.bol2.order = self.order

        self.bol.save()
        self.bol1.save()
        self.bol2.save()

        order_items[0].quantity = 4
        order_items[0].checked_quantity = 4
        order_items[0].save()

        order_items[1].quantity = 5
        order_items[1].checked_quantity = 5
        order_items[1].save()

        self.order_items = order_items
示例#6
0
文件: tests.py 项目: tbson/24ho
    def test_missing(self):
        order = OrderUtils.seeding(1, True)
        order_items = OrderItemUtils.seeding(3)

        checked_input = {}
        checked_input[str(order_items[0].pk)] = 1
        checked_input[str(order_items[1].pk)] = 2
        checked_input[str(order_items[2].pk)] = 1

        for order_item in order_items:
            order_item.order = order
            order_item.save()

        result = OrderUtils.check(order, checked_input)

        checked = OrderItem.objects.filter(order_id=order.pk)

        missing = {}
        missing[str(order_items[2].pk)] = 2

        for checked_item in checked:
            self.assertEqual(checked_item.checked_quantity,
                             checked_input[str(checked_item.pk)])
        self.assertEqual(result, missing)
        self.assertEqual(order.pending, True)
示例#7
0
文件: tests.py 项目: tbson/24ho
    def test_normal_case(self):
        order = OrderUtils.seeding(1, True)
        OrderItemUtils.seeding(2, order=order)

        staff = StaffUtils.seeding(1, True)
        TransactionUtils.recharge(100000000, MoneyType.CASH, order.customer, staff)
        self.assertEqual(Transaction.objects.count(), 1)

        TransactionUtils.deposit(order, staff)
        transaction = Transaction.objects.first()

        self.assertEqual(Transaction.objects.count(), 2)
        self.assertEqual(transaction.order, order)
        self.assertEqual(transaction.staff, staff)
        self.assertEqual(transaction.customer, order.customer)
        self.assertEqual(transaction.amount, OrderUtils.get_deposit_amount(order))
        self.assertEqual(transaction.type, Type.DEPOSIT)
示例#8
0
文件: tests.py 项目: tbson/24ho
    def test_item_order_not_found(self):
        order = OrderUtils.seeding(1, True)
        order_items = OrderItemUtils.seeding(3)
        order_item_4 = OrderItemUtils.seeding(4, True)

        for order_item in order_items:
            order_item.order = order
            order_item.save()

        checked_input = {}
        checked_input[str(order_items[0].pk)] = 1
        checked_input[str(order_items[1].pk)] = 2
        checked_input[str(order_items[2].pk)] = 3
        checked_input[str(order_item_4.pk)] = 4

        with self.assertRaises(ValidationError) as context:
            OrderUtils.check(order, checked_input)
        self.assertTrue(
            error_messages['ITEM_ORDER_NOT_FOUND'] in str(context.exception))
示例#9
0
文件: tests.py 项目: tbson/24ho
    def test_count_check(self):
        CountCheckUtils.seeding(5)
        orderItems = OrderItemUtils.seeding(15)

        item = orderItems[0].order
        item.count_check = False
        item.save()

        output = OrderUtils.cal_count_check_fee(item)
        eput = 0

        self.assertEqual(output, eput)
示例#10
0
文件: tests.py 项目: tbson/24ho
    def test_manual_input(self):
        CountCheckUtils.seeding(5)
        orderItems = OrderItemUtils.seeding(5)

        item = orderItems[0].order
        item.count_check = True
        item.count_check_fee_input = 5
        item.save()

        output = OrderUtils.cal_count_check_fee(item)
        eput = 5

        self.assertEqual(output, eput)
示例#11
0
文件: tests.py 项目: tbson/24ho
    def test_no_manual_input_out_range(self):
        CountCheckUtils.seeding(5)
        orderItems = OrderItemUtils.seeding(5)

        item = orderItems[0].order
        item.count_check = True
        item.count_check_fee_input = 0
        item.save()

        output = OrderUtils.cal_count_check_fee(item)
        eput = settings.DEFAULT_COUNT_CHECK_PRICE

        self.assertEqual(output, eput)
示例#12
0
文件: tests.py 项目: tbson/24ho
    def setUp(self):
        order_items = OrderItemUtils.seeding(2)
        self.order = order_items[0].order
        self.order.do_not_check_pending = True

        order_items[0].quantity = 4
        order_items[0].checked_quantity = 2
        order_items[0].save()

        order_items[1].quantity = 5
        order_items[1].checked_quantity = 1
        order_items[1].save()

        self.order_items = order_items
        self.order.pending = True
        self.order.do_not_check_pending = True
        self.order.save()
示例#13
0
文件: tests.py 项目: tbson/24ho
    def test_order_item_missing(self):
        order = OrderUtils.seeding(1, True)
        order_items = OrderItemUtils.seeding(3)

        for order_item in order_items:
            order_item.order = order
            order_item.save()

        checked_input = {}
        checked_input[str(order_items[0].pk)] = 1
        checked_input[str(order_items[1].pk)] = 2
        checked_input[str(99)] = 2

        with self.assertRaises(ValidationError) as context:
            OrderUtils.check(order, checked_input)
        self.assertTrue(
            error_messages['ORDER_ITEM_MISSING'] in str(context.exception))
示例#14
0
文件: tests.py 项目: tbson/24ho
    def test_have_items_but_all_zero(self):
        bol = BolUtils.seeding(1, True)
        order = OrderUtils.seeding(1, True)

        order_items = OrderItemUtils.seeding(3)
        for order_item in order_items:
            order_item.order = order
            order_item.quantity = 0
            order_item.save()

        bol.order = order
        bol.save()

        with self.assertRaises(ValidationError) as context:
            OrderUtils.get_items_for_checking(bol.uid)
        self.assertTrue(
            error_messages['ORDER_ITEM_NOT_FOUND'] in str(context.exception))
示例#15
0
文件: tests.py 项目: tbson/24ho
    def test_extra(self):
        order = OrderUtils.seeding(1, True)
        order_items = OrderItemUtils.seeding(3)

        checked_input = {}
        checked_input[str(order_items[0].pk)] = 4
        checked_input[str(order_items[1].pk)] = 2
        checked_input[str(order_items[2].pk)] = 3

        for order_item in order_items:
            order_item.order = order
            order_item.save()

        with self.assertRaises(ValidationError) as context:
            OrderUtils.check(order, checked_input)
        self.assertTrue(
            error_messages['CHECKED_QUANTITY_LARGER_THAN_ORIGINAL_QUANTITY'] in
            str(context.exception))
示例#16
0
文件: tests.py 项目: tbson/24ho
    def test_normal_case(self):
        bol = BolUtils.seeding(1, True)
        order = OrderUtils.seeding(1, True)

        order_items = OrderItemUtils.seeding(3)
        for order_item in order_items:
            order_item.order = order
            order_item.save()

        order_items[0].quantity = 0
        order_items[0].save()

        bol.order = order
        bol.save()

        result = OrderUtils.get_items_for_checking(bol.uid)

        self.assertEqual(result.count(), len(order_items) - 1)
示例#17
0
文件: tests.py 项目: tbson/24ho
    def test_wrong_order(self):
        order = OrderUtils.seeding(1, True)
        order2 = OrderUtils.seeding(2, True)
        order_items = OrderItemUtils.seeding(3)

        checked_input = {}
        checked_input[str(order_items[0].pk)] = 1
        checked_input[str(order_items[1].pk)] = 2
        checked_input[str(order_items[2].pk)] = 3

        for order_item in order_items:
            order_item.order = order
            order_item.save()

        order_items[0].order = order2
        order_items[0].save()

        with self.assertRaises(ValidationError) as context:
            OrderUtils.check(order, checked_input)
        self.assertTrue(error_messages['ORDER_MISSING_IN_ORDER_ITEM'] in str(
            context.exception))
示例#18
0
文件: tests.py 项目: tbson/24ho
    def test_integration(self):
        token = TestHelpers.test_setup()
        client = APIClient()
        client.credentials(HTTP_AUTHORIZATION='JWT ' + token)

        bol = BolUtils.seeding(1, True)
        order = OrderUtils.seeding(1, True)

        order_items = OrderItemUtils.seeding(3)
        for order_item in order_items:
            order_item.order = order
            order_item.save()

        bol.order = order
        bol.save()

        response = client.get(
            "/api/v1/order/get-order-items-for-checking/{}".format(bol.uid))
        self.assertEqual(response.status_code, 200)
        response = response.json()
        self.assertEqual(response['count'], len(order_items))
示例#19
0
文件: tests.py 项目: tbson/24ho
    def test_normal_case(self):
        order = OrderUtils.seeding(1, True)

        bols = BolUtils.seeding(3)
        for bol in bols:
            bol.order = order
            bol.packages = 1
            bol.save()

        order_items = OrderItemUtils.seeding(3)
        for order_item in order_items:
            order_item.order = order
            order_item.save()

        order_items[1].url = order_items[0].url
        order_items[1].save()

        eput = {"links": 2, "quantity": 6, "packages": 3}
        output = OrderUtils.cal_statistics(order)
        self.assertEqual(order.statistics, eput)
        self.assertEqual(output, eput)
示例#20
0
文件: tests.py 项目: tbson/24ho
 def test_normal_case(self):
     order_items = OrderItemUtils.seeding(3)
     order = order_items[0].order
     self.assertEqual(OrderUtils.cal_amount(order), 77)
示例#21
0
文件: views.py 项目: tbson/24ho
 def add(self, request):
     data, order_items = OrderUtils.prepare_data(request.data)
     order = OrderUtils.validate_create(data)
     OrderItemUtils.validate_bulk_create(order_items, order.id)
     return res(OrderBaseSr(order).data)