Stored procedure helpers. Order repo and model. More SQLService updates.
* A generic stored procedure helper added, and support for calling them. * Order and OrderItem tables added, including helpers and calls to SP for creation and updates. * Minor updates to other repositories.
This commit is contained in:
parent
b77a7069ce
commit
0af38e286e
9 changed files with 730 additions and 138 deletions
|
|
@ -1,6 +1,7 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
from pyjeeves.models.raw import Article as ArticleModel, ProductClass, ArticleClass, CommodityGroup
|
||||
from pyjeeves.models import db
|
||||
from sqlalchemy.sql.expression import and_
|
||||
from sqlalchemy.orm.exc import NoResultFound
|
||||
|
||||
|
|
@ -10,14 +11,14 @@ logger = logging.getLogger("PyJeeves." + __name__)
|
|||
|
||||
# Relocate Jeeves modules to separate folder and let a "master" module handle imports, and setup.
|
||||
class Article():
|
||||
"""Handles articles in Jeeves"""
|
||||
"""Handles articles in Jeeves, currently filters out all articles with class = 2"""
|
||||
|
||||
@staticmethod
|
||||
def get(art_no):
|
||||
""" Query an article by number """
|
||||
try:
|
||||
return ArticleModel.query.filter_by(
|
||||
ArtNr=art_no
|
||||
return db.raw.query(ArticleModel).filter_by(
|
||||
ArtNr=str(art_no)
|
||||
).one()
|
||||
except NoResultFound:
|
||||
raise KeyError
|
||||
|
|
@ -25,7 +26,29 @@ class Article():
|
|||
@staticmethod
|
||||
def get_all(filter_=and_(ArticleModel.ItemStatusCode == 0, ArticleModel.ArtKod != 2)):
|
||||
# .filter_by(ItemStatusCode=0, ArtKod=2)
|
||||
return ArticleModel.query.filter(filter_).all()
|
||||
return db.raw.query(ArticleModel).filter(filter_).all()
|
||||
|
||||
@staticmethod
|
||||
def is_salable(art_no_list=[]):
|
||||
""" Returns true if all articles are salable,
|
||||
else false with error information """
|
||||
articles = db.raw.query(ArticleModel).filter(
|
||||
and_(ArticleModel.ArtNr.in_(art_no_list))).all()
|
||||
|
||||
blocked_articles = [article.ArtNr for article in articles
|
||||
if article.ArtKod == 2 or article.ItemStatusCode != 0]
|
||||
unknown_articles = [x for x in art_no_list
|
||||
if x not in set([article.ArtNr for article in articles])]
|
||||
|
||||
if blocked_articles or unknown_articles:
|
||||
errors = {}
|
||||
if blocked_articles:
|
||||
errors['blocked_articles'] = blocked_articles
|
||||
if unknown_articles:
|
||||
errors['unknown_articles'] = unknown_articles
|
||||
return False, errors
|
||||
|
||||
return True, {}
|
||||
|
||||
|
||||
class ArticleCategory():
|
||||
|
|
@ -34,9 +57,9 @@ class ArticleCategory():
|
|||
@staticmethod
|
||||
def get_all():
|
||||
# .filter_by(ItemStatusCode=0, ArtKod=2)
|
||||
prod_classes = ProductClass.query.all()
|
||||
art_classes = ArticleClass.query.all()
|
||||
com_groups = CommodityGroup.query.all()
|
||||
prod_classes = db.raw.query(ProductClass).all()
|
||||
art_classes = db.raw.query(ArticleClass).all()
|
||||
com_groups = db.raw.query(CommodityGroup).all()
|
||||
|
||||
return {'ProductClasses': prod_classes,
|
||||
'ArticleClasses': art_classes, 'CommodityGroups': com_groups}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue