|
@@ -21,6 +21,7 @@ openerp.eiru_kitchen_ticket = function (instance) {
|
|
|
show: function(){
|
|
|
this._super();
|
|
|
var self = this;
|
|
|
+
|
|
|
var back_button = this.add_action_button({
|
|
|
label: _t('Back'),
|
|
|
icon: '/point_of_sale/static/src/img/icons/png48/go-previous.png',
|
|
@@ -29,6 +30,7 @@ openerp.eiru_kitchen_ticket = function (instance) {
|
|
|
},
|
|
|
});
|
|
|
this.refresh();
|
|
|
+ this.saveChanges();
|
|
|
},
|
|
|
|
|
|
print: function() {
|
|
@@ -42,13 +44,10 @@ openerp.eiru_kitchen_ticket = function (instance) {
|
|
|
this.pos_widget.screen_selector.set_current_screen(previous);
|
|
|
}
|
|
|
},
|
|
|
-
|
|
|
- refresh: function() {
|
|
|
- var self = this;
|
|
|
- var order = this.pos.get('selectedOrder');
|
|
|
- var categories = self.pos.printers[0].config.product_categories_ids;
|
|
|
+
|
|
|
+ lineResume: function(){
|
|
|
var resume = {};
|
|
|
-
|
|
|
+ var order = this.pos.get('selectedOrder');
|
|
|
order.get('orderLines').each(function(item){
|
|
|
var line = item.export_as_JSON();
|
|
|
if( typeof resume[line.product_id] === 'undefined'){
|
|
@@ -57,19 +56,60 @@ openerp.eiru_kitchen_ticket = function (instance) {
|
|
|
resume[line.product_id] += line.qty;
|
|
|
}
|
|
|
});
|
|
|
+ return resume;
|
|
|
+ },
|
|
|
+
|
|
|
+ saveChanges: function(){
|
|
|
+ this.old_resume = this.lineResume();
|
|
|
+ },
|
|
|
+
|
|
|
+ refresh: function() {
|
|
|
+ var self = this;
|
|
|
+ var order = this.pos.get('selectedOrder');
|
|
|
+ var categories = self.pos.printers[0].config.product_categories_ids;
|
|
|
|
|
|
- var current = resume;
|
|
|
+ // **************************************************
|
|
|
+
|
|
|
+ var current = this.lineResume();
|
|
|
+ var old = this.old_resume || {};
|
|
|
var add = [];
|
|
|
+ var rem = [];
|
|
|
+
|
|
|
+ for(product in current){
|
|
|
+ if (typeof old[product] === 'undefined'){
|
|
|
+ add.push({
|
|
|
+ 'id': product,
|
|
|
+ 'name': this.pos.db.get_product_by_id(product).display_name,
|
|
|
+ 'quantity': current[product],
|
|
|
+ });
|
|
|
+ }else if( old[product] < current[product]){
|
|
|
+ add.push({
|
|
|
+ 'id': product,
|
|
|
+ 'name': this.pos.db.get_product_by_id(product).display_name,
|
|
|
+ 'quantity': current[product] - old[product],
|
|
|
+ });
|
|
|
+ }else if( old[product] > current[product]){
|
|
|
+ rem.push({
|
|
|
+ 'id': product,
|
|
|
+ 'name': this.pos.db.get_product_by_id(product).display_name,
|
|
|
+ 'quantity': old[product] - current[product],
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- for( product in current){
|
|
|
- add.push({
|
|
|
- 'id': product,
|
|
|
- 'name': this.pos.db.get_product_by_id(product).display_name,
|
|
|
- 'quantity': current[product],
|
|
|
- });
|
|
|
+ for( product in old){
|
|
|
+ if(typeof current[product] === 'undefined'){
|
|
|
+ rem.push({
|
|
|
+ 'id': product,
|
|
|
+ 'name': this.pos.db.get_product_by_id(product).display_name,
|
|
|
+ 'quantity': old[product],
|
|
|
+ });
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
if(categories && categories.length > 0){
|
|
|
+
|
|
|
+ var self = this;
|
|
|
function product_in_category(product_id){
|
|
|
var cat = self.pos.db.get_product_by_id(product_id).pos_categ_id[0];
|
|
|
while(cat){
|
|
@@ -80,19 +120,29 @@ openerp.eiru_kitchen_ticket = function (instance) {
|
|
|
}
|
|
|
cat = self.pos.db.get_category_parent_id(cat);
|
|
|
}
|
|
|
-
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
var _add = [];
|
|
|
+ var _rem = [];
|
|
|
+
|
|
|
for(var i = 0; i < add.length; i++){
|
|
|
if(product_in_category(add[i].id)){
|
|
|
_add.push(add[i]);
|
|
|
}
|
|
|
}
|
|
|
add = _add;
|
|
|
+
|
|
|
+ for(var i = 0; i < rem.length; i++){
|
|
|
+ if(product_in_category(rem[i].id)){
|
|
|
+ _rem.push(rem[i]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ rem = _rem;
|
|
|
}
|
|
|
|
|
|
+ // ******************************************
|
|
|
+
|
|
|
$('.pos-receipt-container', this.$el).html(QWeb.render('KitchenTicket',{
|
|
|
widget:this,
|
|
|
order: order,
|
|
@@ -106,7 +156,6 @@ openerp.eiru_kitchen_ticket = function (instance) {
|
|
|
build_widgets: function(){
|
|
|
var self = this;
|
|
|
this._super();
|
|
|
-
|
|
|
this.kitchen_ticket_screen = new module.KitchenTicketScreenWidget(this,{});
|
|
|
this.kitchen_ticket_screen.appendTo(this.$('.screens'));
|
|
|
this.screen_selector.add_screen('kitchenticket',this.kitchen_ticket_screen);
|