summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrederic van der Essen <fva@openerp.com / fvdessen+o@gmail.com>2014-11-07 17:25:42 +0100
committerFrédéric van der Essen <fvdessen@gmail.com>2014-11-26 12:06:18 +0100
commitd18e7f008c9daab717f4c8ff660bd3f0d787bcd0 (patch)
tree0dca6733d2f48df72e9846d47435c79d8919b189
parent32fcfa657c7da678d3fe15ea53a8c142f53cc614 (diff)
[IMP] point_of_sale: add a method for getting totals by product categories, used for custom receipts
-rw-r--r--addons/point_of_sale/static/src/js/db.js11
-rw-r--r--addons/point_of_sale/static/src/js/models.js20
2 files changed, 31 insertions, 0 deletions
diff --git a/addons/point_of_sale/static/src/js/db.js b/addons/point_of_sale/static/src/js/db.js
index 172a7c9dcf4..2711dbcf9f9 100644
--- a/addons/point_of_sale/static/src/js/db.js
+++ b/addons/point_of_sale/static/src/js/db.js
@@ -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){
diff --git a/addons/point_of_sale/static/src/js/models.js b/addons/point_of_sale/static/src/js/models.js
index 25570664a93..8c14ae6b667 100644
--- a/addons/point_of_sale/static/src/js/models.js
+++ b/addons/point_of_sale/static/src/js/models.js
@@ -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();