[IMP] point_of_sale: add a method for getting totals by product categories, used...
authorFrederic van der Essen <fva@openerp.com / fvdessen+o@gmail.com>
Fri, 7 Nov 2014 16:25:42 +0000 (17:25 +0100)
committerFrédéric van der Essen <fvdessen@gmail.com>
Wed, 26 Nov 2014 11:06:18 +0000 (12:06 +0100)
addons/point_of_sale/static/src/js/db.js
addons/point_of_sale/static/src/js/models.js

index 172a7c9..2711dbc 100644 (file)
@@ -122,6 +122,17 @@ function openerp_pos_db(instance, module){
             }
             make_ancestors(this.root_category_id, []);
         },
+        category_contains: function(categ_id, product_id) {
+            var product = this.product_by_id[product_id];
+            if (product) {
+                var cid = product.pos_categ_id[0];
+                while (cid && cid !== categ_id){
+                    cid = this.category_parent[cid];
+                }
+                return !!cid;
+            }
+            return false;
+        },
         /* loads a record store from the database. returns default if nothing is found */
         load: function(store,deft){
             if(this.cache[store] !== undefined){
index 2557066..8c14ae6 100644 (file)
@@ -1479,6 +1479,26 @@ function openerp_pos_models(instance, module){ //module is instance.point_of_sal
 
             return fulldetails;
         },
+        // Returns a total only for the orderlines with products belonging to the category 
+        get_total_for_category_with_tax: function(categ_id){
+            var total = 0;
+            var self = this;
+
+            if (categ_id instanceof Array) {
+                for (var i = 0; i < categ_id.length; i++) {
+                    total += this.get_total_for_category_with_tax(categ_id[i]);
+                }
+                return total;
+            }
+            
+            this.orderlines.each(function(line){
+                if ( self.pos.db.category_contains(categ_id,line.product.id) ) {
+                    total += line.get_price_with_tax();
+                }
+            });
+
+            return total;
+        },
         get_change: function(paymentline) {
             if (!paymentline) {
                 var change = this.get_total_paid() - this.get_total_with_tax();