already tried to write the dummy session data in (sale_order and
sale_order_form) but still same (need submit twice), yet i got some bonus,
traceback error said :
AttributeError: 'str' object has no attribute 'items'
*controllers/default.py*
def sale_order():
session.sale_order = 'test'
return locals()
def sale_order_form():
session.sale_order = 'test'
form = SQLFORM.factory(
Field('product', 'reference product',
requires = IS_IN_DB(db((db.product.
quantity > 0) ),
db.product.id, db.product._format) ),
Field('quantity', 'integer', requires = IS_NOT_EMPTY() ),
)
if form.process(formname = 'myform1').accepted:
response.flash = T('Form accepted')
id = int(request.vars.product)
row = db(db.product.id == id).select().first()
quantity = int(request.vars.quantity)
price = int(row.selling_price)
session.sale_order[id] = quantity, price
response.js = "jQuery('#sale_order_checkout').get(0).reload()"
elif form.errors:
response.flash = T('Form has errors')
return dict(form = form)
*views/default/sale_order_checkout.load*
{{total_quantity = 0 }}
{{grand_total = 0 }}
<table class = "table table-condensed table-hover">
<tr>
<th>{{=T('Product') }}</th>
<th>{{=T('Price') }}</th>
<th>{{=T('Quantity') }}</th>
<th>{{=T('Total Price') }}</th>
<th>{{=T('Action') }}</td>
</tr>
{{for id, (quantity, price) in session_detail.items():}}
{{product = db.product(id) }}
{{total_price = quantity * price}}
{{total_quantity += quantity}}
{{grand_total += total_price}}
<tr>
<td>
{{=SPAN(product.name) }}
</td>
<td>{{=SPAN('Rp. %s' % format(price, ",d").replace(",", ".") )
}}</td>
<td>
<form>
<input name = "{{='quantity_%s' % id}}" value =
"{{=quantity}}"
onkeyup = "ajax('{{=URL(link_callback, vars = dict(id = id,
price = price,
action = 'adjust_total') ) }}', ['{{='quantity_%s' %
id}}'], ':eval' )" />
</form>
</td>
<td>Rp. {{=SPAN('%s' % format(total_price, ",d").replace(",", "."),
_id = 'total_price_%s' % id) }}</td>
<td>
{{=SPAN(A(I(_class = 'glyphicon glyphicon-remove-sign'),
callback = URL(link_callback,
vars = dict(id = id, action = 'remove') ), delete =
'tr',
_title = 'Remove %s' % product.name) ) }}
</td>
</tr>
{{pass}}
<tr>
<td></td>
<td>{{=B(T('Grand Total') ) }}</td>
<td>{{=SPAN('%s' % format(total_quantity, ",d").replace(",", "."),
_id = 'total_quantity') }}</td>
<td>Rp. {{=SPAN('%s' % format(grand_total, ",d").replace(",", "."),
_id = 'grand_total') }}</td>
<td></td>
</tr>
</table>
{{=SPAN(A(T('Empty'), _href = URL(link_empty), _title = 'Empty',
_onclick = "javascript:return confirm('Are you sure you want to
empty?')",
_class = 'btn btn-info') ) }}
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 [email protected].
For more options, visit https://groups.google.com/d/optout.