simonluijk / django-invoice

Django invoicing app
Other
188 stars 64 forks source link

Invoice Numbers #2

Open vandorjw opened 10 years ago

vandorjw commented 10 years ago

Bug:

https://github.com/simonluijk/django-invoice/blob/master/invoice/utils/friendly_id.py#L74

Is broken on python3

I can fix it, and send a pull-request, but before I do, I would like to hear what you think about the following.

I agree that the invoice numbers should not expose how many invoices have been created. However the current implementation can be simplified, and become more meaningful, by setting the id to the following pattern.

invoice-id = yyyymmdd-aaaa0000

Today:

invoice-100 = 20140424-8cff2cdc

Tomorrow:

#Notice the date increased
invoice-101 = 20140425-175abd80

Where the first 8 digits are the date the invoice was created, and the last 8 digits are the first 8 digits from uuid4()

from uuid import uuid4
def test_uuid4():
    x = str(uuid4())
    print(x)
    print(x[:8])

result

test_uuid4()
    8cff2cdc-e535-45be-ada4-492fb6f6ff37
    8cff2cdc

Each invoice ID will be unique, and somewhat meaningful, since we prefix them all with the day.

simonluijk commented 10 years ago

Sorry about not replying sooner. I did not receive a notification and was too absorbed with work to check GH.

I like what you have suggested especially removing friendly_id.py. I do think we should add some configuration options though. INVOICE_ID_PREPEND_DATE=True|False I think is self explanatory. INVOICE_ID_LENGTH=8 would limit the random chars appended. Also the invoice id should be uppercase for consistency.

The only advantage of using the current perfect hash implementation is that there is no chance of a collision. Either we live with the chance of a collision or add code to re-generate the invoice id on a collision.

Would you be willing to submit a PR?