i'm so sorry my bad, it can work now, the problem is :
>>> sum = db.purchase_detail.quantity.sum()
print db().select(sum).first()[sum]

should be :
>>> sum = db.purchase_detail.quantity.sum()
>>> print db().select(sum).first()[sum]

the problem is occured because i create the query on the text editor and 
then copy whole code (2 lines) and paste in the web2py shell, it should be 
copy just one line and then paste it on the web2py shell.

and for the query above is i made a mistook for the select and _select, all 
works now.
*views/report/report_product.html*
{{=DIV('%s - %s' % (from_date, to_date) ) }}

<table class = table>
<tr>
<th>{{=SPAN(B(T('Code') ) ) }} 
</th>
<th>{{=SPAN(B(T('Name') ) ) }} 
</th>
<th>{{=SPAN(B(T('Base Unit') ) ) }}
</th>
<th>{{=SPAN(B(T('Beginning') ) ) }}
</th>
<th>{{=SPAN(B(T('In') ) ) }}
</th>
<th>{{=SPAN(B(T('Out') ) ) }}
</th>
<th>{{=SPAN(B(T('Balance') ) ) }}
</th>
</tr>

{{for row_product in db(db.product).select():}}
{{sum_quantity_purchase = db.purchase_detail.quantity.sum()}}
{{sum_quantity_sale = db.sale_detail.quantity.sum()}}

{{query_purchase_detail = (row_product.id == db.purchase_detail.product) & 
(db.purchase_detail.purchase_no == db.purchase_header.id) & 
(db.purchase_header.purchase_date >= from_date) & 
(db.purchase_header.purchase_date <= to_date)}}
{{query_sale_detail = (row_product.id == db.sale_detail.product) & 
(db.sale_detail.sale_no == db.sale_header.id) & (db.sale_header.sale_date 
>= from_date) & (db.sale_header.sale_date <= to_date) }}

{{purchase_result = 
db(query_purchase_detail).select(sum_quantity_purchase).first()[sum_quantity_purchase]
 
if db(query_purchase_detail).select() else 0}}
{{sale_result = 
db(query_sale_detail).select(sum_quantity_sale).first()[sum_quantity_sale] 
if db(query_sale_detail).select() else 0}}

<tr>
<td>{{=DIV(row_product.code)}}
</td>
<td>{{=DIV(row_product.name)}}
</td>
<td>{{=DIV(row_product.base_unit)}}
</td>
<td>{{=DIV(row_product.quantity + sale_result - purchase_result)}}
</td>
<td>{{=DIV(purchase_result)}}
</td>
<td>{{=DIV(sale_result)}}
</td>
<td>{{=DIV(row_product.quantity)}}
</td>
</tr>
{{pass}}

</table>

thanks and best regards,
stifan

-- 
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/groups/opt_out.

Reply via email to