PyJeeves/pyjeeves/repositories/company.py
Marcus Lindvall 0af38e286e 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.
2019-08-30 12:09:10 +02:00

56 lines
1.6 KiB
Python

# -*- coding: utf-8 -*-
from pyjeeves.models.raw import Company as CompanyModel, Customer as CustomerModel
from pyjeeves.models import db
from sqlalchemy.sql.expression import and_
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 Company():
"""Handles companies in Jeeves"""
@staticmethod
def get(ftg_nr):
""" Query an article by number """
return db.raw.query(CompanyModel).filter_by(
FtgNr=ftg_nr
).one()
@staticmethod
def get_all_active_customers():
cust = db.raw.query(CustomerModel).filter(and_(CustomerModel.Makulerad == 0)).all()
return [c.CompanyModel for c in cust]
@staticmethod
def get_list(ftg_nr=[]):
return db.raw.query(CompanyModel).filter(
CompanyModel.FtgNr.in_(ftg_nr)
).all()
if __name__ == '__main__':
# print([column.key for column in CompanyModel.__table__.columns])
logger.info("Starting TEST")
# session = RawSession()
logger.info("Testing gettings a company")
# c1 = session.query(CompanyModel).filter_by(FtgNr="179580").first()
# print(CompanyModel)
# print(CompanyModel.get_list(['406569', '179580', '2440070', '179584']))
from pprint import pprint
pprint(CompanyModel.get('179584').to_dict())
# c1 = CompanyModel.query.filter_by(FtgNr="406569").first()
# print(c1)
# logger.info(c1.json)
# print(
# len(CompanyModel.get_all_active_customers())
# )
# print(CompanyModel.get_all_active_customers()[0].CompanyModel)