- {{item.Code}} |
- {{item.Name}} ({{item.Units}}) |
- ₹ {{item.Price}} |
+ {{item.Code}} |
+ {{item.Name}} ({{show_extended ? item.Fraction + ' ' + item.FractionUnits + ' = 1 ' : ''}}{{item.Units}}) |
+ {{item.Price | currency}} |
+ {{item.ProductYield * 100 | number:2}}% |
{{item.ProductGroup}} |
{{item.IsActive}} |
diff --git a/brewman/static/scripts/product.js b/brewman/static/scripts/product.js
index f385bab2..a2ba4a5d 100644
--- a/brewman/static/scripts/product.js
+++ b/brewman/static/scripts/product.js
@@ -2,8 +2,8 @@
var ProductListCtrl = ['$scope', '$location', '$routeParams', 'products', function ($scope, $location, $routeParams, products) {
$scope.search = $routeParams.q || '';
+ $scope.show_extended = false;
$scope.info = products;
- var re = /((([^ ]+):\s*('[^':]+'|"[^":]+"|[^ ]+))|[^ ]+[^: '"]*)/g;
$scope.isTrue = function (value) {
value = value.toLowerCase();
@@ -16,6 +16,31 @@ var ProductListCtrl = ['$scope', '$location', '$routeParams', 'products', functi
$scope.filterProducts(newValue);
}, true);
+ $scope.parseFilterString = function (q, defaultKey) {
+ var re = /((([^ ]+):\s*('[^':]+'|"[^":]+"|[^ ]+))|[^ ]+[^: '"]*)/g;
+ var matches = [];
+ if (angular.isUndefined(defaultKey)) {
+ defaultKey = 'n';
+ }
+ var m = q.match(re);
+ _.forEach(m, function (item) {
+ item = item.toLowerCase();
+ if (item.indexOf(':') === -1) {
+ matches.push({'key': defaultKey, 'value': item});
+ } else {
+ var key = item.substr(0, item.indexOf(':')).toLowerCase();
+ var value = item.substr(item.indexOf(':') + 1, item.length).trim().toLowerCase();
+ if (value.indexOf("'") !== 0 || value.indexOf('"') !== 0) {
+ value = value.substring(1, value.length - 2).trim();
+ }
+ if (key !== '' && value !== '') {
+ matches.push({'key': key, 'value': value});
+ }
+ }
+ });
+ return matches;
+ };
+
$scope.filterProducts = _.debounce(function (q) {
if (q !== $scope._search) {
$scope._search = q;
@@ -25,35 +50,20 @@ var ProductListCtrl = ['$scope', '$location', '$routeParams', 'products', functi
$location.path('/Products').search({'q': q}).replace();
}
$scope.$apply(function () {
- $scope.products = $scope.doFilter(q);
+ var matches = $scope.parseFilterString(q);
+ $scope.show_extended = _.any(matches, function (item) {
+ return ((item.key === 'e' || item.key === 'ext') && $scope.isTrue(item.value));
+ });
+ $scope.products = $scope.doFilter(q, matches);
});
}
}, 350);
- $scope.doFilter = _.memoize(function (q) {
- var matches = [], i, len;
- if (angular.isUndefined(q) || q === '') {
+ $scope.doFilter = _.memoize(function (q, matches) {
+ var i, len = matches.length;
+ if (len <= 0) {
return $scope.info;
}
- var m = q.match(re);
- _.forEach(m, function (item) {
- item = item.toLowerCase();
- if (item.indexOf(':') === -1) {
- matches.push({'key': 'n', 'value': item});
- } else {
- var key = item.substr(0, item.indexOf(':')).toLowerCase();
- var value = item.substr(item.indexOf(':') + 1, item.length).trim().toLowerCase();
- if (value.indexOf("'") === 0 || value.indexOf('"') === 0) {
- value = value.substring(1, value.length - 2);
- }
- if (key !== '' && value !== '' && _.any(['a', 'u', 'g'], function (item) {
- return item === key;
- })) {
- matches.push({'key': key, 'value': value});
- }
- }
- });
return _.filter($scope.info, function (item) {
- len = matches.length;
for (i = 0; i < len; i++) {
var match = matches[i];
if (match.key === 'n') {
@@ -61,7 +71,7 @@ var ProductListCtrl = ['$scope', '$location', '$routeParams', 'products', functi
return false;
}
} else if (match.key === 'a') {
- if (item.IsActive === $scope.isTrue(match.value)) {
+ if (item.IsActive !== $scope.isTrue(match.value)) {
return false;
}
} else if (match.key === 'u') {
diff --git a/brewman/views/product.py b/brewman/views/product.py
index 968a60be..ce822f8f 100644
--- a/brewman/views/product.py
+++ b/brewman/views/product.py
@@ -141,7 +141,9 @@ def show_list(request):
for item in list:
products.append({'Code': item.code, 'Name': item.name, 'Units': item.units, 'Price': item.price,
'ProductGroup': item.product_group.name, 'IsActive': item.is_active,
- 'IsFixture': item.is_fixture, 'Url': request.route_url('product_id', id=item.id)})
+ 'Fraction': item.fraction, 'FractionUnits': item.fraction_units,
+ 'ProductYield': item.product_yield, 'IsFixture': item.is_fixture,
+ 'Url': request.route_url('product_id', id=item.id)})
return products