In progress: Jeeves communication is now based on SQLAlchemy
This commit is contained in:
parent
0fdc029153
commit
28726fee01
21 changed files with 637 additions and 78 deletions
69
pyjeeves/repositories/location.py
Normal file
69
pyjeeves/repositories/location.py
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
from pyjeeves.models.raw import Companies, DelivLoc
|
||||
|
||||
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 Location():
|
||||
"""Handles dispatch locations in Jeeves"""
|
||||
def __init__(self):
|
||||
super(Location, self).__init__()
|
||||
self.associated_company = '' # Company with new/existing locations
|
||||
self._deliv_locs = [] # List of locations to be connected
|
||||
|
||||
def _connect_deliv_loc(self, ftgnr, description, code):
|
||||
if self.associated_company == '':
|
||||
raise
|
||||
if len(description) > 36:
|
||||
logger.warn("Truncated description %s", (description))
|
||||
description = description[:36]
|
||||
_deliv_loc = DelivLoc(
|
||||
FtgNr=self.associated_company, OrdLevPlats1=ftgnr,
|
||||
OrdLevPlBeskr=description, ForetagKod=1)
|
||||
self._deliv_locs.append(_deliv_loc)
|
||||
# self.session.merge(_deliv_loc)
|
||||
return _deliv_loc
|
||||
|
||||
def create_lev_location(self, ftgnr='', name='', address='',
|
||||
postal_code='', city='', gln='', invoice_ref='', phone=''):
|
||||
|
||||
_loc = Companies(
|
||||
FtgNr=str(ftgnr), FtgNamn=name, FtgPostadr5=address,
|
||||
FtgLevPostNr=postal_code, FtgPostLevAdr3=city,
|
||||
EAN_Loc_Code=gln, FtgPostAdr1=invoice_ref, ComNr=phone,
|
||||
ForetagKod=1)
|
||||
|
||||
# logger.debug("Adding company to location session")
|
||||
# with self.session.no_autoflush:
|
||||
# # self.session.merge(_loc) # "merge" updates if existing location exists.
|
||||
_deliv_loc = self._connect_deliv_loc(ftgnr, name, gln)
|
||||
|
||||
return _loc, _deliv_loc
|
||||
|
||||
def save_locations(self):
|
||||
logger.debug("Committing all location changes")
|
||||
# self.session.commit() # Location company needs to be created in order to connect them.
|
||||
for deliv_loc in self._deliv_locs:
|
||||
deliv_loc.merge()
|
||||
# self.session.merge(deliv_loc) # Create "connnections" between Customer and Location.
|
||||
Companies.commit()
|
||||
# self.session.commit()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
# print([column.key for column in Companies.__table__.columns])
|
||||
|
||||
logger.info("Starting TEST")
|
||||
# session = RawSession()
|
||||
|
||||
logger.info("Testing gettings a company")
|
||||
# c1 = session.query(Companies).filter_by(FtgNr="179580").first()
|
||||
print(Companies)
|
||||
c1 = Companies.query.filter_by(FtgNr="179580").first()
|
||||
logger.info(c1.json)
|
||||
# RawSession.remove()
|
||||
# from sqlalchemy.inspection import inspect
|
||||
# print (inspect(Companies).columns.items())
|
||||
Loading…
Add table
Add a link
Reference in a new issue