X-Git-Url: http://git.inspyration.org/?a=blobdiff_plain;f=addons%2Fpos_restaurant%2Fstatic%2Fsrc%2Fjs%2Fmultiprint.js;fp=addons%2Fpos_restaurant%2Fstatic%2Fsrc%2Fjs%2Fmultiprint.js;h=c4343cbf2d610e7674d0d294cdee0ef26000609f;hb=fcd06145dda957a83e687fd033ff294c407da5f4;hp=81b0e34053a633fd02dc17fac5c900282c2cc190;hpb=d9610efd979c974e540353716f8d0b9ecdb9d952;p=odoo%2Fodoo.git diff --git a/addons/pos_restaurant/static/src/js/multiprint.js b/addons/pos_restaurant/static/src/js/multiprint.js index 81b0e34..c4343cb 100644 --- a/addons/pos_restaurant/static/src/js/multiprint.js +++ b/addons/pos_restaurant/static/src/js/multiprint.js @@ -54,26 +54,43 @@ function openerp_restaurant_multiprint(instance,module){ }, }); + module.Orderline = module.Orderline.extend({ + get_line_diff_hash: function(){ + if (this.get_note()) { + return this.get_product().id + '|' + this.get_note(); + } else { + return '' + this.get_product().id; + } + }, + }); + + var _super_order = module.Order.prototype; module.Order = module.Order.extend({ lineResume: function(){ var resume = {}; - this.get('orderLines').each(function(item){ - var line = item.export_as_JSON(); - if( typeof resume[line.product_id] === 'undefined'){ - resume[line.product_id] = line.qty; - }else{ - resume[line.product_id] += line.qty; + + this.orderlines.each(function(line){ + 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 }; + } else { + resume[line_hash].qty += qty; } }); return resume; }, saveChanges: function(){ - this.old_resume = this.lineResume(); + this.saved_resume = this.build_line_resume(); + this.trigger('change',this); }, computeChanges: function(categories){ - var current = this.lineResume(); - var old = this.old_resume || {}; - var json = this.export_as_JSON(); + var current_res = this.build_line_resume(); + var old_res = this.saved_resume || {}; + var json = this.export_as_JSON(); var add = []; var rem = []; @@ -145,11 +162,22 @@ function openerp_restaurant_multiprint(instance,module){ rem = _rem; } + var d = new Date(); + var hours = '' + d.getHours(); + hours = hours.length < 2 ? ('0' + hours) : hours; + var minutes = '' + d.getMinutes(); + minutes = minutes.length < 2 ? ('0' + minutes) : minutes; + return { 'new': add, 'cancelled': rem, - 'table': json.table || 'unknown table', + 'table': json.table || false, + 'floor': json.floor || false, 'name': json.name || 'unknown order', + 'time': { + 'hours': hours, + 'minutes': minutes, + }, }; }, @@ -173,6 +201,15 @@ function openerp_restaurant_multiprint(instance,module){ } return false; }, + export_as_JSON: function(){ + var json = _super_order.export_as_JSON.apply(this,arguments); + json.multiprint_resume = this.saved_resume; + return json; + }, + init_from_JSON: function(json){ + _super_order.init_from_JSON.apply(this,arguments); + this.saved_resume = json.multiprint_resume; + }, }); module.PosWidget.include({