I am able to group them up using *(groupby) *e.g
(*products=db().select(db.sales.ALL,
orderby=db.sales.product.name, groupby=db.sales.product.name)*) but now I
have a problem calculating the sum of each item's sold quantities.
On Wednesday, October 27, 2021 at 8:27:50 PM UTC+2 Jim S wrote:
> I
You need to create an alias for your field.
Look here:
http://web2py.com/books/default/chapter/29/06/the-database-abstraction-layer?search=count%28%29#sum-avg-min-max-and-len
Massimiliano
Il 28 ott 2021, 11:15:48, mostwanted ha scritto:
> I am able to group them up using *(groupby) *e.g
> (*
In the solution I proposed, I would create a variable in my template and
sum it as I looped through the records.
It might help if you showed a visual example of what you're trying to
accomplish. I may be misunderstanding the question, and if so, giving bad
advice.
-Jim
On Thursday, October 28
Hey Jim, thanks for your proposed solution,it worked as shown below, i hope
this is how you imagined it but this works now the problem I still have
&cant imagine is how I do the sum up of all of the item's purchase
quantity, how would you go about it:
*CONTROLLER:*
products=db().select(db.s
Ok, here is what I would do in my template:
{{last_item_name=[]}}
{{item_quantity = 0}}
{{for sales in products:}}
{{if sales.product.name not in last_item_name:}}
{{=sales.product.name}}
{{last_item_name.append(sales.product.name)}}
{{else:}}
{{pass}}
{
I apologize for that, i'm terrible at giving variables, my variable confuse
me at times too, *sales.product.Quantity* is the initial stock, its the
Quantity in the *Products *table, different from the sold quantity in the
*sales
*table (*sales.quantity*)
On Thursday, October 28, 2021 at 4:22:
In that case, then I'd do something like this:
If the product name changes, add a 'total' row showing the totals from the
previous product name.
{{last_item_name=[]}}
{{item_quantity = 0}}
{{for sales in products:}}
{{if sales.product.name not in last_item_name:}}
{{if item_quantit
7 matches
Mail list logo