Exemplo n.º 1
0
def mobile_register_company(request):
    if request.method == 'POST':

        form = CompanyForm(request.POST, request.FILES)
        if form.is_valid():

            company = form.save(False)
            company.created_by = request.user
            form.save()

            # add 'admin' permissions for the user that registered this company
            default_permission = Permission(
                created_by=request.user,
                user=request.user,
                company=company,
                permission='admin',
            )
            default_permission.save()

            return JsonOk(extra=company_to_dict(request.user, company, True, True))

        else:
            print form.errors.as_data().keys()
            return JsonError(message='register failed', extra=form.errors.as_data().keys())

    return JsonResponse({'error': "should not happen"})
Exemplo n.º 2
0
def handle_invitation(request, reference, user_response, mobile=False):
    try:
        action = Action.objects.get(receiver=request.user.email,
                                    reference=reference,
                                    status=g.ACTION_WAITING)
    except Action.DoesNotExist:  # wtf?
        return redirect('web:select_company')

    # if the invite has been accepted, create a new permission
    if user_response == g.ACTION_ACCEPTED:
        data = json.loads(action.data)
        permission = data.get('permission')
        if permission not in g.PERMISSION_TYPES:
            permission = g.PERMISSION_TYPES[0]

        # get the user that sent the invite and select it as the user that created the permission
        try:
            sender = BlocklogicUser.objects.get(email=action.sender)
        except BlocklogicUser.DoesNotExist:
            sender = request.user

        new_permission = Permission(
            created_by=sender,
            user=request.user,
            company=action.company,
            permission=permission
        )
        # new_permission.create_pin(False)
        new_permission.save()

    # else: if the invite was declined, just update its status (which must be done anyway)
    action.status = user_response
    action.save()
    if mobile:
        return JsonOk()
    else:
        return redirect('web:select_company')
Exemplo n.º 3
0
        query_string = urllib.urlencode(my_dict)
        query_dict = QueryDict(query_string)

        form = CompanyForm(query_dict)

        if form.is_valid():
            company = form.save(False)
            company.created_by = new_user
            form.save()

            # add 'admin' permissions for the user that registered this company
            default_permission = Permission(
                created_by=new_user,

                user=new_user,
                company=company,
                permission='admin',
            )
            default_permission.save()

            print "New company successfully created..."
        else:
            print "---"
            print "Company form not valid"
            print form.errors

            Company.objects.get(url_name='neko-podjetje').delete()

            raise Exception
Exemplo n.º 4
0
def create_company_defaults(user, company):
    """ creates all initial data for a new company; """
    # permissions
    # add 'admin' permissions for the user that registered this company
    default_permission = Permission(
        created_by=user,

        user=user,
        company=company,
        permission='admin',
    )
    default_permission.save()
        ## assign pin number
        #default_permission.create_pin()
    
    # taxes
    # create a set of taxes depending on company's country
    if company.country == 'SI':
        tax = Tax(created_by=user, company=company, amount=22.0, name='Splošno', default=True)
        tax.save()
        
        tax = Tax(created_by=user, company=company, amount=9.5, name='Znižana', default=False)
        tax.save()
        
        tax = Tax(created_by=user, company=company, amount=0, name='Brez', default=False)
        tax.save()

    # categories
    # create a fixed set of categories: {name, description, color, [children]}
    default_categories = [
        [
            _("Foods"), _("Everything edible"), 10, [
                # [_("Bread"), _("Stuff from the oven"), 1, []],
                [_("Vegetables"), _("Oh so healthy"), 6, []],
                [_("Fruit"), _("Oh so healthy"), 3, []],
            ]
        ],
        [_("Drinks"), _("For the thirsty"), 9, []]
    ]
    
    def add_category(data, parent=None):
        cat = Category(
            created_by=user,
            company=company,
            parent=parent,
            name=data[0],
            description=data[1],
            color=g.CATEGORY_COLORS[data[2]]
        )
        cat.save()
        
        for child in data[3]:
            add_category(child, cat)
    
    for c in default_categories:
        add_category(c)
        
    # cash register
    # create a default, A4 cash register with data from company
    register = Register(
        created_by=user,
        company=company,
        name=_("Default"),
        receipt_format=g.RECEIPT_FORMATS[0][0],
        receipt_type=g.RECEIPT_TYPES[0][0],
        location="",
        print_location=False,
        printer_driver=g.PRINTER_DRIVERS[0][0])
    register.save()