Skip to content

Instantly share code, notes, and snippets.

@yk2kus
Last active August 29, 2015 14:20
Show Gist options
  • Save yk2kus/11ca5c3c4c1cd9149f24 to your computer and use it in GitHub Desktop.
Save yk2kus/11ca5c3c4c1cd9149f24 to your computer and use it in GitHub Desktop.
module.PosWidget = module.PosWidget.extend({
build_widgets: function() {
var self = this;
this._super();
this.discount_card_widget = new module.PaymentScreenDiscountWidget(this, {});
this.discount_card_widget.replace($('.placeholder-PaymentScreenDiscountWidget'));
},
});
module.Order = module.Order.extend({
getTotalCardDiscount: function() {
var subtotal = (this.get('orderLines')).reduce((function(sum, orderLine) {
return sum + orderLine.get_price_with_tax();
}), 0);
var discount_id = self.$('#discount-card-select').val();
if (discount_id) {
var discount_card = new module.PaymentScreenDiscountWidget(this, {});
var discount_promise = discount_card
.fetch('pos.discount.cards', ['type', 'value'], [
['id', '=', discount_id]
]).then(function(discount) {
var type = discount[0].type;
var value = discount[0].value;
if (type === 'fi') {
discount = value;
} else {
discount = (subtotal * value) / 100;
}
return discount;
});
} else {
discount_promise = Promise.resolve(0);
}
return discount_promise.then(function(discount) {
return discount;
});
// need to return discount
},
getTotalTaxIncluded: function() {
this.getTotalCardDiscount().then(function(discount){
console.log("returned discount..............",discount)
return discount
})
return 100 ;
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment