Re: [web2py] Re: Autoincrement which resets each month (not primary id)

2017-03-06 Thread Richard Vézina
Anthony is right... In my case I had to manage such kind of custom primary key generation... I use onvalidation() make a callback and find the sequence field and increment it... I have some function to generate the item id or custom primary key that contains the logic to increment properly the seq

[web2py] Re: Autoincrement which resets each month (not primary id)

2017-03-06 Thread Anthony
The problem with any solution that inspects the current records in the database table in order to figure out the ID for a new record is that you will not be able to account for deleted records (i.e., you might end up re-using IDs that were previously used by records that were later deleted). Th

Re: [web2py] Re: Autoincrement which resets each month (not primary id)

2017-03-06 Thread Kiran Subbaraman
For the trigger ... you could also consider using the web2py support for on insert / on update callbacks: http://web2py.com/books/default/chapter/29/06/the-database-abstraction-layer#callbacks-on-record-insert-delete-and-update Kiran Subbaraman http://su

Re: [web2py] Re: Autoincrement which resets each month (not primary id)

2017-03-06 Thread Paul Ellis
Hey Brian, Doing it on the fly won't work because I want the number to be set at record creation and be a part of the dataset. Also, this is what I am already doing. Using a database trigger is something I don't know anything about. So thank you for the nudge, I will research this option. Paul

[web2py] Re: Autoincrement which resets each month (not primary id)

2017-03-05 Thread Brian M
First of all, at the risk of asking a silly question - is there actually a reason to store this secondary ID in the database rather than just have it calculated on the fly as-needed using a virtual field? Assuming that you've got a created_date field already in the table that'll give you the mon

[web2py] Re: Autoincrement which resets each month (not primary id)

2017-03-05 Thread 黄祥
perhaps you can use count *e.g.* count_invoice = db.invoice.id.count() this_year = request.now.year this_month = request.now.month query_invoice = ((db.invoice.invoice_date.year() == this_year) & (db.invoice.invoice_date.month() == this_month) ) query_count_invoice = db(query_invoice).select(co