예제 #1
0
    def create(self, request):
        
        serializer = CustomerSerializer(data=request.data)

        if serializer.is_valid():
            customer = Customer()
            customer.name = serializer['name'].value
            customer.zipcode = serializer['zipcode'].value

            #Call BOB Api
            r = requests.get(BOB_API_URL.format(customer.zipcode))
            if r.status_code == 200 and r.json()['results']:
                print("ZipCode found")
                ret = r.json()['results'][0]
                customer.street = ret['street']
                customer.state = ret['state']
                customer.city = ret['city']
            else:
                print("zipCode not found on BOB_API")


            self.perform_create(customer)

        headers = self.get_success_headers(serializer.data)
        return Response(serializer.data, status=status.HTTP_201_CREATED, headers=headers)
예제 #2
0
    def test_save(self):
        cust = Customer()
        cust.name = "test name"
        cust.zipcode = 666
        cust.save()

        self.assertEquals(cust.id, 1)
예제 #3
0
def customer_create(request):
    params = json.loads(request.body.decode("utf-8"))
    data = {}

    blacklist = Blacklist.objects.all()
    for man in blacklist:
        nameRatio = fuzz.partial_ratio(man.name, params['name'])
        nationRatio = fuzz.partial_ratio(man.nationality, params['nation'])
        addrRatio = fuzz.partial_ratio(man.address, params['address'])
        print(nameRatio, addrRatio, nationRatio)
        if (nameRatio > 70 or addrRatio > 80
                or (nameRatio + nationRatio) > 170):
            log = AlertLog()
            log.name = params['name']
            log.operate = '開戶'
            log.reason = '疑似為高風險或黑名單人物'
            log.save()
            return common_response(data, message='黑名單人物')

    try:
        with transaction.atomic():
            distrcit = District.objects.get(id=params['district']['id'])
            customer = Customer()
            customer.name = params['name']
            customer.roc_id = params['roc_id']
            customer.gender = params['gender']
            customer.birthday = params['birthday']
            customer.cell_phone = params['cell_phone']
            customer.address = params['address']
            customer.district = distrcit
            customer.password = get_sha256_value(params['cell_phone'])
            customer.email = params['email']
            customer.save()
            data['id'] = customer.id

            # 產生帳戶號碼
            code = generate_16_digits_code()
            exist_codes = [account.code for account in Account.objects.all()]
            while code in exist_codes:
                code = generate_16_digits_code()

            # 新增帳戶
            account = Account()
            account.code = code
            account.customer = Customer.objects.get(id=customer.id)

            # 預設第1筆(新台幣)
            currency_list = Currency.objects.filter(id=1)
            if len(currency_list) != 0:
                account.currency = currency_list[0]
            account.save()

        return common_response(data)
    except Exception as e:
        return common_response(data, message=str(e))
예제 #4
0
def add_customer_details(request):

    if request.method == 'POST':
        customer = Customer()
        name = request.POST.get('name')
        mail = request.POST.get('email')
        phone_number = request.POST.get('contact')
        address = request.POST.get('comment')
        customer.name = name
        customer.mail = mail
        customer.phone_number = phone_number
        customer.address = address
        customer.save()
    return render(request, 'add_customer_details.html', {})