Ejemplo n.º 1
0
    def post(self, request, format=None):
        invoiceset = get_object_from_query_params('invoice_set',
                                                  request.query_params)

        amount, receivable_type, notes = get_values_from_credit_request(
            request.data)

        try:
            if amount and receivable_type:
                credit_invoiceset = invoiceset.create_credit_invoiceset_for_amount(
                    amount=amount,
                    receivable_type=receivable_type,
                    notes=notes)
            else:
                credit_invoiceset = invoiceset.create_credit_invoiceset(
                    receivable_type=receivable_type, notes=notes)
        except RuntimeError as e:
            raise APIException(e)

        credit_invoiceset_serializer = InvoiceSetSerializer(credit_invoiceset)

        result = {
            'invoiceset': credit_invoiceset_serializer.data,
            'invoices': [],
        }

        for credit_invoice in credit_invoiceset.invoices.all():
            result['invoices'].append(InvoiceSerializer(credit_invoice).data)

        return Response(result)
Ejemplo n.º 2
0
    def post(self, request, format=None):
        invoice_row = get_object_from_query_params('invoice_row',
                                                   request.query_params)

        amount = request.data.get('amount', None)

        if amount is not None:
            try:
                amount = Decimal(amount)
            except InvalidOperation:
                raise APIException(_('Invalid amount'))

            if amount.compare(Decimal(0)) != Decimal(1):
                raise APIException(_('Amount must be bigger than zero'))

        try:
            credit_invoice = invoice_row.invoice.create_credit_invoice(
                row_ids=[invoice_row.id], amount=amount)
        except RuntimeError as e:
            raise APIException(e)

        credit_invoice_serializer = InvoiceSerializer(credit_invoice)

        result = {
            'invoice': credit_invoice_serializer.data,
        }

        return Response(result)
Ejemplo n.º 3
0
    def post(self, request, format=None):
        invoice = get_object_from_query_params('invoice', request.query_params)
        amount, receivable_type, notes = get_values_from_credit_request(
            request.data)

        try:
            credit_invoice = invoice.create_credit_invoice(
                amount=amount, receivable_type=receivable_type, notes=notes)
        except RuntimeError as e:
            raise APIException(e)

        credit_invoice_serializer = InvoiceSerializer(credit_invoice)

        result = {
            'invoice': credit_invoice_serializer.data,
        }

        return Response(result)
Ejemplo n.º 4
0
    def post(self, request, format=None):
        invoice = get_object_from_query_params("invoice", request.query_params)

        if not invoice.sent_to_sap_at:
            raise ValidationError(
                _("Cannot credit invoices that have not been sent to SAP")
            )

        amount, receivable_type, notes = get_values_from_credit_request(request.data)

        try:
            credit_invoice = invoice.create_credit_invoice(
                amount=amount, receivable_type=receivable_type, notes=notes
            )
        except RuntimeError as e:
            raise APIException(str(e))

        credit_invoice_serializer = InvoiceSerializer(credit_invoice)

        result = {"invoice": credit_invoice_serializer.data}

        return Response(result)