示例#1
0
 def post(self, request):
     user_profile = UserProfile.objects.get(badge=request.POST.get('badge'))
     user = user_profile.user
     item = Item.objects.get(code=request.POST.get('code'))
     sale = Sale(user=user)
     sale.save()
     sl = SaleLine(quantity=1, item=item, sale=sale)
     sl.save()
     t = Transaction(user=user, amount=-sale.total)
     t.save()
     return HttpResponse()
示例#2
0
def add_employee_sales():
    if not current_user.is_authenticated:
        return redirect(url_for('login'))
    # add employee sales to database
    # declare the Sale Form
    form = SaleForm(request.form)
    msg = None
    # check if both http method is POST and form is valid on submit
    if form.validate_on_submit():
        # assign form data to variables
        quantity = request.form.get('quantity', 0, type=int)
        request_id = request.form.get('request_item', 0, type=int)
        # request_id = int(form.request_item.value)
        # print (request_id)
        sale = Sale(current_user.id, request_id, quantity)
        sale.save()
        flash('Sale entry successfully created!')
    else:
        flash('I am sorry but the details you entered cannot be saved :(')
    return redirect(f'/psalm2vs8/employee-requests/sales/{request_id}')
示例#3
0
    def post(self):
        '''Create a sale'''
        parser = reqparse.RequestParser()
        parser.add_argument('buyer_name',
                            help='The product field cannot be blank',
                            required=True,
                            type=str)
        data = parser.parse_args()
        logged_in_user = User.get_by_id(get_jwt_identity())['username']
        sale = Sale(id=None,
                    buyer_name=data['buyer_name'],
                    status='open',
                    created_by=logged_in_user,
                    date_created=str(datetime.now()),
                    date_modified=str(datetime.now()))

        sale.save()
        posted_sale = dict(buyer_name=data['buyer_name'],
                           status='open',
                           created_by=User.get_by_id(id=get_jwt_identity()),
                           date_created=str(datetime.now()),
                           date_modified=str(datetime.now()))
        return {"message": "Sale created", "data": posted_sale}