"""Model for the USPhysicalRetailerViewCoop.""" from sqlalchemy import Column, Integer from reporting.models.persister import get_all, get_filter from reporting.models.us_physical_retailer_view import USPhysicalRetailerView class USPhysicalRetailerViewCoop(USPhysicalRetailerView): """US Physical Coop View model.""" coop_expired_amount = Column( Integer, nullable=True, name='COOP_EXPIRED_LABEL_AM' ) coop_open_amount = Column( Integer, nullable=True, name='COOP_OPEN_LABEL_AM' ) coop_closed_amount = Column( Integer, nullable=True, name='COOP_CLOSED_LABEL_AM' ) @classmethod def all(cls, params): """Get all for US Product View.""" filters = [ 'artist', 'product_status', '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, subaccount_id): """Get filter for US Product View.""" return get_filter( cls.__tablename__, vendor_id, subaccount_id, cls.filter_data, filter_out_generic_products=False, ) @classmethod def headers(cls): """Get all headers.""" return [x for x in cls().to_dict().keys() if x != 'local_product_cd'] def total_coop_rtd_amount(self): """Total Co-Op spend.""" open_am = self.coop_open_amount or 0 expired_am = self.coop_expired_amount or 0 closed_am = self.coop_closed_amount or 0 return sum([open_am, expired_am, closed_am]) def open_coop_amount(self): """Open Co-Op spend.""" open_am = self.coop_open_amount or 0 expired_am = self.coop_expired_amount or 0 return sum([open_am, expired_am]) def to_dict(self): """To dictionary.""" data = USPhysicalRetailerView.to_dict(self) data['Total RTD Co-Op $'] = self.total_coop_rtd_amount() data['Closed Co-Op $'] = self.coop_closed_amount data['Open Co-Op $'] = self.open_coop_amount() return data