Fix: Batch autocomplete would bork on empty string as it would try to split Null

v8.0.1
This commit is contained in:
tanshu committed 2020-10-11 16:02:41 +05:30
1 parent 889cac237c
commit 14930954a2
11 files changed
+34 -32

No files matched your search

+1 -1
View File
@@ -1 +1 @@
__version__ = "8.0.0" __version__ = "8.0.1"
+5 -5
View File
@@ -109,15 +109,15 @@ class Product(Base):
@classmethod @classmethod
def query(cls, q, is_purchased=None, active=None, db=None): def query(cls, q, is_purchased=None, active=None, db=None):
query_ = db.query(Product) query_ = db.query(cls)
if active is not None: 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: 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: if q is not None:
for item in q.split(): for item in q.split():
if item.strip() != "": if item.strip() != "":
query_ = query_.filter(Product.name.ilike("%" + item + "%")) query_ = query_.filter(cls.name.ilike(f"%{item}%"))
return query_ return query_
@classmethod @classmethod
@@ -326,7 +326,7 @@ class AccountBase(Base):
query_ = query_.filter(cls.is_active == active) query_ = query_.filter(cls.is_active == active)
if q is not None: if q is not None:
for item in q.split(): 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) return query_.order_by(cls.name)
def create(self, db: Session): def create(self, db: Session):
+5 -4
View File
@@ -391,14 +391,15 @@ class Batch(Base):
) )
@classmethod @classmethod
def list(cls, name, include_nil, date, db: Session): def list(cls, q, include_nil, date, db: Session):
query = db.query(Batch).join(Batch.product) query = db.query(cls).join(cls.product)
if not include_nil: if not include_nil:
query = query.filter(cls.quantity_remaining > 0) query = query.filter(cls.quantity_remaining > 0)
if date is not None: if date is not None:
query = query.filter(cls.name <= date) query = query.filter(cls.name <= date)
for item in name.split(): if q is not None:
query = query.filter(Product.name.ilike(f"%{item}%")) for item in q.split():
query = query.filter(cls.name.ilike(f"%{item}%"))
return query.order_by(Product.name).order_by(cls.name).all() return query.order_by(Product.name).order_by(cls.name).all()
@classmethod @classmethod
-1
View File
@@ -152,7 +152,6 @@ async def show_term(
current_user: UserToken = Depends(get_user), current_user: UserToken = Depends(get_user),
): ):
count = c count = c
list_ = [] list_ = []
for index, item in enumerate(AccountBase.query(q, t, r, a, db)): for index, item in enumerate(AccountBase.query(q, t, r, a, db)):
list_.append({"id": item.id, "name": item.name}) list_.append({"id": item.id, "name": item.name})
+1 -4
View File
@@ -29,12 +29,9 @@ def batch_term(
db: Session = Depends(get_db), db: Session = Depends(get_db),
current_user: UserToken = Depends(get_user), 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") date = None if not d else datetime.datetime.strptime(d, "%d-%b-%Y")
list_ = [] list_ = []
for index, item in enumerate( for index, item in enumerate(Batch.list(q, include_nil=False, date=date, db=db)):
Batch.list(filter_, 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')}" text = f"{item.product.name} ({item.product.units}) {item.quantity_remaining:.2f}@{item.rate:.2f} from {item.name.strftime('%d-%b-%Y')}"
list_.append( list_.append(
{ {
+1 -2
View File
@@ -1,6 +1,6 @@
[tool.poetry] [tool.poetry]
name = "brewman" name = "brewman"
version = "8.0.0" version = "8.0.1"
description = "Accounting plus inventory management for a restaurant." description = "Accounting plus inventory management for a restaurant."
authors = ["tanshu <git@tanshu.com>"] authors = ["tanshu <git@tanshu.com>"]
@@ -41,7 +41,6 @@ skip_glob = ["*/setup.py"]
filter_files = true filter_files = true
known_first_party = "poetry" known_first_party = "poetry"
[tool.black] [tool.black]
line-length = 88 line-length = 88
include = '\.pyi?$' include = '\.pyi?$'
+14 -7
View File
@@ -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: # For additional information regarding the format and rule options, please see:
# https://github.com/browserslist/browserslist#queries # 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% # For the full list of supported browsers by the Angular framework, please see:
last 2 versions # 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 Firefox ESR
not dead 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 9-11 not IE 11 # Angular supports IE 11 only as an opt-in. To opt-in, remove the 'not' prefix on this line.
+3 -4
View File
@@ -1,14 +1,14 @@
{ {
"name": "overlord", "name": "overlord",
"version": "8.0.0", "version": "8.0.1",
"scripts": { "scripts": {
"ng": "ng", "ng": "ng",
"eslint": "eslint",
"start": "ng serve", "start": "ng serve",
"build": "ng build", "build": "ng build",
"test": "ng test", "test": "ng test",
"lint": "ng lint", "lint": "ng lint",
"e2e": "ng e2e", "e2e": "ng e2e",
"eslint": "eslint",
"prettier": "prettier", "prettier": "prettier",
"husky": "husky" "husky": "husky"
}, },
@@ -76,8 +76,7 @@
}, },
"husky": { "husky": {
"hooks": { "hooks": {
"pre-commit": "lint-staged", "pre-commit": "lint-staged"
"pre-push": "ng build --prod"
} }
}, },
"lint-staged": { "lint-staged": {
@@ -7,7 +7,7 @@ import * as moment from 'moment';
import { Observable, of as observableOf } from 'rxjs'; import { Observable, of as observableOf } from 'rxjs';
import { debounceTime, distinctUntilChanged, map, startWith, switchMap } from 'rxjs/operators'; 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 { AuthService } from '../auth/auth.service';
import { Product } from '../core/product'; import { Product } from '../core/product';
import { ToasterService } from '../core/toaster.service'; import { ToasterService } from '../core/toaster.service';
@@ -182,7 +182,7 @@ export class SettingsComponent implements OnInit {
listenToProductChanges() { listenToProductChanges() {
this.products = this.resetStockForm.get('product').valueChanges.pipe( this.products = this.resetStockForm.get('product').valueChanges.pipe(
startWith(null), startWith(''),
map((x) => (x !== null && x.length >= 1 ? x : null)), map((x) => (x !== null && x.length >= 1 ? x : null)),
debounceTime(150), debounceTime(150),
distinctUntilChanged(), distinctUntilChanged(),
@@ -1,5 +1,5 @@
export const environment = { export const environment = {
production: true, production: true,
ACCESS_TOKEN_REFRESH_MINUTES: 10, // refresh token 10 minutes before expiry ACCESS_TOKEN_REFRESH_MINUTES: 10, // refresh token 10 minutes before expiry
version: '8.0.0', version: '8.0.1',
}; };
+1 -1
View File
@@ -5,7 +5,7 @@
export const environment = { export const environment = {
production: false, production: false,
ACCESS_TOKEN_REFRESH_MINUTES: 10, // refresh token 10 minutes before expiry ACCESS_TOKEN_REFRESH_MINUTES: 10, // refresh token 10 minutes before expiry
version: '8.0.0', version: '8.0.1',
}; };
/* /*