Thanks for the help. Here is the complete function defined in the
controller:

------ code for controller starts ------

@auth.requires_login()
def new_sale():
  response.title="New sale"
  if not session.cart:
    session.cart={}
  if not session.cart_qty:
    session.cart_qty={}
  if not session.qty_forms:
    session.qty_forms={}
  form = FORM(INPUT(_name="search", requires=IS_NOT_EMPTY()),
              INPUT(_type="submit",
_value="Search"),_name="form_search")
  if form.accepts(request.vars,session,formname="form_search"):
    rows=db(db.products.barcode==request.vars.search).select()
    if len(rows) == 1:
      product = rows.first()
      if product.id in session.cart:
        session.cart_qty[product.id]+=1
        session.qty_forms[product.id][0]
['_value']=session.cart_qty[product.id]
      else:
        session.cart[product.id]=product
        session.cart_qty[product.id]=1
        qty_form=FORM(INPUT( _name="qty", _value=1),
                      INPUT(_type="hidden",
_name="prod_id",_value=product.id),
 
INPUT(_type="submit",_value=T("Update"),_style="display:none;"),
                      _name="formqty"+str(product.id))
        if qty_form.accepts(request.vars,
session,formname="formqty"+str(product.id)):
          session.cart_qty[request.vars.prod_id]+=1
          temp_qty = session.cart_qty[request.vars.prod_id]
          session.qty_forms[request.vars.prod_id][0]['_value'] =
temp_qty
        session.qty_forms[product.id]=qty_form
  return dict(form=form)

------ code for controller ends ------

Now this is the view code:

------ code for view starts ------
{{extend 'layout.html'}}

<h1>Venta</h1>

<div id="buscar_codigo">
  {{=form}}
</div>

{{if len(session.cart)>0:}}
  <table class="data_table">
    <thead>
      <tr>
        <th scope="col" class="a10pc">Cantidad</th>
        <th scope="col" class="a10pc">Codigo</th>
        <th scope="col" class="a50pc">Producto</th>
        <th scope="col" class="a10pc">Precio</th>
        <th scope="col" class="a10pc">Sub-Total</th>
        <th scope="col" class="a10pc">Quitar</th>
      </tr>
    </thead>
      <tbody>
        {{i=0}}
        {{total=0}}
        {{for id, product in session.cart.iteritems():}}
          {{if i%2==1:}}
            <tr class="impar">
          {{else:}}
            <tr>
          {{pass}}
              <!--So I basically read all the products in the cart (a
dictionary)
                  Each product must have a quantity form so the user
can modify the amount of
                  products sold.-->
              <td>{{=session.qty_forms[id]}}</td>
              <td>{{=session.cart[id].codigo_de_barras}}</td>
              <td>{{=session.cart[id].nombre}}</td>
              <td>{{=session.cart[id].precio_de_venta}}</td>
 
<td>{{=session.cart[id].precio_de_venta*session.cart_qty[id]}}</td>
              <td></td>
          </tr>
          {{i+=1}}
          {{total
+=session.cart[id].precio_de_venta*session.cart_qty[id]}}
        {{pass}}
        <tfoot>
          <tr class="total_row">
            <th align="right" colspan="3" class="total"><strong>Total</
strong></td>
            <th colspan="3" class="total"><strong>{{=total}}</strong></
td>
          </tr>
        </tfoot>
    </tbody>
</table>
{{pass}}
------ code for view ends ------

Hopefully this time indentation wont break. Any way as I already said
the forms display correctly is just that the accept code doesn't. And
my forms all have different names. Hope some one can give a hand.

Thanks.

Reply via email to