Repository URL to install this package:
|
Version:
0.4.139 ▾
|
lib-py-b2b
/
inventory.py
|
|---|
from lib_b2b.erp import ERPOrderLine
from py_aws_oracle_util import fetch
from .errors import NotFoundError
from pprint import pformat
from aws_xray_sdk.core import xray_recorder
class InventoryItem:
serialized_query = """SELECT
c.WO_NUM,
c.WO_LINE,
c.WC,
c.MACHINE,
c.LOT,
c.CONTAINER_ID,
c.EMPLOYEE_ID,
c.COMP_DATE,
c.TRANSACTION_TIME,
c.GRAM_WEIGHT,
c.ITEM,
c.REVISION,
i.HEIGHT,
i.WIDTH,
i.LENGTH,
i.WEIGHT,
i.WEIGHT_UM
FROM BMC_MACHINE_COMP c
inner join ITEM i on i.ITEM = c.ITEM and i.REVISION = c.REVISION
WHERE
CCN=:ccn
AND trim(c.CONTAINER_ID)=:inventory_no
AND c.TRANSACTION_TYPE='completion'
AND c.REVERSED <> 'Y'
AND c.GLOVIA_TASK_STATUS IN ('COMPLETE', 'BACKFLUSH_FAILED')"""
lotted_query = """select
i.ITEM,
i.REVISION,
i.WEIGHT,
i.WEIGHT_UM,
i.HEIGHT,
i.WIDTH,
i.LENGTH,
l.LOT,
sum(l.OH_QTY) OH_QTY
from ITEM_DET l
INNER JOIN ITEM i ON i.ITEM = l.ITEM and i.REVISION = l.REVISION
where
LOT_SER_CCN=:ccn
AND trim(LOT)=:inventory_no
GROUP BY i.ITEM,
i.REVISION,
i.WEIGHT,
i.WEIGHT_UM,
i.HEIGHT,
i.WIDTH,
i.LENGTH,
l.LOT
"""
@staticmethod
@xray_recorder.capture()
def fetch(is_serialized, ccn, inventory_no):
statement = InventoryItem.serialized_query if is_serialized else InventoryItem.lotted_query
orders = fetch(
sql=statement,
parameters={'ccn': ccn, 'inventory_no': inventory_no.strip()},
config_path="/erp/tdb"
)
if orders:
if is_serialized:
return SerializedInventoryItem.create(orders[0])
else:
return LottedInventoryItem.create(orders[0])
else:
raise NotFoundError(f"Unable to find completion records for ccn:{ccn}, "
f"inventory_no:{inventory_no}")
def __init__(self, inventory_no, item, revision, actual_weight, weight_um, standard_weight, length, width, height):
self.inventory_no = inventory_no
self.item = item
self.revision = revision
self.standard_weight = standard_weight
self.weight_um = weight_um
self.actual_weight = actual_weight
self.length = length
self.width = width
self.height = height
def matches(self, order: ERPOrderLine):
return self.item.strip() == order.item and self.revision.strip() == order.item_revision
def __repr__(self):
return "<" + type(self).__name__ + "> " + pformat(vars(self), indent=2, width=1)
def __str__(self):
return pformat(vars(self), indent=2, width=1)
class SerializedInventoryItem(InventoryItem):
@staticmethod
def create(results):
return SerializedInventoryItem(
inventory_no=results['CONTAINER_ID'],
wo=results['WO_NUM'],
wo_line=results['WO_LINE'],
work_center=results['WC'],
machine=results['MACHINE'],
lot=results['LOT'],
container_id=results['CONTAINER_ID'],
employee_id=results['EMPLOYEE_ID'],
completion_date=results['COMP_DATE'],
transaction_time=results['TRANSACTION_TIME'],
actual_weight=results['GRAM_WEIGHT'],
weight_um=results['WEIGHT_UM'],
standard_weight=results['WEIGHT'],
item=results['ITEM'],
revision=results['REVISION'],
length=results['LENGTH'],
width=results['WIDTH'],
height=results['HEIGHT']
)
def __init__(self, inventory_no, wo, wo_line, work_center, machine, lot, container_id, employee_id, completion_date,
transaction_time, actual_weight, weight_um, standard_weight, item, revision, length, width, height):
# self.inventory_no = inventory_no
super().__init__(inventory_no, item, revision, actual_weight, weight_um, standard_weight, length, width, height)
self.wo = wo
self.wo_line = wo_line
self.work_center = work_center
self.machine = machine
self.lot = lot
self.container_id = container_id
self.employee_id = employee_id
self.completion_date = completion_date
self.transaction_time = transaction_time
def __repr__(self):
return "<" + type(self).__name__ + "> " + pformat(vars(self), indent=2, width=1)
def __str__(self):
return pformat(vars(self), indent=2, width=1)
class LottedInventoryItem(InventoryItem):
@staticmethod
def create(results):
return LottedInventoryItem(
inventory_no=results['LOT'],
lot=results['LOT'],
standard_weight=results['WEIGHT'],
weight_um=results['WEIGHT_UM'],
item=results['ITEM'],
revision=results['REVISION'],
oh_qty=results['OH_QTY'],
length=results['LENGTH'],
width=results['WIDTH'],
height=results['HEIGHT']
)
def __init__(self, inventory_no, lot, weight_um, standard_weight, item, revision, oh_qty, length, width, height):
# self.inventory_no = inventory_no
super().__init__(inventory_no, item, revision, None, weight_um, standard_weight, length, width, height)
self.lot = lot
self.oh_qty = oh_qty
def __repr__(self):
return "<" + type(self).__name__ + "> " + pformat(vars(self), indent=2, width=1)
def __str__(self):
return pformat(vars(self), indent=2, width=1)