From 14930954a26ea4b40b6b517e21c1f22ce6affbcd Mon Sep 17 00:00:00 2001 From: tanshu Date: Sun, 11 Oct 2020 16:02:41 +0530 Subject: [PATCH] Fix: Batch autocomplete would bork on empty string as it would try to split Null v8.0.1 --- brewman/brewman/__version__.py | 2 +- brewman/brewman/models/master.py | 10 ++++----- brewman/brewman/models/voucher.py | 9 ++++---- brewman/brewman/routers/account.py | 1 - brewman/brewman/routers/batch.py | 5 +---- brewman/pyproject.toml | 3 +-- overlord/.browserslistrc | 21 ++++++++++++------- overlord/package.json | 7 +++---- .../src/app/settings/settings.component.ts | 4 ++-- overlord/src/environments/environment.prod.ts | 2 +- overlord/src/environments/environment.ts | 2 +- 11 files changed, 34 insertions(+), 32 deletions(-) diff --git a/brewman/brewman/__version__.py b/brewman/brewman/__version__.py index 73d4c8be..9e17e009 100644 --- a/brewman/brewman/__version__.py +++ b/brewman/brewman/__version__.py @@ -1 +1 @@ -__version__ = "8.0.0" +__version__ = "8.0.1" diff --git a/brewman/brewman/models/master.py b/brewman/brewman/models/master.py index 83c49d47..a0079275 100644 --- a/brewman/brewman/models/master.py +++ b/brewman/brewman/models/master.py @@ -109,15 +109,15 @@ class Product(Base): @classmethod def query(cls, q, is_purchased=None, active=None, db=None): - query_ = db.query(Product) + query_ = db.query(cls) if active is not None: - query_ = query_.filter(Product.is_active == active) + query_ = query_.filter(cls.is_active == active) if is_purchased is not None: - query_ = query_.filter(Product.is_purchased == is_purchased) + query_ = query_.filter(cls.is_purchased == is_purchased) if q is not None: for item in q.split(): if item.strip() != "": - query_ = query_.filter(Product.name.ilike("%" + item + "%")) + query_ = query_.filter(cls.name.ilike(f"%{item}%")) return query_ @classmethod @@ -326,7 +326,7 @@ class AccountBase(Base): query_ = query_.filter(cls.is_active == active) if q is not None: for item in q.split(): - query_ = query_.filter(cls.name.ilike("%" + item + "%")) + query_ = query_.filter(cls.name.ilike(f"%{item}%")) return query_.order_by(cls.name) def create(self, db: Session): diff --git a/brewman/brewman/models/voucher.py b/brewman/brewman/models/voucher.py index b701b12d..16cd2195 100644 --- a/brewman/brewman/models/voucher.py +++ b/brewman/brewman/models/voucher.py @@ -391,14 +391,15 @@ class Batch(Base): ) @classmethod - def list(cls, name, include_nil, date, db: Session): - query = db.query(Batch).join(Batch.product) + def list(cls, q, include_nil, date, db: Session): + query = db.query(cls).join(cls.product) if not include_nil: query = query.filter(cls.quantity_remaining > 0) if date is not None: query = query.filter(cls.name <= date) - for item in name.split(): - query = query.filter(Product.name.ilike(f"%{item}%")) + if q is not None: + for item in q.split(): + query = query.filter(cls.name.ilike(f"%{item}%")) return query.order_by(Product.name).order_by(cls.name).all() @classmethod diff --git a/brewman/brewman/routers/account.py b/brewman/brewman/routers/account.py index 57ececbd..6008bed7 100644 --- a/brewman/brewman/routers/account.py +++ b/brewman/brewman/routers/account.py @@ -152,7 +152,6 @@ async def show_term( current_user: UserToken = Depends(get_user), ): count = c - list_ = [] for index, item in enumerate(AccountBase.query(q, t, r, a, db)): list_.append({"id": item.id, "name": item.name}) diff --git a/brewman/brewman/routers/batch.py b/brewman/brewman/routers/batch.py index 3491fc6e..82b8aa02 100644 --- a/brewman/brewman/routers/batch.py +++ b/brewman/brewman/routers/batch.py @@ -29,12 +29,9 @@ def batch_term( db: Session = Depends(get_db), current_user: UserToken = Depends(get_user), ): - filter_ = q if q is not None and q.strip() != "" else None date = None if not d else datetime.datetime.strptime(d, "%d-%b-%Y") list_ = [] - for index, item in enumerate( - Batch.list(filter_, include_nil=False, date=date, db=db) - ): + for index, item in enumerate(Batch.list(q, include_nil=False, date=date, db=db)): text = f"{item.product.name} ({item.product.units}) {item.quantity_remaining:.2f}@{item.rate:.2f} from {item.name.strftime('%d-%b-%Y')}" list_.append( { diff --git a/brewman/pyproject.toml b/brewman/pyproject.toml index 149573fa..f9766fce 100644 --- a/brewman/pyproject.toml +++ b/brewman/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "brewman" -version = "8.0.0" +version = "8.0.1" description = "Accounting plus inventory management for a restaurant." authors = ["tanshu "] @@ -41,7 +41,6 @@ skip_glob = ["*/setup.py"] filter_files = true known_first_party = "poetry" - [tool.black] line-length = 88 include = '\.pyi?$' diff --git a/overlord/.browserslistrc b/overlord/.browserslistrc index 37371cb0..0ccadaf3 100644 --- a/overlord/.browserslistrc +++ b/overlord/.browserslistrc @@ -1,11 +1,18 @@ -# This file is currently used by autoprefixer to adjust CSS to support the below specified browsers +# This file is used by the build system to adjust CSS and JS output to support the specified browsers below. # For additional information regarding the format and rule options, please see: # https://github.com/browserslist/browserslist#queries -# -# For IE 9-11 support, please remove 'not' from the last line of the file and adjust as needed -> 0.5% -last 2 versions +# For the full list of supported browsers by the Angular framework, please see: +# https://angular.io/guide/browser-support + +# You can see what browsers were selected by your queries by running: +# npx browserslist + +last 1 Chrome version +last 1 Firefox version +last 2 Edge major versions +last 2 Safari major versions +last 2 iOS major versions Firefox ESR -not dead -not IE 9-11 \ No newline at end of file +not IE 9-10 # Angular support for IE 9-10 has been deprecated and will be removed as of Angular v11. To opt-in, remove the 'not' prefix on this line. +not IE 11 # Angular supports IE 11 only as an opt-in. To opt-in, remove the 'not' prefix on this line. diff --git a/overlord/package.json b/overlord/package.json index eac74cad..32adfef6 100644 --- a/overlord/package.json +++ b/overlord/package.json @@ -1,14 +1,14 @@ { "name": "overlord", - "version": "8.0.0", + "version": "8.0.1", "scripts": { "ng": "ng", - "eslint": "eslint", "start": "ng serve", "build": "ng build", "test": "ng test", "lint": "ng lint", "e2e": "ng e2e", + "eslint": "eslint", "prettier": "prettier", "husky": "husky" }, @@ -76,8 +76,7 @@ }, "husky": { "hooks": { - "pre-commit": "lint-staged", - "pre-push": "ng build --prod" + "pre-commit": "lint-staged" } }, "lint-staged": { diff --git a/overlord/src/app/settings/settings.component.ts b/overlord/src/app/settings/settings.component.ts index dcb64249..a228efd5 100644 --- a/overlord/src/app/settings/settings.component.ts +++ b/overlord/src/app/settings/settings.component.ts @@ -7,7 +7,7 @@ import * as moment from 'moment'; import { Observable, of as observableOf } from 'rxjs'; import { debounceTime, distinctUntilChanged, map, startWith, switchMap } from 'rxjs/operators'; -import { environment } from '../../environments/environment'; +import {environment} from "../../environments/environment"; import { AuthService } from '../auth/auth.service'; import { Product } from '../core/product'; import { ToasterService } from '../core/toaster.service'; @@ -182,7 +182,7 @@ export class SettingsComponent implements OnInit { listenToProductChanges() { this.products = this.resetStockForm.get('product').valueChanges.pipe( - startWith(null), + startWith(''), map((x) => (x !== null && x.length >= 1 ? x : null)), debounceTime(150), distinctUntilChanged(), diff --git a/overlord/src/environments/environment.prod.ts b/overlord/src/environments/environment.prod.ts index c27b5ee5..3d56a26a 100644 --- a/overlord/src/environments/environment.prod.ts +++ b/overlord/src/environments/environment.prod.ts @@ -1,5 +1,5 @@ export const environment = { production: true, ACCESS_TOKEN_REFRESH_MINUTES: 10, // refresh token 10 minutes before expiry - version: '8.0.0', + version: '8.0.1', }; diff --git a/overlord/src/environments/environment.ts b/overlord/src/environments/environment.ts index 402d0efb..bbb8d266 100644 --- a/overlord/src/environments/environment.ts +++ b/overlord/src/environments/environment.ts @@ -5,7 +5,7 @@ export const environment = { production: false, ACCESS_TOKEN_REFRESH_MINUTES: 10, // refresh token 10 minutes before expiry - version: '8.0.0', + version: '8.0.1', }; /*