On Sun, May 9, 2010 at 00:38, mdipierro <[email protected]> wrote:
> There are two problems:
> 1)  order is reserved keyword.

Yes but about the quotes that I suggested? :-)

> 2) decimal types are treated as string internally and there for
> compute should be
>
> db.order.tipgranted.compute=lambda r:
> float(r['totalsale'])*float(r['tipvalue'])
>
> or better
>
> db.order.tipgranted.compute=lambda r:
> decimal.Decimal(r['totalsale'])*decimal.Decimal(r['tipvalue'])
>
>
> On May 8, 10:00 pm, greenpoise <[email protected]> wrote:
>> Model:
>>
>> db.define_table('order',
>>     Field('employee',db.person),
>>     Field('tablenumber'),
>>     Field('ordernumber'),
>>     Field('orderdate','date'),
>>     Field('totalsale', 'decimal(10,2)'),
>>     Field('tipgranted', 'decimal(10,2)',default=None, update=None,
>> readable=False),
>>     Field('tipvalue','decimal(10,2)',default='0.15'),)
>>
>> @auth.requires_login()
>> def show_orders():
>>     db.order.tipgranted.compute=lambda r:
>> r['totalsale']*r['tipvalue']
>>     form=crud.create(db.order)
>>
>> orders=db(db.order.employee==employee.id).select(orderby=db.order.ordernumber)
>>     return dict(employee=employee,orders=orders,form=form)
>>
>> thanks
>>
>> On May 8, 10:54 pm, mdipierro <[email protected]> wrote:
>>
>> > Can you show us the model and the action that triggers this?
>>
>> > On May 8, 9:49 pm, greenpoise <[email protected]> wrote:
>>
>> > > Can someone help me. I am trying to do a simple calculation of fields.
>> > > Fields are defined as decimal in db.py and here is the calculation:
>>
>> > >     db.order.tipgranted.compute=lambda r: r['totalsale']*r['tipvalue']
>>
>> > > error: TypeError: can't multiply sequence by non-int of type 'float'
>>
>>
>



-- 
Álvaro Justen - Turicas
 http://blog.justen.eng.br/
 21 9898-0141

Reply via email to