* 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.
83 lines
2.8 KiB
Python
83 lines
2.8 KiB
Python
# -*- 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
|
|
|
|
from pyjeeves import logging
|
|
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, currently filters out all articles with class = 2"""
|
|
|
|
@staticmethod
|
|
def get(art_no):
|
|
""" Query an article by number """
|
|
try:
|
|
return db.raw.query(ArticleModel).filter_by(
|
|
ArtNr=str(art_no)
|
|
).one()
|
|
except NoResultFound:
|
|
raise KeyError
|
|
|
|
@staticmethod
|
|
def get_all(filter_=and_(ArticleModel.ItemStatusCode == 0, ArticleModel.ArtKod != 2)):
|
|
# .filter_by(ItemStatusCode=0, ArtKod=2)
|
|
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():
|
|
"""Handles article categories, such as classes and groups in Jeeves"""
|
|
|
|
@staticmethod
|
|
def get_all():
|
|
# .filter_by(ItemStatusCode=0, ArtKod=2)
|
|
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}
|
|
|
|
|
|
if __name__ == '__main__':
|
|
# print([column.key for column in Company.__table__.columns])
|
|
|
|
logger.info("Starting TEST")
|
|
# session = RawSession()
|
|
|
|
logger.info("Testing gettings an article")
|
|
# c1 = session.query(Company).filter_by(FtgNr="179580").first()
|
|
# print(ArticleModel)
|
|
c1 = ArticleModel.query.filter_by(ArtNr="2103").first()
|
|
print(c1)
|
|
logger.info(c1.json)
|
|
|
|
print(
|
|
len(ArticleModel.get_all())
|
|
)
|