def convert_hcodereport_list(data): context = [ [_('Laboratory'), _('Rooms'), _('Shelf'), _('Reactive'), _('Quantity'), _('Unit'), _('H code')] ] for result in data: reactive_id = result['reactive_id'] result['unit'] = ShelfObject.get_units(result['unit']) result['h_codes'] = ",".join(Object.objects.filter(pk=reactive_id).values_list('h_code__code', flat=True)) context.append([ result['name'], result['room'], result['furniture'], result['reactive'], result['quantity'], result['unit'], result['h_codes'] ]) return context
def convert_hcodereport_table(data): reactive_list = [] context = {} for result in data: name = result.pop('name') reactive_id = result['reactive_id'] result['unit'] = ShelfObject.get_units(result['unit']) result['h_codes'] = Object.objects.filter(pk=reactive_id).values_list( 'sustancecharacteristics__h_code__code', 'sustancecharacteristics__h_code__description') if name not in context: context[name] = len(reactive_list) reactive_list.append({'lab': name, 'reactives': []}) reactive_list[context[name]]['reactives'].append(result) return reactive_list
def make_book_objects(objects, summary=False, type_id=None): description = [ _("Code"), _("Name"), _("Type"), _("Quantity total"), _('Measurement units') ] if type_id == '0': description += [ _("Molecular formula"), _("CAS id number"), _("Is precursor?"), _("IMDG type") ] content = { 'objects': [ description, ] } objects = objects.annotate( quantity_total=Sum('shelfobject__quantity'), measurement_unit=Min('shelfobject__measurement_unit')) for object in objects: obj_info = [ object.code, object.name, object.get_type_display(), object.quantity_total, ShelfObject.get_units(object.measurement_unit) ] if type_id == '0': obj_info += [ get_molecular_formula(object), get_cas(object, ''), object.is_precursor, str(get_imdg(object, '')) ] content['objects'].append(obj_info) if not summary: for shelfobj in object.shelfobject_set.all(): content['objects'].append([ '', shelfobj.shelf.furniture.name, shelfobj.shelf.name, shelfobj.quantity, shelfobj.get_measurement_unit_display() ]) return content
def make_book_objects(objects, summary=False, type_id=None): description = [ _("Code"), _("Name"), _("Type"), _( "Quantity total"), _('Measurement units') ] if type_id == '0': description += [ _("Molecular formula"), _("CAS id number"), _("Is precursor?"), _("IMDG type") ] content = { 'objects': [ description, ] } objects = objects.annotate(quantity_total=Sum('shelfobject__quantity'), measurement_unit=Min('shelfobject__measurement_unit')) for object in objects: obj_info = [ object.code, object.name, object.get_type_display(), object.quantity_total, ShelfObject.get_units(object.measurement_unit)] if type_id == '0': obj_info += [ object.molecular_formula, object.cas_id_number, object.is_precursor, object.get_imdg_code_display()] content['objects'].append(obj_info) if not summary: for shelfobj in object.shelfobject_set.all(): content['objects'].append(['', shelfobj.shelf.furniture.name, shelfobj.shelf.name, shelfobj.quantity, shelfobj.get_measurement_unit_display() ]) return content
def setUp(self): self.user = User(username='******', email="*****@*****.**", is_active=True, is_staff=True, is_superuser=True) self.user.set_password('test') self.user.save() self.client = APIClient() count = 4 # laboratory for il in range(count): laboratory = Laboratory(name="Lab %i" % il, phone_number='884665435') laboratory.save() self.lab = laboratory # ObjectFeatures for i in range(count): of = ObjectFeatures(name=i) of.save() self.feature = of #objects for io in range(count): object = Object( code="LBC-0003", name="Ácido %i" % io, type="0", description="Corrosivo", molecular_formula="H2SO4", cas_id_number="7664-93-9", is_precursor=True, imdg_code="8", ) object.save() object.features.add(of) self.object = object # labroom for il in range(count): lab = LaboratoryRoom(name="Sala %i" % il) lab.save() self.labroom = lab laboratory.rooms.add(lab) # Furniture for ifu in range(count): ofurniture = Furniture(name="A-%i Escritorio" % ifu, type='F', dataconfig="[[[],[]]]", labroom=lab) ofurniture.save() self.furniture = ofurniture # Shelf for ish in range(count): shelf = Shelf(name="Tapas cd-%i" % ish, type="C", furniture=ofurniture, container_shelf=None) shelf.save() ofurniture.change_shelf_dataconfig(0, 0, shelf.pk) self.shelf = shelf # Shelfobject for isho in range(count): oshelf = ShelfObject(quantity=1, limit_quantity=0, measurement_unit="3", shelf=shelf, object=object) oshelf.save() self.shelfO = oshelf