Beispiel #1
0
    def seeding(index: int,
                single: bool = False,
                save: bool = True) -> models.QuerySet:
        from .serializers import ReceiptBaseSr
        from .models import Type

        customer = CustomerUtils.seeding(1, True)
        staff = StaffUtils.seeding(1, True)
        address = AddressUtils.seeding(1, True)

        if index == 0:
            raise Exception('Indext must be start with 1.')

        def get_data(i: int) -> dict:
            data = {
                'customer': customer.pk,
                'staff': staff.pk,
                'address': address.pk,
                'type': Type.ORDER,
                'vnd_sub_fee': 1000 + i,
                'vnd_total': 10000 + i
            }
            if save is False:
                return data

            instance = ReceiptBaseSr(data=data)
            instance.is_valid(raise_exception=True)
            instance = instance.save()
            return instance

        def get_list_data(index):
            return [get_data(i) for i in range(1, index + 1)]

        return get_data(index) if single is True else get_list_data(index)
Beispiel #2
0
    def seeding(index: int, single: bool = False, save: bool = True, **kwargs) -> models.QuerySet:
        from .serializers import BolBaseSr

        if index == 0:
            raise Exception('Indext must be start with 1.')

        address = AddressUtils.seeding(1, True)

        def get_data(i: int) -> dict:

            data = {
                'uid': "UID{}".format(i),
                'address': address.pk
            }

            _order = kwargs.get('order', None)
            if _order is not None:
                data['order'] = _order.pk

            if save is False:
                return data

            instance = BolBaseSr(data=data)
            instance.is_valid(raise_exception=True)
            instance = instance.save()
            return instance

        def get_list_data(index):
            return [get_data(i) for i in range(1, index + 1)]

        return get_data(index) if single is True else get_list_data(index)
Beispiel #3
0
    def test_not_blank_names(self):
        address = AddressUtils.seeding(1, True)
        sale = StaffUtils.seeding(2, True)
        cust_care = StaffUtils.seeding(3, True)
        approver = StaffUtils.seeding(4, True)

        data = {
            'uid': str(uuid.uuid4()),
            'address': address.id,
            'sale': sale.id,
            'cust_care': cust_care.id,
            'approver': approver.id,
            'shop_link': 'link1',
            'site': 'TAOBAO',
            'rate': 3400,
            'real_rate': 3300,
        }
        order = OrderBaseSr(data=data)
        order.is_valid(raise_exception=True)
        order.save()

        self.assertEqual(order.data['customer_name'], 'last1 first1')
        self.assertEqual(order.data['sale_name'], 'last2 first2')
        self.assertEqual(order.data['cust_care_name'], 'last3 first3')
        self.assertEqual(order.data['approver_name'], 'last4 first4')
Beispiel #4
0
    def column_to_row(column_dict: Dict, staff: models.QuerySet) -> List[Dict]:
        from apps.address.utils import AddressUtils
        from apps.bag.utils import BagUtils
        from .serializers import BolBaseSr
        from .models import Bol
        result: List = []
        for index in range(len(column_dict['uid'])):
            bag_uid = column_dict['bag_uid'][index]
            uid = column_dict['uid'][index]
            address_code = column_dict['address_code'][index]
            mass = column_dict['mass'][index]
            length = column_dict['length'][index]
            width = column_dict['width'][index]
            height = column_dict['height'][index]
            packages = column_dict['packages'][index]
            count_check = column_dict['count_check'][index]
            cny_shockproof_fee = column_dict['cny_shockproof_fee'][index]
            cny_wooden_box_fee = column_dict['cny_wooden_box_fee'][index]
            note = column_dict['note'][index]

            item = {
                'bag_uid': BagUtils.uid_to_pk(Tools.remove_special_chars(bag_uid, True)),
                'uid': Tools.remove_special_chars(uid, True),
                'address_code': AddressUtils.uid_to_pk(Tools.remove_special_chars(address_code, True)),
                'mass': Tools.string_to_float(mass),
                'length': Tools.string_to_float(length),
                'width': Tools.string_to_float(width),
                'height': Tools.string_to_float(height),
                'packages': Tools.string_to_int(packages),
                'count_check': Tools.string_to_bool(count_check),
                'cny_shockproof_fee': Tools.string_to_float(cny_shockproof_fee),
                'cny_wooden_box_fee': Tools.string_to_float(cny_wooden_box_fee),
                'note': note,
            }
            item['shockproof'] = bool(int(item['cny_shockproof_fee']))
            item['wooden_box'] = bool(int(item['cny_wooden_box_fee']))
            item['cn_date'] = Tools.now()
            item['staff_id'] = staff.pk
            if item['uid']:
                if item['address_code']:
                    item['address'] = item['address_code']
                if item['bag_uid']:
                    item['bag'] = item['bag_uid']
                del item['address_code']
                del item['bag_uid']

                try:
                    bol = Bol.objects.get(uid=item['uid'])
                    del item['uid']
                    print(item)
                    serializer = BolBaseSr(bol, data=item, partial=True)
                except Bol.DoesNotExist:
                    serializer = BolBaseSr(data=item)

                if serializer.is_valid(raise_exception=False):
                    serializer.save()
                    result.append(item)

        return result
Beispiel #5
0
    def test_normal_case(self):
        address = AddressUtils.seeding(1, True)
        address.uid = '1HN0'
        address.save()

        order = OrderUtils.seeding(1, True)
        order.address = address
        order.uid = '1HN001A5'
        order.save()

        date_now = timezone.now()
        uid, address_code, date = OrderUtils.prepare_next_uid(address)

        self.assertEqual(uid, order.uid)
        self.assertEqual(address_code, address.uid)
        self.assertEqual(date.day, date_now.day)
        self.assertEqual(date.month, date_now.month)
Beispiel #6
0
    def setUp(self):
        CustomerUtils.seeding(1, True)

        customer2 = CustomerUtils.seeding(2, True)
        user2 = TestHelpers.user_seeding(2, True)
        customer2.user_id = user2.pk
        customer2.save()

        address2 = AddressUtils.seeding(2, True)
        address2.customer = customer2
        address2.save()

        self.client = APIClient()
        self.client.credentials(HTTP_AUTHORIZATION='JWT ' +
                                TestHelpers.get_customer_token())

        self.items = OrderUtils.seeding(3)
        self.items[2].address = address2
        self.items[2].save()
Beispiel #7
0
    def test_address(self):
        address = AddressUtils.seeding(1, True)

        # Update not exist
        response = self.client.put(
            "/api/v1/order/{}/change-address/".format(0), {}, format='json')
        self.assertEqual(response.status_code, 404)

        # Update exist address
        response = self.client.put("/api/v1/order/{}/change-address/".format(
            self.item.pk), {"value": address.pk},
                                   format='json')
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.json()['address'], address.pk)

        # Update not exist address -> do not change original value
        response = self.client.put("/api/v1/order/{}/change-address/".format(
            self.item.pk), {"value": 9999},
                                   format='json')
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.json()['address'], address.pk)
Beispiel #8
0
    def seeding(index: int,
                single: bool = False,
                save: bool = True,
                **kwargs) -> models.QuerySet:
        from .serializers import OrderBaseSr

        address = AddressUtils.seeding(1, True)

        if index == 0:
            raise Exception('Indext must be start with 1.')

        def get_data(i: int) -> dict:
            data = {
                'uid': str(uuid.uuid4()),
                'address': address.id,
                'shop_link': "shop_link{}".format(i),
                'shop_nick': "shop_nick{}".format(i),
                'site': "site{}".format(i),
                'rate': 3400,
                'real_rate': 3300
            }

            _customer = kwargs.get('customer', None)
            if _customer is not None:
                data['customer'] = _customer.pk

            if save is False:
                return data

            instance = OrderBaseSr(data=data)
            instance.is_valid(raise_exception=True)
            instance = instance.save()
            return instance

        def get_list_data(index):
            return [get_data(i) for i in range(1, index + 1)]

        return get_data(index) if single is True else get_list_data(index)
Beispiel #9
0
    def test_normal_case(self):
        address = AddressUtils.seeding(1, True)
        customer = CustomerUtils.seeding(2, True)
        data = {
            'uid': str(uuid.uuid4()),
            'address': address.id,
            'shop_link': 'link1',
            'site': 'TAOBAO',
            'real_rate': 3300,
            'rate': 3400,
            'cny_amount': 100,
            'cny_order_fee': 5,
            'cny_inland_delivery_fee': 5.5,
            'cny_count_check_fee': 3,
            'cny_shockproof_fee': 3,
            'cny_wooden_box_fee': 3,
            'vnd_delivery_fee': 100000,
            'vnd_sub_fee': 20000,
            'cny_sub_fee': 12,
        }
        order = OrderBaseSr(data=data)
        order.is_valid(raise_exception=True)
        order_obj = order.save()

        self.assertEqual(order.data['vnd_total'], 567100)
        self.assertEqual(order.data['customer'], address.customer.pk)

        # Update address -> update customer
        address.customer = customer
        address.save()
        order = OrderBaseSr(order_obj,
                            data={'address': address.pk},
                            partial=True)
        order.is_valid(raise_exception=True)
        order.save()
        self.assertEqual(order.data['customer'], customer.pk)
Beispiel #10
0
 def setUp(self):
     self.address = AddressUtils.seeding(1, True)
     self.address_1 = AddressUtils.seeding(2, True)
Beispiel #11
0
 def test_normal_case(self):
     address = AddressUtils.seeding(1, True)
     output = OrderUtils.get_next_uid(address)
     eput = '1HN017I6'
     self.assertEqual(output, eput)