+1. if your calculation needs 3 fields to be something "numeric", you can't ask web2py (or python) to compute something that can't be calculated (you can't do, e.g. 2.1*None*4 and expect a result). Your code should check the existence of the values (at the very least) with something like
if r['abc'] and r['def']: return r['abc'] * r['def'] else: return None On Tuesday, November 4, 2014 9:51:56 PM UTC+1, Derek wrote: > > you are going wrong by computing it when you can't actually compute it. > > On Monday, November 3, 2014 4:45:30 PM UTC-7, Anthony Smith wrote: >> >> Hi >> >> I am stuck on the following, if no_of _items, dollars_items are not used >> the total_sale_price is left blank I get the follow message >> >> compute=lambda r: r['no_of_items']*r['dollars_items']), >> TypeError: unsupported operand type(s) for *: 'NoneType' and 'NoneType' >> >> If I leave the no_by weight, cent_per_kg i get the following >> >> compute=lambda r: r['estimated_weight']*r['no_by_weight']*r['cents_per_kg']), >> TypeError: unsupported operand type(s) for *: 'NoneType' and 'NoneType' >> >> >> Field('no_of_items', 'integer'), >> Field('dollars_items', 'double'), >> Field('sub_total_items','double', >> compute=lambda r: r['no_of_head']*r['dollars_hd']), >> Field('no_by_weight', 'integer'), >> Field('estimated_weight', 'double'), >> Field('cents_per_kg', 'double'), >> Field('sub_total_kg', 'double', >> compute=lambda r: >> r['estimated_weight']*r['no_by_weight']*r['cents_per_kg']), >> Field('total_sale_price', 'double', >> compute=lambda r: r['sub_total_hd'] >> +r['sub_total_kg']), >> >> >> Where am I going wrong >> >> cheers >> >> >> >> -- 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 web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.