def create_asset_model(self, model_name): try: model = AssetModel.objects.get(name=model_name) except AssetModel.DoesNotExist: model = AssetModel() model.name = model_name model.save() return model
def create_asset(self, record_id, roolback=True): obj = ImportRecord.objects.get(id=record_id) date = obj.date or None obj.device_id, crtd = Device.objects.get_or_create(sn=obj.sn) ass = Asset.create( base_args=dict( type=AssetType.data_center, model=AssetModel.concurrent_get_or_create(name=obj.model)[0], category=AssetCategory.concurrent_get_or_create( name=obj.device_type,defaults=dict(type=AssetCategoryType.data_center))[0], invoice_no=obj.fv, price=decimal.Decimal(str(obj.invent_value.replace(',', '.')) or 0), remarks=obj.info + '\n' + 'Inw. name: ' + obj.name, niw=obj.niw, production_use_date=date, source=AssetSource.shipment, sn=obj.sn or None, barcode=obj.barcode or None, deprecation_rate=decimal.Decimal(obj.deprecation_rate.replace(',','.') or 0), warehouse=Warehouse.concurrent_get_or_create(name=obj.dc)[0], ), device_info_args=dict( ralph_device_id=obj.device_id.id, u_level=obj.u_level, u_height=obj.u_height, size=0, rack=obj.rack, ), ) obj.imported = True obj.save() return ass