Parcourir la source

[FIX] correcion en la impresion de ticket para la cocina y limpieza de codigo

Rodney Elpidio Enciso Arias il y a 7 ans
Parent
commit
d635f0ac7b
2 fichiers modifiés avec 79 ajouts et 76 suppressions
  1. 0 57
      README.rst
  2. 79 19
      static/src/js/main.js

+ 0 - 57
README.rst

@@ -1,57 +0,0 @@
-.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
-    :alt: License: AGPL-3
-
-Kitchen Ticket for Odoo Point of Sale
-=====================================
-
-This module allows to print a kitchen ticket, which is the same ticket than normal
-but without prices and taxes. This will be useful when the order is done internally
-without the payment.
-
-It has a additional **Payment** button on the Kitchen Ticket window to change the
-flow from **Payment->Receipt** to **Receipt->Payment**.
-
-This module target the POSBoxless environments, as the POSBox environment already 
-have a Bill printing method which can be enabled with pos_restaurant module that 
-Odoo provides.
-
-Usage
-=====
-
-Just press the *Kitchen Ticket* button that appears below the order
-
-
-Installation
-============
-
-Nothing special is needed to install this module.
-
-
-Configuration
-=============
-
-No configuration needed.
-
-
-Known issues / Roadmap
-======================
-
-Missing features
-----------------
-* Not tested with a **PosBox setting** so surely will not work if *'print by
-proxy'* is enabled.
-
-
-Credits
-=======
-
-Contributors
-------------
-
-* Dhinesh D <dvdhinesh.mail@gmail.com>
-
-
-Maintainer
-----------
-
-* Dhinesh D <dvdhinesh.mail@gmail.com>

+ 79 - 19
static/src/js/main.js

@@ -1,5 +1,5 @@
 openerp.eiru_kitchen_ticket = function (instance) {
-	var module   = instance.point_of_sale;
+    var module   = instance.point_of_sale;
     var _t = instance.web._t,
         _lt = instance.web._lt;
     var QWeb = instance.web.qweb;
@@ -13,6 +13,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',
@@ -34,13 +35,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'){
@@ -49,19 +47,51 @@ openerp.eiru_kitchen_ticket = function (instance) {
                     resume[line.product_id] += line.qty;
                 }
             });
-            
-            var current = resume;
+            return resume;
+        },
+
+        computeChanges: function(){
+            var order = this.pos.get('selectedOrder');
+            var categories = this.pos.printers[0].config.product_categories_ids;
+            var current = this.lineResume();
+            var old     = this.pos.get('selectedOrder').old_resume || {};
             var add = [];
+            var rem = [];
 
             for( product in current){
-                add.push({
-                    'id': product,
-                    'name': this.pos.db.get_product_by_id(product).display_name,
-                    'quantity': current[product],
-                });
+                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 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){
@@ -72,24 +102,53 @@ 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;
             }
+            return {
+                'new': add,
+                'cancelled': rem,
+                'name': this.pos.get('selectedOrder').attributes.name
+            };
+        },
 
+        hasChangesToPrint: function(){
+            var printers = this.pos.printers;
+            for(var i = 0; i < printers.length; i++){
+                var changes = this.computeChanges(printers[i].config.product_categories_ids);
+                if ( changes['new'].length > 0 || changes['cancelled'].length > 0){
+                    return true;
+                }
+            }
+            return false;
+        },
+        
+        refresh: function() {
+            var self = this;
+            var order = self.pos.get('selectedOrder');
+            var change = self.computeChanges();
             $('.pos-receipt-container', this.$el).html(QWeb.render('KitchenTicket',{
                 widget:this,
                 order: order,
                 orderlines: order.get('orderLines').models,
-                filterLines: add,
+                filterLines: change.new,
             }));
         },
     });
@@ -98,7 +157,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);
@@ -106,8 +164,11 @@ openerp.eiru_kitchen_ticket = function (instance) {
             var kitchen_ticket_button = $(QWeb.render('KitchenTicketButton'));
 
             kitchen_ticket_button.click(function(){
-                if(self.pos.get('selectedOrder').get('orderLines').models.length > 0){ 
+                var order = self.pos.get('selectedOrder');
+                if(order.hasChangesToPrint()){
                     self.pos_widget.screen_selector.set_current_screen('kitchenticket');
+                    order.saveChanges();
+                    self.pos_widget.order_widget.update_summary();
                 }
             });
 
@@ -115,5 +176,4 @@ openerp.eiru_kitchen_ticket = function (instance) {
             this.$('.control-buttons').removeClass('oe_hidden');
         },
     });
-
 };