"""Product Physical History Model.""" import datetime from sqlalchemy import Column from sqlalchemy import Enum from sqlalchemy import Integer from sqlalchemy import String from ows_product_physical.connector import mysql from ows_product_physical.constant import field class ProductPhysicalChangeHistory(mysql.BaseModel): """Product Physical Change History Model.""" __tablename__ = 'product_physical_change_history' change_id = Column( 'id', Integer, primary_key=True, autoincrement=True, nullable=False) artworkpath = Column(String) product_id = Column(Integer) field_name = Column(String) date_changed = Column(String, default=datetime.datetime.now) delivered = Column(Enum('Y', 'N'), default='N') store_id = Column(Integer) new_price = Column(String) old_release_date = Column(String) new_release_date = Column(String) old_sale_start_date = Column(String) new_sale_start_date = Column(String) old_embargo_date = Column(String) new_embargo_date = Column(String) def to_dict(self): """Dict-ified row of the product_physical table.""" return { 'id': self.change_id, field.ARTWORKPATH: self.artworkpath, field.PRODUCT_ID: self.product_id, field.FIELD_NAME: self.field_name, field.DATE_CHANGED: self.date_changed, field.DELIVERED: self.delivered, field.STORE_ID: self.store_id, field.NEW_PRICE: self.new_price } def create(session, **values): """Insert a product_physical_change_history row. Args: values (dict): dictionary of values to store session: database connection object """ history_change = ProductPhysicalChangeHistory(**values) session.add(history_change) session.flush()