From a10bc113c1b602fa80c725a82045c9b1c2eeaa09 Mon Sep 17 00:00:00 2001 From: Stefan Rijnhart Date: Sun, 20 Dec 2015 19:39:47 +0100 Subject: [PATCH] [IMP] Preserve manually modified price in most cases --- pos_pricelist/static/src/js/models.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/pos_pricelist/static/src/js/models.js b/pos_pricelist/static/src/js/models.js index ea3566fb..adc79c3e 100644 --- a/pos_pricelist/static/src/js/models.js +++ b/pos_pricelist/static/src/js/models.js @@ -162,17 +162,26 @@ function pos_pricelist_models(instance, module) { * @param quantity */ set_quantity: function (quantity) { - OrderlineParent.prototype.set_quantity.apply(this, arguments); var partner = this.order ? this.order.get_client() : null; var product = this.product; var db = this.pos.db; + var old_price = 0; + if (this.get_quantity()) { + old_price = this.pos.pricelist_engine.compute_price_all( + db, product, partner, this.get_quantity() + ); + } + OrderlineParent.prototype.set_quantity.apply(this, arguments); var price = this.pos.pricelist_engine.compute_price_all( db, product, partner, quantity ); - if (price !== false) { + /* Update the price if the unit price is actually different from + the unit price of the previous quantity, to preserve manually + entered prices as much as possible. */ + if (price !== false && price !== old_price) { this.price = price; + this.trigger('change', this); } - this.trigger('change', this); }, /** * override this method to take fiscal positions in consideration