Traceback (most recent call last):
File "/home/appgov/web2py/gluon/restricted.py", line 219, in restricted
exec(ccode, environment)
File "/home/appgov/web2py/applications/apg/controllers/cg.py", line 836, in <module>
File "/home/appgov/web2py/gluon/globals.py", line 414, in <lambda>
self._caller = lambda f: f()
File "/home/appgov/web2py/applications/apg/controllers/cg.py", line 657, in cgsusearch
grid = SQLTABLE(rows, headers=hdrs, truncate=50)
File "/home/appgov/web2py/gluon/sqlhtml.py", line 3330, in __init__
tablemap = dict(((f.tablename, f.table) for f in fieldmap.values()))
File "/home/appgov/web2py/gluon/sqlhtml.py", line 3330, in <genexpr>
tablemap = dict(((f.tablename, f.table) for f in fieldmap.values()))
AttributeError: 'Expression' object has no attribute 'tablename'
Code:
query = db.dpspend.supplier.like(xsearch, case_sensitive=False)
isum = db.dpspend.amount.sum()
icount = db.dpspend.amount.count()
# group by family then supplier ....
rows = db(query).select(db.dpspend.dpfamily, db.dpspend.supplier, isum, icount, orderby=db.dpspend.dpfamily, groupby=db.dpspend.dpfamily|db.dpspend.supplier)
# Calculate the overall total values ....
for row in rows:
session.cgtotamt = session.cgtotamt + row._extra[isum]
session.cgtotrecs = session.cgtotrecs + row._extra[icount]
session.cgtotsus += 1
db.dpspend.amount.represent = lambda value, row: DIV('{0:,}'.format(0.0 if value == None else value), _style='text-align: right;')
hdrs = {'dpspend.dpfamily':T('Department'),
'dpspend.supplier':T('Supplier name'),
'SUM(dpspend.amount)':T('Total amount'),
'COUNT(dpspend.amount)':T('Records')}
grid = SQLTABLE(rows, headers=hdrs, truncate=50)
return dict(grid=grid)
tablemap = dict(((f.tablename, f.table) for f in fieldmap.values()))
tablemap = dict(((f.tablename, f.table) if isinstance(f, Field) else (f._table._tablename, f._table) for f in fieldmap.values()))