From 5261216b010e46db410205f7e39aa6968f866a6b Mon Sep 17 00:00:00 2001 From: Adil Houmadi Date: Tue, 14 Jul 2015 04:00:17 +0200 Subject: [PATCH] [IMP] : Take in account @antespi remark's Clean way to inherit in JS And improve get_display_price method --- pos_pricelist/static/src/js/models.js | 25 +++++++++++++++++++------ pos_pricelist/static/src/js/widgets.js | 7 ++++++- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/pos_pricelist/static/src/js/models.js b/pos_pricelist/static/src/js/models.js index 8d0b8a73..d08402d6 100644 --- a/pos_pricelist/static/src/js/models.js +++ b/pos_pricelist/static/src/js/models.js @@ -24,13 +24,14 @@ function pos_pricelist_models(instance, module) { /** * Extend the POS model */ + var PosModelParent = module.PosModel; module.PosModel = module.PosModel.extend({ /** * @param session * @param attributes */ initialize: function (session, attributes) { - this.constructor.__super__.initialize.apply(this, arguments); + PosModelParent.prototype.initialize.apply(this, arguments); this.pricelist_engine = new module.PricelistEngine({ 'pos': this, 'db': this.db, @@ -59,7 +60,7 @@ function pos_pricelist_models(instance, module) { * @param reason */ on_removed_order: function (removed_order, index, reason) { - this.constructor.__super__.on_removed_order.apply(this, arguments); + PosModelParent.prototype.on_removed_order.apply(this, arguments); if ((reason === 'abandon' || removed_order.temporary) && this.get('orders').size() > 0) { var current_order = (this.get('orders').at(index) @@ -129,13 +130,14 @@ function pos_pricelist_models(instance, module) { /** * Extend the Order line */ + var OrderlineParent = module.Orderline; module.Orderline = module.Orderline.extend({ /** * @param attr * @param options */ initialize: function (attr, options) { - this.constructor.__super__.initialize.apply(this, arguments); + OrderlineParent.prototype.initialize.apply(this, arguments); this.manuel_price = false; if (this.product !== undefined) { var qty = this.compute_qty(this.order, this.product); @@ -160,7 +162,7 @@ function pos_pricelist_models(instance, module) { * @param quantity */ set_quantity: function (quantity) { - this.constructor.__super__.set_quantity.apply(this, arguments); + OrderlineParent.prototype.set_quantity.apply(this, arguments); var partner = this.order.get_client(); var product = this.product; var db = this.pos.db; @@ -215,7 +217,7 @@ function pos_pricelist_models(instance, module) { * @returns {boolean} */ can_be_merged_with: function (orderline) { - var result = this.constructor.__super__.can_be_merged_with.apply( + var result = OrderlineParent.prototype.can_be_merged_with.apply( this, arguments ); if (!result) { @@ -234,7 +236,7 @@ function pos_pricelist_models(instance, module) { * @param orderline */ merge: function (orderline) { - this.constructor.__super__.merge.apply(this, arguments); + OrderlineParent.prototype.merge.apply(this, arguments); this.set_unit_price(orderline.price); }, /** @@ -297,6 +299,17 @@ function pos_pricelist_models(instance, module) { } return product_taxes; }, + /** + * @returns {*} + */ + get_display_price: function () { + if (this.pos.config.display_price_with_taxes) { + return this.get_price_with_tax(); + } + return OrderlineParent.prototype.get_display_price.apply( + this, arguments + ); + } }); /** diff --git a/pos_pricelist/static/src/js/widgets.js b/pos_pricelist/static/src/js/widgets.js index b1812b1c..d6f63c2a 100644 --- a/pos_pricelist/static/src/js/widgets.js +++ b/pos_pricelist/static/src/js/widgets.js @@ -55,7 +55,12 @@ function pos_pricelist_widgets(instance, module) { }, renderElement: function () { this._super(); - this.pos.pricelist_engine.update_products_ui(null); + var order = posmodel.get_order(); + var customer = null; + if(order) { + customer = order.get_client(); + } + this.pos.pricelist_engine.update_products_ui(customer); } }); }