Hi Massimo,
I have a multi tenant invoicing system serving multiple companies, all
invoices from different companies are stored in a single table flagged with
company_id. I would like each company being able to have their own
invoice_number starting from 1 and increment up.
db.define_table('invoice',
Field('invoice_number', 'integer'),
Field('customer', 'reference customer'),
Field('total', 'double', default=0),
Field('company_id', 'integer', readable=False,
writable=False))
If i do (auth_user table has an additional field company_id) ....
max_id=db(db.invoice.company_id==auth.user.company_id).select
(db.invoice.invoice_number, orderby=~db.invoice.invoice_number, limitby=
(0,1)).first().invoice_number
db.invoice.invoice_number.default = max_id + 1
form=SQLFORM(db.invoice).process()
It works but like you said it can't support multiple user creating invoices
at the same time. Any suggestion what I can do to support multiple users
creating invoices for a specific company at the same time? Thanks! Rudy
On Sunday, September 27, 2009 at 6:51:34 AM UTC+8, mdipierro wrote:
>
> You have to do it in two steps
>
> max_id=db(db.table.questionary_id==1).select
> (db.table.question_number,orderby=~db.question.number,limitby=
> (0,1)).first().question_number
> db.table.insert(....,question_number=max_id+1)
>
> and make sure that one user at the time is editing this one
> questionary.
>
> On Sep 26, 4:45 pm, ProfessionalIT <[email protected]> wrote:
> > > Question Number = 02 (get the last(max)(where the
> questionary_id=1) value of this field + 1)
> >
> > Well, in a crud create form I have this questionary_id, it is shown
> > how a html select field.
--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.