The default argument can be a function, but it does not have access to the
other fields being inserted/updated, so it cannot determine the appropriate
quotationClient record from which to pull these values. This means you
cannot use default for this purpose.
Do you simply want the default values on *initial* insert to be the values
from the quotationClient record, or do you want to keep the values of these
fields in sync between quotationClient and quotation?
If the former, I suppose you could make these computed fields -- something
like:
Field('Book_In', 'date', compute=lambda r: db.quotationClient(r.customer).
Book_In)
Note, that will update the Book_In value on every update in which the
customer field is also supplied. Alternatively, you could use a
_before_insert() hook to add the Book_In and Book_Out fields before initial
insert only.
If you need to keep the fields in sync between the tables, you could use a
_before_insert() hook on the quotation table (to grab the initial values),
along with an _after_update() hook on the quotationClient table (to update
the values in any referencing records).
Anthony
On Saturday, December 1, 2018 at 2:41:54 PM UTC-5, mostwanted wrote:
>
>
> I am trying to achieve something here, i have two tables and i want the
> values of one table to be default values of another table so that i don't
> have to re enter the same information over & over again: In the code below
> observe where highlited in green, is there a way for me to do something
> like below.
>
> *CODE*:
> db.define_table('quotationClient',
> Field('Client_Surname'),
> Field('Client_Name'),
> Field('Company'),
> Field('Contact_Details'),
> Field('Book_In', 'date'),
> Field('Book_Out', 'date'),
> Field('Days', compute=lambda r: (r['Book_Out']-r['Book_In'
> ]).days),
> Field('Booked_By', 'reference auth_user', default=auth.
> user_id, writable=False, label=SPAN('Booked In By', _style="font-weight:
> bold;")),
> Field('Booking_Date', 'datetime', default=request.now,
> writable=False, label=SPAN('Booking Date', _style="font-weight: bold;")),
> format="%(Client_Surname)s %(Client_Name)s"
> )
>
> db.define_table('quotation',
> Field('customer', 'reference quotationClient', writable=
> False),
> Field('Quotation_For'),
> *#HOW CAN I DO THE BELOW IN SUCH A WAY THAT WORKS*
>
> * Field('Book_In', 'date', default='db.quotationClient.Book_In',
> writable=False, readable=False), Field('Book_Out', 'date',
> default='db.quotationClient.Book_Out', writable=False, readable=False),*
> Field('No_of_Pax', 'integer'),
> Field('Days', compute=lambda r: (r['Book_Out']-r['Book_In'
> ]).days),
> #Field('No_of_Days', 'integer'),
> Field('Unit_Price', 'integer'),
> #Field('vat', compute=lambda r:
> int(r['Days'])*r['Unit_Price']*r['No_of_Pax']*0.1),
> Field('Amount', compute=lambda r: int(r['Days'])*r[
> 'Unit_Price']* r['No_of_Pax']),
> Field('Quoted_By','reference auth_user', default=auth.
> user_id, writable=False),
> Field('Quoted_On','datetime',default=request.now,writable=
> False))
>
> Mostwanted
>
--
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.