Esempio n. 1
0
    def update(self, request, *args, **kwargs):
        pkfield = kwargs.get(self.model._meta.pk.name) or request.data.get(
            self.model._meta.pk.name)

        if not pkfield or request.data is None:
            return rc.BAD_REQUEST

        try:
            obj = self.model.objects.get(pk=pkfield)
        except self.model.ObjectDoesNotExist:
            return rc.NOT_FOUND

        if not self.check_instance_permission(request, obj, "w"):
            return rc.FORBIDDEN

        attrs = self.flatten_dict(request)

        form = self.form(instance=obj, **attrs)
        if form.is_valid():
            opportunity = form.save(commit=False)
            convert(opportunity, 'amount')
            return opportunity
        else:
            self.status = 400
            return form.errors
Esempio n. 2
0
    def create(self, request, object_ptr, *args, **kwargs):
        if request.data is None:
            return rc.BAD_REQUEST

        order = getOrNone(SaleOrder, pk=object_ptr)
        if not order:
            return rc.NOT_FOUND

        if not request.user.get_profile().has_permission(order, mode='x'):
            return rc.FORBIDDEN

        ordered_product = OrderedProduct()
        ordered_product.order = order
        form = OrderedProductForm(request.user.get_profile(),
                                  order,
                                  request.data,
                                  instance=ordered_product)
        if form.is_valid():
            ordered_product = form.save(commit=False)
            convert(ordered_product,
                    'rate',
                    currency=ordered_product.order.currency)
            ordered_product.set_user_from_request(request)
            ordered_product.order.update_total()
            return ordered_product
        else:
            self.status = 400
            return form.errors
Esempio n. 3
0
    def update(self, request, *args, **kwargs):

        pkfield = kwargs.get(self.model._meta.pk.name) or request.data.get(
            self.model._meta.pk.name)

        if not pkfield:
            return rc.BAD_REQUEST

        try:
            obj = self.model.objects.get(pk=pkfield)
        except ObjectDoesNotExist:
            return rc.NOT_FOUND

        form = self.form(request.user.get_profile(),
                         None,
                         None,
                         request.data,
                         instance=obj)
        if form.is_valid():
            transaction = form.save(commit=False)
            convert(transaction, 'value')
            return transaction
        else:
            self.status = 400
            return form.errors
Esempio n. 4
0
    def create(self, request, *args, **kwargs):
        if request.data is None:
            return rc.BAD_REQUEST

        # if not self.check_create_permission(request, "x"):
        #    return rc.FORBIDDEN

        transaction = self.model()
        form = self.form(
            request.user.get_profile(), None, None, request.POST, instance=transaction)
        if form.is_valid():
            transaction = form.save(commit=False)
            convert(transaction, 'value')
            transaction.set_user_from_request(request)
            if request.data.has_key("order"):
                try:
                    order = SaleOrder.objects.get(pk=request.data['order'])
                    order.payment.add(transaction)
                    order.save()
                except:
                    pass
            return transaction
        else:
            self.status = 400
            return form.errors
Esempio n. 5
0
    def create(self, request, *args, **kwargs):
        if request.data is None:
            return rc.BAD_REQUEST

        # if not self.check_create_permission(request, "x"):
        #    return rc.FORBIDDEN

        transaction = self.model()
        form = self.form(request.user.get_profile(),
                         None,
                         None,
                         request.POST,
                         instance=transaction)
        if form.is_valid():
            transaction = form.save(commit=False)
            convert(transaction, 'value')
            transaction.set_user_from_request(request)
            if request.data.has_key("order"):
                try:
                    order = SaleOrder.objects.get(pk=request.data['order'])
                    order.payment.add(transaction)
                    order.save()
                except:
                    pass
            return transaction
        else:
            self.status = 400
            return form.errors
Esempio n. 6
0
    def create(self, request, object_ptr, *args, **kwargs):
        if request.data is None:
            return rc.BAD_REQUEST

        order = getOrNone(SaleOrder, pk=object_ptr)
        if not order:
            return rc.NOT_FOUND

        if not request.user.get_profile().has_permission(order, mode='x'):
            return rc.FORBIDDEN

        ordered_product = OrderedProduct()
        ordered_product.order = order
        form = OrderedProductForm(
            request.user.get_profile(), order, request.data, instance=ordered_product)
        if form.is_valid():
            ordered_product = form.save(commit=False)
            convert(
                ordered_product, 'rate', currency=ordered_product.order.currency)
            ordered_product.set_user_from_request(request)
            ordered_product.order.update_total()
            return ordered_product
        else:
            self.status = 400
            return form.errors
Esempio n. 7
0
    def update(self, request, *args, **kwargs):
        pkfield = kwargs.get(self.model._meta.pk.name) or request.data.get(
            self.model._meta.pk.name)

        if not pkfield or request.data is None:
            return rc.BAD_REQUEST

        try:
            obj = self.model.objects.get(pk=pkfield)
        except self.model.ObjectDoesNotExist:
            return rc.NOT_FOUND

        if not self.check_instance_permission(request, obj, "w"):
            return rc.FORBIDDEN

        attrs = self.flatten_dict(request)

        form = self.form(instance=obj, **attrs)
        if form.is_valid():
            opportunity = form.save(commit=False)
            convert(opportunity, 'amount')
            return opportunity
        else:
            self.status = 400
            return form.errors
Esempio n. 8
0
    def create(self, request, *args, **kwargs):
        if request.data is None:
            return rc.BAD_REQUEST

        if not self.check_create_permission(request, "x"):
            return rc.FORBIDDEN

        account = Account()
        form = AccountForm(request.user.get_profile(), request.data, instance=account)
        if form.is_valid():
            account = form.save(commit=False)
            convert(account, 'balance')
            account.set_user_from_request(request)
            return account
        else:
            self.status = 400
            return form.errors
Esempio n. 9
0
    def create(self, request, *args, **kwargs):
        if request.data is None:
            return rc.BAD_REQUEST

        if not self.check_create_permission(request, "x"):
            return rc.FORBIDDEN

        attrs = self.flatten_dict(request)

        form = self.form(**attrs)
        if form.is_valid():
            opportunity = form.save(commit=False)
            convert(opportunity, 'amount')
            opportunity.set_user_from_request(request)
            return opportunity
        else:
            self.status = 400
            return form.errors
Esempio n. 10
0
    def update(self, request, object_ptr, *args, **kwargs):
        if request.data is None:
            return rc.BAD_REQUEST

        ordered_product = getOrNone(OrderedProduct, pk=object_ptr)
        if not request.user.get_profile().has_permission(ordered_product, mode="w"):
            return rc.FORBIDDEN

        order = ordered_product.order
        form = OrderedProductForm(request.user.get_profile(), order, request.data, instance=ordered_product)
        if form.is_valid():
            ordered_product = form.save(commit=False)
            convert(ordered_product, "rate", currency=ordered_product.order.currency)
            ordered_product.order.update_total()
            return ordered_product
        else:
            self.status = 400
            return form.errors
Esempio n. 11
0
    def create(self, request, *args, **kwargs):
        if request.data is None:
            return rc.BAD_REQUEST

        if not self.check_create_permission(request, "x"):
            return rc.FORBIDDEN

        attrs = self.flatten_dict(request)

        form = self.form(**attrs)
        if form.is_valid():
            opportunity = form.save(commit=False)
            convert(opportunity, "amount")
            opportunity.set_user_from_request(request)
            return opportunity
        else:
            self.status = 400
            return form.errors
Esempio n. 12
0
    def create(self, request, *args, **kwargs):
        if request.data is None:
            return rc.BAD_REQUEST

        #if not self.check_create_permission(request, "x"):
        #    return rc.FORBIDDEN

        liability = self.model()
        form = self.form(request.user.get_profile(), request.data, instance=liability)
        if form.is_valid():
            liability = form.save(commit=False)
            liability.source = liability.account.owner
            convert(liability,'value')
            liability.set_user_from_request(request)
            return liability
        else:
            self.status = 400
            return form.errors
Esempio n. 13
0
    def update(self, request, *args, **kwargs):

        pkfield = kwargs.get(self.model._meta.pk.name) or request.data.get(self.model._meta.pk.name)

        if not pkfield:
            return rc.BAD_REQUEST

        try:
            obj = self.model.objects.get(pk=pkfield)
        except ObjectDoesNotExist:
            return rc.NOT_FOUND

        form = self.form(request.user.get_profile(), None, None, request.data, instance=obj)
        if form.is_valid():
            transaction = form.save(commit=False)
            convert(transaction, 'value')
            return transaction
        else:
            self.status = 400
            return form.errors