$('#payment-remaining').html(remaining);
},
});
- /*
- "Receipt" step.
- */
- var ReceiptLineWidget = db.web.Widget.extend({
- tag_name: 'tr',
- template_fct: qweb_template('pos-receiptline-template'),
- init: function(parent, options) {
- this._super(parent);
- this.model = options.model;
- this.model.bind('change', this.render_element, this);
- },
- render_element: function() {
- this.$element.addClass('receiptline');
- this.$element.html(this.template_fct(this.model.toJSON()));
- },
- });
var ReceiptWidget = db.web.Widget.extend({
init: function(parent, options) {
this._super(parent);
this.model = options.model;
this.shop = options.shop;
+ },
+ start: function() {
this.shop.bind('change:selectedOrder', this.changeSelectedOrder, this);
- this.bindOrderLineEvents();
- this.bindPaymentLineEvents();
+ this.changeSelectedOrder();
+ },
+ render_element: function() {
+ this.$element.html(qweb_template('pos-receipt-view'));
+ $('button#pos-finish-order', this.$element).click(_.bind(this.finishOrder, this));
},
finishOrder: function() {
this.shop.get('selectedOrder').destroy();
},
- receiptLineList: function() {
- return this.$element.find('#receiptlines');
- },
- bindOrderLineEvents: function() {
+ changeSelectedOrder: function() {
+ if (this.currentOrderLines)
+ this.currentOrderLines.unbind();
this.currentOrderLines = (this.shop.get('selectedOrder')).get('orderLines');
- this.currentOrderLines.bind('add', this.addReceiptLine, this);
- this.currentOrderLines.bind('change', this.render_element, this);
- this.currentOrderLines.bind('remove', this.render_element, this);
- },
- bindPaymentLineEvents: function() {
+ this.currentOrderLines.bind('add', this.refresh, this);
+ this.currentOrderLines.bind('change', this.refresh, this);
+ this.currentOrderLines.bind('remove', this.refresh, this);
+ if (this.currentPaymentLines)
+ this.currentPaymentLines.unbind();
this.currentPaymentLines = (this.shop.get('selectedOrder')).get('paymentLines');
- this.currentPaymentLines.bind('all', this.updateReceiptSummary, this);
- },
- changeSelectedOrder: function() {
- this.currentOrderLines.unbind();
- this.bindOrderLineEvents();
- this.currentPaymentLines.unbind();
- this.bindPaymentLineEvents();
- this.render_element();
+ this.currentPaymentLines.bind('all', this.refresh, this);
+ this.refresh();
},
- addReceiptLine: function(newOrderItem) {
- var x = new ReceiptLineWidget(null, {
- model: newOrderItem
- });
- x.appendTo(this.receiptLineList());
- this.updateReceiptSummary();
- },
- render_element: function() {
- this.$element.html(qweb_template('pos-receipt-view'));
- $('button#pos-finish-order', this.$element).click(_.bind(this.finishOrder, this));
- this.currentOrderLines.each(_.bind( function(orderItem) {
- var x = new ReceiptLineWidget(null, {
- model: orderItem
- });
- x.appendTo(this.receiptLineList());
- }, this));
- this.updateReceiptSummary();
- },
- updateReceiptSummary: function() {
- var change, currentOrder, tax, total;
- currentOrder = this.shop.get('selectedOrder');
- total = currentOrder.getTotal();
- tax = currentOrder.getTax();
- change = currentOrder.getPaidTotal() - total;
- $('#receipt-summary-tax').html(tax.toFixed(2));
- $('#receipt-summary-total').html(total.toFixed(2));
- $('#receipt-summary-change').html(change.toFixed(2));
+ refresh: function() {
+ this.currentOrder = this.shop.get('selectedOrder');
+ $('.pos-receipt-container', this.$element).html(qweb_template('pos-ticket')({widget:this}));
},
});
var OrderButtonWidget = db.web.Widget.extend({
<input type="text" t-att-value="amount.toFixed(2)" />
</td>
</t>
- <t t-name="pos-receiptline-template">
- <td class="receiptline-quantity pos-rigth-align">
- <t t-esc="quantity.toFixed(0)"/>
- </td>
- <td class="receiptline-name">
- <t t-esc="name"/>
- </td>
- <td class="receiptline-amount">
- <t t-esc="format_amount((list_price * (1 - discount/100) * quantity).toFixed(2))"/>
- </td>
- </t>
<t t-name="pos-payment-button-template">
<button class="payment-button" t-att-cash-register-id="id">
<t t-esc="name"/>
<header><h2>Receipt</h2></header>
<div class="pos-step-container">
<div class="pos-receipt-container">
- <div class="pos-sale-ticket">
- OpenERP Point of Sale<br />
- <br />
- <div class="pos-rigth-align"><t t-esc="new Date().toString(Date.CultureInfo.formatPatterns.shortDate + ' ' +
- Date.CultureInfo.formatPatterns.longTime)"/></div>
- <br />
- <table id="receiptlines"></table>
- <br />
- <table>
- <tr><td>Total:</td><td class="pos-rigth-align">
- <t t-if="currency.position == 'before'" t-esc="currency.symbol"/>
- <span id="receipt-summary-total"></span>
- <t t-if="currency.position == 'after'" t-esc="currency.symbol"/>
- </td></tr>
- <tr><td>Tax:</td><td class="pos-rigth-align">
- <t t-if="currency.position == 'before'" t-esc="currency.symbol"/>
- <span id="receipt-summary-tax"></span>
- <t t-if="currency.position == 'after'" t-esc="currency.symbol"/>
- </td></tr>
- <tr><td>Change:</td><td class="pos-rigth-align">
- <t t-if="currency.position == 'before'" t-esc="currency.symbol"/>
- <span id="receipt-summary-change"></span>
- <t t-if="currency.position == 'after'" t-esc="currency.symbol"/>
- </td></tr>
- </table>
- </div>
</div>
<button id="pos-finish-order">Next Order</button>
</div>
</div>
</t>
+ <t t-name="pos-ticket">
+ <div class="pos-sale-ticket">
+ OpenERP Point of Sale<br />
+ <br />
+ <div class="pos-rigth-align"><t t-esc="new Date().toString(Date.CultureInfo.formatPatterns.shortDate + ' ' +
+ Date.CultureInfo.formatPatterns.longTime)"/></div>
+ <br />
+ <table id="receiptlines">
+ <tr t-foreach="widget.currentOrderLines.toArray()" t-as="order" class="receiptline">
+ <td class="receiptline-quantity pos-rigth-align">
+ <t t-esc="order.get('quantity').toFixed(0)"/>
+ </td>
+ <td class="receiptline-name">
+ <t t-esc="order.get('name')"/>
+ </td>
+ <td class="receiptline-amount">
+ <t t-esc="format_amount((order.get('list_price') * (1 - order.get('discount')/100) * order.get('quantity')).toFixed(2))"/>
+ </td>
+ </tr>
+ </table>
+ <br />
+ <table>
+ <tr><td>Total:</td><td class="pos-rigth-align">
+ <t t-esc="format_amount(widget.currentOrder.getTotal().toFixed(2))"/>
+ </td></tr>
+ <tr><td>Tax:</td><td class="pos-rigth-align">
+ <t t-esc="format_amount(widget.currentOrder.getTax().toFixed(2))"/>
+ </td></tr>
+ <tr><td>Change:</td><td class="pos-rigth-align">
+ <t t-esc="format_amount((widget.currentOrder.getPaidTotal() - widget.currentOrder.getTotal()).toFixed(2))"/>
+ </td></tr>
+ </table>
+ </div>
+ </t>
</templates>
\ No newline at end of file