Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

product_code not taken up by API when creating invoice #666

Open
jeromecc opened this issue Dec 13, 2019 · 1 comment
Open

product_code not taken up by API when creating invoice #666

jeromecc opened this issue Dec 13, 2019 · 1 comment

Comments

@jeromecc
Copy link
Contributor

Hi!

I'm using the latest pip version within a Django 2.2 project (Python 3.6.9).

I could succesfully create customers, providers, product-codes through the API.

I'm trying to create invoices through the API directly (without using plans, because my current use case is a one time invoice for a one time payment for a one time service, even though i plan to use all the features offered by Silver in the future).

The dict in my Python code looks like this.

invoice_dct = {
        "due_date": due_date,
        "issue_date": due_date,
        "customer": customer_url,
        "provider": provider_url,
        "invoice_entries": [
            {
                "description": product_instance.description,
                "unit": product_instance.unit,
                "quantity": quantity,
                "unit_price": product_instance.unit_price,
                "product_code": {
                    "url": get_product_code_copper_url(product_instance.product_code),
                    "value": product_instance.product_code
                },
                "start_date": due_date,
                "end_date": due_date,
                "prorated": False
            },
        ],
        "sales_tax_percent": product_instance.sales_tax_percent,
        "sales_tax_name": product_instance.sales_tax_name,
        "currency": product_instance.currency,
        "state": "draft"
    }

Everything works fine (all fields are fed correctly, invoice is created)... except product_code which is null.
I created a product_code entry with a value (let's say value = "test-product" and it's the 1st product-code with a url like ".../product-codes/1/")

I tried feeding an url to the api:
"product-code": "http://example.com/product-codes/1/"

I tried feeding it url + value
product-code: {"url": "http://example.com/product-codes/1/", "value": "test-product"}

I also tried the value alone:
"product-code": "test-product"

and I even tried the key alone:
"product-code": 1 (or "1")

but nothing works for me, I end up with "product-code": null and I have to add the right product-code FK manually in the admin to have a complete invoice.

Is there a way to inject this data through the API?

Thank you for your outstanding work and for sharing it as free and open source software! :-)
jérôme

@jeromecc jeromecc changed the title product_plan not taken up by API when creating invoice product_code not taken up by API when creating invoice Dec 13, 2019
@bogdanpetrea
Copy link
Contributor

bogdanpetrea commented Dec 16, 2019

Hi @jeromecc,

It seems the product_code field is set to read-only: https://github.com/silverapp/silver/blob/master/silver/api/serializers/documents_serializers.py#L30

I've identified the origin of this change to be 5 years old: 4c4ab85, but I can't tell if there was any reasoning behind it. If I were to guess I would say not...

Anyway, I don't see any reason why this field can't be made writable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants