Problem: Sum total price and total quantity of a product

37 views
Skip to first unread message

Ayron Rangel

unread,
Apr 20, 2018, 3:35:22 PM4/20/18
to web2py-users

I am developing an Inventory Control and am having difficulty calculating the sum of the values ​​of a given product type and calculating the quantity of products with the same model

Alby Cartner

unread,
Apr 20, 2018, 5:42:12 PM4/20/18
to web2py-users
I have just worked through it myself.
My solution is below - I did a small test app to sort it.
I am sure there are more elegant ways to solve it but this worked for me.

Model
db.define_table('additup',
                Field('number1','integer', default = 0),
                Field('number2','integer',default = 0),
                Field('number3','integer', default = 0),
                Field('total','integer'))

Controller

def index():
    form = SQLFORM(db.additup)
    return locals()

View

{{extend 'layout.html'}}

{{=form}}

<script>
jQuery("input[name='number1'],input[name='number2'],input[name='number2']").change(function()
{
jQuery("input[name='total']").val(parseInt(jQuery("input[name='number1']").val())+parseInt(jQuery("input[name='number2']").val())+parseInt(jQuery("input[name='number3']").val()));
});
</script>

pbreit

unread,
Apr 20, 2018, 5:46:55 PM4/20/18
to web...@googlegroups.com
Something like this?


sum = db.product.inventory_count.sum()
print db(db.product.type=='large').select(sum).first()[sum]

count = db(db.product.model=='Model S').count()
Reply all
Reply to author
Forward
0 new messages