def destruction_pv_mark_as_signed(obj: DestructionPV) -> bool: if obj.copies.all().filter(state=STATE_PRESENT).count() != obj.copies.all().count(): return False obj.step = DestructionPV.PV_SIGNED obj.save() obj.copies.all().filter(state=STATE_PRESENT).update(state=STATE_DESTROYED) return True
def destruction_pv_create(copies) -> DestructionPV: copies = [x for x in copies if x.state == STATE_PRESENT] if not copies: return None count = RecordNumbers.get_next_record('destruction') record_number = '%s/destruction/%s' % (settings.RECORD_PREFIX, count) code_1d = '%s%05d%07d' % (DestructionPV.PREFIX_1D, settings.EAN13_IDENTIFIER, count) obj = DestructionPV(step=DestructionPV.PV_WAITING, emission_date=datetime.datetime.now(tz=utc), ministry=settings.MINISTRY, organization=settings.ORGANIZATION, location=settings.LOCATION, record_number=record_number, self_issued=True, code_1d=code_1d, signature=get_signature(record_number)) obj.save() obj.copies.add(*copies) return obj
def test_2d(self): doc_1 = ClassifiedDocument(record_number='record-1', classification=SD) doc_1.save() code_1d = '%s%05d%07d' % (Copy.PREFIX_1D, settings.EAN13_IDENTIFIER, 1) copy_1 = Copy(document=doc_1, copy_identifier=1, reproduction_identifier=None, self_issued=True, signature=get_signature(doc_1.record_number), code_1d=code_1d) copy_1.save() record_number = 'pv-1' obj_1 = DestructionPV(record_number=record_number, signature=get_signature(record_number), code_1d=code_1d) obj_1.save() obj_1.copies.add(copy_1) self.assertEqual(obj_1.to_2d(), 'pv-1:pv-1:1000010000001:record-1;SD;1;-') result = obj_1.to_2d() result += ':record-2;SD;2;-' obj_2 = DestructionPV.from_2d(result) self.assertEqual(obj_2.record_number, record_number) self.assertEqual(2, obj_2.copies.all().count()) self.assertEqual(1, ClassifiedDocument.objects.filter(record_number='record-2', classification=SD).count())