P.S. perhaps this should be changed. Decimal is not used very much and
not supported well on sqlite at all. I would use float.

On May 8, 10:38 pm, mdipierro <mdipie...@cs.depaul.edu> wrote:
> There are two problems:
> 1)  order is reserved keyword.
> 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 <danel.sega...@gmail.com> 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 <mdipie...@cs.depaul.edu> wrote:
>
> > > Can you show us the model and the action that triggers this?
>
> > > On May 8, 9:49 pm, greenpoise <danel.sega...@gmail.com> 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'
>
>

Reply via email to