"""Model for the UKPhysicalProductView.""" from collections import OrderedDict from sqlalchemy import Column, Integer, String from sqlalchemy.ext.declarative import declarative_base from reporting.models.persister import get_all, get_filter from reporting.utils.physical_reporting import ProductSharedFieldsMixin BaseModel = declarative_base() class UKPhysicalProductView(ProductSharedFieldsMixin, BaseModel): """The United Kingdom Product View.""" __tablename__ = 'UK_PHYSICAL_PRODUCT_VIEW' upc_ean = Column( String(14), nullable=True, name='UPC/EAN', primary_key=True ) product_code = Column( String(18), nullable=True, name='Product Code', primary_key=True ) allocated = Column(Integer, nullable=True, name='Allocated') faulty = Column(Integer, nullable=True, name='Faulty') consignment = Column(Integer, nullable=True, name='Consignment') @classmethod def all(cls, params): """Get all for UK Product View.""" filters = [ 'artist', 'product_type', 'product_name', 'sub_label', 'release_date', 'vendor_id', 'subacct_id', 'product_code', 'upc_ean', ] return get_all(cls, params, filters) @classmethod def filter(cls, vendor_id, subacct_id): """Get filter for UK Product View.""" filter_data = [ {'column': 'Sub Label', 'alias': 'sub_label'}, {'column': 'Product Type', 'alias': 'product_type'}, {'column': 'Product Name', 'alias': 'product_name'}, {'column': 'Artist', 'alias': 'artist'}, {'column': 'UPC/EAN', 'alias': 'upc_ean'}, {'column': 'Product Code', 'alias': 'product_code'}, ] return get_filter( cls.__tablename__, vendor_id, subacct_id, filter_data, filter_out_generic_products=False, ) @classmethod def headers(cls): """Get all headers.""" return [x for x in cls().to_dict().keys()] def to_dict(self): """To dictionary.""" data = OrderedDict() data['Product Name'] = self.product_name data['Artist'] = self.artist data['Label Name'] = self.label_name data['Sub Label'] = self.sub_label data['Genre'] = self.genre data['Sub Genre'] = self.sub_genre data['Product Code'] = self.product_code data['UPC/EAN'] = self.upc_ean try: data['Release Date'] = self.release_date.isoformat() except AttributeError: data['Release Date'] = '' data['Product Type'] = self.product_type data['Format'] = self.product_format data['Units Per Set'] = self.units_per_set data['Display Configuration'] = self.display_configuration data['Exclusive'] = self.exclusive data['On Hand'] = self.on_hand data['Available'] = self.available data['Allocated'] = self.allocated data['Faulty'] = self.faulty data['Consignment'] = self.consignment return data