diff --git a/addons/pos_restaurant/static/src/js/multiprint.js b/addons/pos_restaurant/static/src/js/multiprint.js index 0c43f6cba6f..3ef5859a185 100644 --- a/addons/pos_restaurant/static/src/js/multiprint.js +++ b/addons/pos_restaurant/static/src/js/multiprint.js @@ -132,22 +132,16 @@ models.Order = models.Order.extend({ if (line.mp_skip) { return; } - var line_hash = line.get_line_diff_hash(); var qty = Number(line.get_quantity()); var note = line.get_note(); var product_id = line.get_product().id; - - if (typeof resume[line_hash] === 'undefined') { - resume[line_hash] = { - qty: qty, - note: note, - product_id: product_id, - product_name_wrapped: line.generate_wrapped_product_name(), - }; - } else { - resume[line_hash].qty += qty; - } - + var product_resume = product_id in resume ? resume[product_id] : { + product_name_wrapped: line.generate_wrapped_product_name(), + qties: {}, + }; + if (note in product_resume['qties']) product_resume['qties'][note] += qty; + else product_resume['qties'][note] = qty; + resume[product_id] = product_resume; }); return resume; }, @@ -164,62 +158,55 @@ models.Order = models.Order.extend({ var json = this.export_as_JSON(); var add = []; var rem = []; - var line_hash; + var pid, note; - for ( line_hash in current_res) { - var curr = current_res[line_hash]; - var old = {}; - var found = false; - for(var id in old_res) { - if(old_res[id].product_id === curr.product_id){ - found = true; - old = old_res[id]; - break; + for (pid in current_res) { + for (note in current_res[pid]['qties']) { + var curr = current_res[pid]; + var old = old_res[pid] || {}; + var found = pid in old_res && note in old_res[pid]['qties']; + + if (!found) { + add.push({ + 'id': pid, + 'name': this.pos.db.get_product_by_id(pid).display_name, + 'name_wrapped': curr.product_name_wrapped, + 'note': note, + 'qty': curr['qties'][note], + }); + } else if (old['qties'][note] < curr['qties'][note]) { + add.push({ + 'id': pid, + 'name': this.pos.db.get_product_by_id(pid).display_name, + 'name_wrapped': curr.product_name_wrapped, + 'note': note, + 'qty': curr['qties'][note] - old['qties'][note], + }); + } else if (old['qties'][note] > curr['qties'][note]) { + rem.push({ + 'id': pid, + 'name': this.pos.db.get_product_by_id(pid).display_name, + 'name_wrapped': curr.product_name_wrapped, + 'note': note, + 'qty': old['qties'][note] - curr['qties'][note], + }); } } - - if (!found) { - add.push({ - 'id': curr.product_id, - 'name': this.pos.db.get_product_by_id(curr.product_id).display_name, - 'name_wrapped': curr.product_name_wrapped, - 'note': curr.note, - 'qty': curr.qty, - }); - } else if (old.qty < curr.qty) { - add.push({ - 'id': curr.product_id, - 'name': this.pos.db.get_product_by_id(curr.product_id).display_name, - 'name_wrapped': curr.product_name_wrapped, - 'note': curr.note, - 'qty': curr.qty - old.qty, - }); - } else if (old.qty > curr.qty) { - rem.push({ - 'id': curr.product_id, - 'name': this.pos.db.get_product_by_id(curr.product_id).display_name, - 'name_wrapped': curr.product_name_wrapped, - 'note': curr.note, - 'qty': old.qty - curr.qty, - }); - } } - for (line_hash in old_res) { - var found = false; - for(var id in current_res) { - if(current_res[id].product_id === old_res[line_hash].product_id) - found = true; - } - if (!found) { - var old = old_res[line_hash]; - rem.push({ - 'id': old.product_id, - 'name': this.pos.db.get_product_by_id(old.product_id).display_name, - 'name_wrapped': old.product_name_wrapped, - 'note': old.note, - 'qty': old.qty, - }); + for (pid in old_res) { + for (note in old_res[pid]['qties']) { + var found = pid in current_res && note in current_res[pid]['qties']; + if (!found) { + var old = old_res[pid]; + rem.push({ + 'id': pid, + 'name': this.pos.db.get_product_by_id(pid).display_name, + 'name_wrapped': old.product_name_wrapped, + 'note': note, + 'qty': old['qties'][note], + }); + } } }