def _prices_per_venture_device_details(device, exclude=[]): components, stock = [], [] total = 0 for detail in _get_details( device, ignore_deprecation=True, exclude=exclude, ): model = detail.get('model') price = detail.get('price') or 0 if not model: components.append({ 'model': 'n/a', 'icon': 'n/a', 'count': 'n/a', 'price': 'n/a', 'serial': 'n/a', }) if model not in stock: components.append({ 'model': model.name if hasattr(model, 'name') else model, 'icon': detail.get('icon'), 'count': 1, 'price': price, 'serial': detail.get('serial'), }) else: for component in components: if component['model'] == model: component['count'] = component['count'] + 1 total += price stock.append(model) venture = 'N/a' if device.venture and device.venture.symbol: venture = device.venture.symbol return { 'device': { 'id': device.id, 'name': device.name, 'sn': device.sn, 'barcode': device.barcode, 'deprecation_date': device.deprecation_date, 'cached_price': device.cached_price, 'icon': get_device_icon(device), 'venture': venture, 'role': device.role or 'N/a', }, 'components': components, 'total': total, 'deprecated': device.is_deprecated(), }
def get_context_data(self, **kwargs): ret = super(View, self).get_context_data(**kwargs) ret.update( { "ci": self.ci, "label": "View CI - " + self.ci.name, "url_query": self.request.GET, "components": _get_details(self.ci.content_object, purchase_only=False), } ) return ret
def get_context_data(self, **kwargs): ret = super(View, self).get_context_data(**kwargs) ret.update({ 'ci': self.ci, 'label': 'View CI: {} (uid: {})'.format(self.ci.name, self.ci.uid), 'url_query': self.request.GET, 'components': _get_details( self.ci.content_object, purchase_only=False ) }) return ret
def dehydrate(self, bundle): device = bundle.obj details = _get_details(bundle.obj) components = dict() total = 0 for detail in details: model = detail.get('model') price = detail.get('price') or 0 model_type = None model_name = str(model) if hasattr(model, 'type'): try: model_type = ComponentType.from_id(model.type) except ValueError: pass if model_type and model_type == ComponentType.software: model = ComponentType.software.name, model_name = model if not components.get(model_name): components[model_name] = { 'model': model, 'count': 1, 'price': price, 'serial': detail.get('serial'), } else: components[model_name]['count'] += 1 total += price bundle.data['components'] = components.values() bundle.data['total_cost'] = total bundle.data['deprecated'] = device.is_deprecated() splunk_start = bundle.request.GET.get('splunk_start') splunk_end = bundle.request.GET.get('splunk_end') if splunk_start and splunk_end: try: splunk_start = datetime.datetime.strptime( splunk_start, '%Y-%m-%d', ) splunk_end = datetime.datetime.strptime( splunk_end, '%Y-%m-%d', ) except ValueError: splunk_start, splunk_end = None, None splunk = self.splunk_cost(bundle.obj, splunk_start, splunk_end) bundle.data['splunk'] = splunk return bundle
def dehydrate(self, bundle): device = bundle.obj details = _get_details(bundle.obj) components = dict() total = 0 for detail in details: model = detail.get("model") price = detail.get("price") or 0 model_type = None model_name = str(model) if hasattr(model, "type"): try: model_type = ComponentType.from_id(model.type) except ValueError: pass if model_type and model_type == ComponentType.software: model = (ComponentType.software.name,) model_name = model if not components.get(model_name): components[model_name] = {"model": model, "count": 1, "price": price, "serial": detail.get("serial")} else: components[model_name]["count"] += 1 total += price bundle.data["components"] = components.values() bundle.data["total_cost"] = total bundle.data["deprecated"] = device.is_deprecated() splunk_start = bundle.request.GET.get("splunk_start") splunk_end = bundle.request.GET.get("splunk_end") if splunk_start and splunk_end: try: splunk_start = datetime.datetime.strptime(splunk_start, "%Y-%m-%d") splunk_end = datetime.datetime.strptime(splunk_end, "%Y-%m-%d") except ValueError: splunk_start, splunk_end = None, None splunk = self.splunk_cost(bundle.obj, splunk_start, splunk_end) bundle.data["splunk"] = splunk return bundle
def get_device_with_components(self, venture_devices, blacklist): devices = [] for device in venture_devices: all_components_price = 0 components = [] for component in _get_details(device, ignore_deprecation=True): count = 1 model = component.get("model") if not isinstance(model, basestring): component_type = model.type component_group = model.group_id model_group = model.group else: component_group = None component_type = None model_group = None act_components = [x.get("name") for x in components] if model not in act_components and component_type not in blacklist: if is_bladesystem(component): bs_count = device.child_set.filter(deleted=False).count() or 1 chassis_price = get_device_chassis_price(device) auto_price = get_device_auto_price(device) bs_price = 0 if device.price != 0: bs_price = device.price / bs_count elif chassis_price != 0: bs_price = chassis_price elif auto_price != 0: bs_price = auto_price / bs_count components.append( { "icon": component.get("icon"), "name": model, "price": bs_price, "count": count, "bs_count": bs_count, } ) elif component_type == ComponentType.share: components.append( { "icon": component.get("icon"), "name": model, "price": component.get("price") or 0, "count": component.get("count") or 1, } ) else: d_price = 0 if device.price and device.price != 0: d_price = device.price else: d_price = component.get("price") or 0 components.append( { "icon": component.get("icon"), "name": model, "price": d_price, "model_group": model_group, "count": count, } ) else: for component in components: if component.get("name") == model: count = component.get("count") component.update(count=count + 1) for component in components: count = component.get("count") price = component.get("price") total_component = price * count component["total_component"] = total_component all_components_price += total_component devices.append( { "device": device, "deprecated": is_deprecated(device), "price": all_components_price, "components": components, } ) return devices