From e702e3a776524f14b2252dbac508cf27625a293a Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Thu, 6 Apr 2023 06:09:04 +0000 Subject: [PATCH] [IMP] point_of_sale: simplify can_be_merged_with code Existing version uses a visually complicated chain of if/else and double negations, this is much more readable as a simple chain of AND-ed conditions checking for positive merge-ability factors. Part-of: odoo/odoo#117874 --- addons/point_of_sale/static/src/js/models.js | 44 ++++++++------------ 1 file changed, 17 insertions(+), 27 deletions(-) diff --git a/addons/point_of_sale/static/src/js/models.js b/addons/point_of_sale/static/src/js/models.js index 35ad907db52..c5572a81ac2 100644 --- a/addons/point_of_sale/static/src/js/models.js +++ b/addons/point_of_sale/static/src/js/models.js @@ -2190,35 +2190,25 @@ export class Orderline extends PosModel { orderline.compute_fixed_price(order_line_price), this.pos.currency.decimal_places ); - if (this.get_product().id !== orderline.get_product().id) { - //only orderline of the same product can be merged - return false; - } else if (!this.get_unit() || !this.get_unit().is_pos_groupable) { - return false; - } else if (this.get_discount() > 0) { - // we don't merge discounted orderlines - return false; - } else if ( - !utils.float_is_zero( + // only orderlines of the same product can be merged + return ( + this.get_product().id === orderline.get_product().id && + this.get_unit() && + this.get_unit().is_pos_groupable && + // don't merge discounted orderlines + this.get_discount() === 0 && + utils.float_is_zero( price - order_line_price - orderline.get_price_extra(), this.pos.currency.decimal_places - ) - ) { - return false; - } else if ( - this.product.tracking == "lot" && - (this.pos.picking_type.use_create_lots || this.pos.picking_type.use_existing_lots) - ) { - return false; - } else if (this.description !== orderline.description) { - return false; - } else if (orderline.get_customer_note() !== this.get_customer_note()) { - return false; - } else if (this.refunded_orderline_id) { - return false; - } else { - return true; - } + ) && + !( + this.product.tracking === "lot" && + (this.pos.picking_type.use_create_lots || this.pos.picking_type.use_existing_lots) + ) && + this.description === orderline.description && + orderline.get_customer_note() === this.get_customer_note() && + !this.refunded_orderline_id + ); } merge(orderline) { this.order.assert_editable();