Esempio n. 1
0
File: tests.py Progetto: tbson/24ho
 def test_transport_register(self):
     bols = BolUtils.seeding(3)
     for bol in bols:
         bol.wooden_box = True
         bol.cny_wooden_box_fee = 2
         bol.save()
         self.assertEqual(BolUtils.cal_wooden_box_fee(bol), 2)
Esempio n. 2
0
File: tests.py Progetto: tbson/24ho
 def test_transport_register(self):
     bols = BolUtils.seeding(3)
     for bol in bols:
         bol.shockproof = True
         bol.cny_shockproof_fee = 2
         bol.save()
         self.assertEqual(BolUtils.cal_shockproof_fee(bol), 2)
Esempio n. 3
0
File: tests.py Progetto: 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
Esempio n. 4
0
    def save(self, *args, **kwargs):
        from .utils import OrderUtils
        from apps.bol.utils import BolUtils

        if not self._state.adding:
            self = OrderUtils.check_order_for_frozen(self)

            BolUtils.update_order_service(self)

        if self._state.adding and self.address and not self.uid:
            self.uid = OrderUtils.get_next_uid(self.address)

            self.customer = self.address.customer
            deposit_factor = self.customer.deposit_factor
            if not deposit_factor or deposit_factor < 0 or deposit_factor > 90:
                self.deposit_factor = settings.DEPOSIT_FACTOR
            else:
                self.deposit_factor = self.customer.deposit_factor

        if self._state.adding and self.address:
            customer = self.address.customer
            if not self.sale:
                self.sale = customer.sale
            if not self.cust_care:
                self.cust_care = customer.cust_care

        if self.purchase_code:
            self.purchase_code = self.purchase_code.strip()

        self.customer = self.address.customer

        if not Tools.is_testing():
            self.__dict__.update(OrderUtils.cal_all(self))
        super(Order, self).save(*args, **kwargs)
Esempio n. 5
0
File: tests.py Progetto: 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)
Esempio n. 6
0
File: tests.py Progetto: tbson/24ho
 def test_normal_case(self):
     bols = BolUtils.seeding(3)
     order = OrderUtils.seeding(1, True)
     for bol in bols:
         bol.order = order
         bol.save()
     self.assertEqual(OrderUtils.cal_delivery_fee(order), 6)
Esempio n. 7
0
File: utils.py Progetto: tbson/24ho
 def cal_delivery_fee(item: models.QuerySet) -> float:
     from apps.bol.utils import BolUtils
     # sum of bols's delivery fee
     return sum([
         BolUtils.cal_delivery_fee(bol)['delivery_fee']
         for bol in item.order_bols.all()
     ])
Esempio n. 8
0
File: tests.py Progetto: tbson/24ho
 def test_normal_case(self):
     bols = BolUtils.seeding(3)
     order = OrderUtils.seeding(1, True)
     for bol in bols:
         bol.order = order
         bol.cny_sub_fee = 2
         bol.save()
     self.assertEqual(order.cny_sub_fee, 6)
     self.assertEqual(OrderUtils.cal_sub_fee(order), 6)
Esempio n. 9
0
File: tests.py Progetto: tbson/24ho
 def test_with_register(self):
     bols = BolUtils.seeding(3)
     order = OrderUtils.seeding(1, True)
     order.wooden_box = True
     order.save()
     for bol in bols:
         bol.order = order
         bol.cny_wooden_box_fee = 2
         bol.save()
     self.assertEqual(order.cny_wooden_box_fee, 6)
     self.assertEqual(OrderUtils.cal_wooden_box_fee(order), 6)
Esempio n. 10
0
File: tests.py Progetto: tbson/24ho
 def test_without_register(self):
     bols = BolUtils.seeding(3)
     order = OrderUtils.seeding(1, True)
     order.shockproof = False
     order.save()
     for bol in bols:
         bol.order = order
         bol.cny_shockproof_fee = 2
         bol.save()
     self.assertEqual(order.cny_shockproof_fee, 0)
     self.assertEqual(OrderUtils.cal_shockproof_fee(order), 0)
Esempio n. 11
0
File: tests.py Progetto: tbson/24ho
    def test_no_items(self):
        bol = BolUtils.seeding(1, True)
        order = OrderUtils.seeding(1, True)

        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))
Esempio n. 12
0
File: tests.py Progetto: tbson/24ho
    def test_after_exporting_order(self):
        bol = BolUtils.seeding(1, True)
        order = OrderUtils.seeding(1, True)
        order.status = Status.EXPORTED
        order.do_not_check_exported = True

        bol.order = order
        bol.save()

        order.do_not_check_exported = True
        order.save()

        with self.assertRaises(ValidationError) as context:
            OrderUtils.get_items_for_checking(bol.uid)
        self.assertTrue(
            error_messages['ORDER_AFTER_EXPORTING'] in str(context.exception))
Esempio n. 13
0
File: tests.py Progetto: tbson/24ho
    def test_pending_order(self):
        bol = BolUtils.seeding(1, True)
        order = OrderUtils.seeding(1, True)
        order.pending = True
        order.do_not_check_pending = True

        bol.order = order
        bol.save()

        order.do_not_check_pending = True
        order.save()

        with self.assertRaises(ValidationError) as context:
            OrderUtils.get_items_for_checking(bol.uid)
        self.assertTrue(
            error_messages['ORDER_WAS_PENDING'] in str(context.exception))
Esempio n. 14
0
File: tests.py Progetto: 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))
Esempio n. 15
0
File: tests.py Progetto: 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)
Esempio n. 16
0
File: tests.py Progetto: 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))
Esempio n. 17
0
File: tests.py Progetto: 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)
Esempio n. 18
0
File: tests.py Progetto: tbson/24ho
    def test_update_shockproof(self):
        order = OrderUtils.seeding(1, True)
        order.shockproof = True
        order.wooden_box = True
        order.count_check = True
        order.save()

        bols = BolUtils.seeding(3)

        for bol in bols:
            self.assertEqual(bol.shockproof, False)
            self.assertEqual(bol.wooden_box, False)
            self.assertEqual(bol.shockproof, False)

        for bol in bols:
            bol.order = order
            bol.save()

        for bol in bols:
            self.assertEqual(bol.shockproof, True)
            self.assertEqual(bol.wooden_box, True)
            self.assertEqual(bol.shockproof, True)
Esempio n. 19
0
File: utils.py Progetto: tbson/24ho
 def cal_wooden_box_fee(item: models.QuerySet) -> float:
     from apps.bol.utils import BolUtils
     # sum of bols's wooden box fee
     return sum([
         BolUtils.cal_wooden_box_fee(bol) for bol in item.order_bols.all()
     ])
Esempio n. 20
0
File: utils.py Progetto: tbson/24ho
 def cal_shockproof_fee(item: models.QuerySet) -> float:
     from apps.bol.utils import BolUtils
     # sum of bols's shockproof fee
     return sum([
         BolUtils.cal_shockproof_fee(bol) for bol in item.order_bols.all()
     ])
Esempio n. 21
0
 def retrieve_to_print_transport(receipt: models.QuerySet) -> dict:
     from apps.bol.utils import BolUtils
     bols = BolUtils.calculate_transport_bol_fee(receipt.receipt_bols.all())
     return {'bols': bols}
Esempio n. 22
0
 def retrieve_to_print_order(receipt: models.QuerySet) -> dict:
     from apps.bol.utils import BolUtils
     orders = BolUtils.calculate_order_remain(receipt.receipt_orders.all())
     return {'orders': orders}