def getWeeksToExpire(self): """ Returns the amount of weeks untils it's certification expire """ cert = self.getLatestValidCertification() if cert == None: return '' date = cert.getValidTo().asdatetime().date(); return date - date.today()
def isCalibrationInProgress(self): """ Returns if the current instrument is under calibration progress """ calibration = self.getLatestValidCalibration() today = date.today() if calibration and calibration.getDownTo(): validfrom = calibration.getDownFrom().asdatetime().date() validto = calibration.getDownTo().asdatetime().date() if validfrom <= today <= validto: return True return False
def isOutOfDate(self): """ Returns if the current instrument is out-of-date regards to its certifications """ cert = self.getLatestValidCertification() today = date.today() if cert and cert.getValidTo(): validto = cert.getValidTo().asdatetime().date(); if validto > today: return False return True
def getValidCertifications(self): """ Returns the certifications fully valid """ certs = [] today = date.today() for c in self.getCertifications(): validfrom = c.getValidFrom() if c else None validto = c.getValidTo() if validfrom else None if not validfrom or not validto: continue validfrom = validfrom.asdatetime().date() validto = validto.asdatetime().date() if (today >= validfrom and today <= validto): certs.append(c) return certs
def test_instrument_calibration(self): # Getting all instruments instrument_names = self.portal.bika_setup.bika_instruments.keys() # Setting calibration dates for instrument_name in instrument_names: # Getting each instrument instrument = self.portal.bika_setup.bika_instruments[ instrument_name] today = date.today() # Getting last valid calibration lastcal = instrument.getLatestValidCalibration() if not lastcal: # Creating a new calibration cal_obj = _createObjectByType("InstrumentCalibration", instrument, tmpID()) cal_obj.edit(title='test', DownFrom=today.strftime("%Y/%m/%d"), DownTo=today.strftime("%Y/%m/%d"), Instrument=instrument) cal_obj.unmarkCreationFlag() renameAfterCreation(cal_obj) else: # Updating last calibration lastcal.setDownTo(today) lastcal.setDownFrom(today) # Testing calibration state for instrument_name in instrument_names: instrument = self.portal.bika_setup.bika_instruments[ instrument_name] self.assertTrue(instrument.isCalibrationInProgress()) for instrument_name in instrument_names: instrument = self.portal.bika_setup.bika_instruments[ instrument_name] anotherday = '2014/11/27' lastcal = instrument.getLatestValidCalibration() lastcal.setDownTo(anotherday) lastcal.setDownFrom(anotherday) for instrument_name in instrument_names: instrument = self.portal.bika_setup.bika_instruments[ instrument_name] self.assertFalse(instrument.isCalibrationInProgress())
def test_instrument_calibration(self): # Getting all instruments instrument_names = self.portal.bika_setup.bika_instruments.keys() # Setting calibration dates for instrument_name in instrument_names: # Getting each instrument instrument = self.portal.bika_setup.bika_instruments[instrument_name] today = date.today() # Getting last valid calibration lastcal = instrument.getLatestValidCalibration() if not lastcal: # Creating a new calibration cal_obj = _createObjectByType("InstrumentCalibration", instrument, tmpID()) cal_obj.edit( title='test', DownFrom=today.strftime("%Y/%m/%d"), DownTo=today.strftime("%Y/%m/%d"), Instrument=instrument ) cal_obj.unmarkCreationFlag() renameAfterCreation(cal_obj) else: # Updating last calibration lastcal.setDownTo(today) lastcal.setDownFrom(today) # Testing calibration state for instrument_name in instrument_names: instrument = self.portal.bika_setup.bika_instruments[instrument_name] self.assertTrue(instrument.isCalibrationInProgress()) for instrument_name in instrument_names: instrument = self.portal.bika_setup.bika_instruments[instrument_name] anotherday = '2014/11/27' lastcal = instrument.getLatestValidCalibration() lastcal.setDownTo(anotherday) lastcal.setDownFrom(anotherday) for instrument_name in instrument_names: instrument = self.portal.bika_setup.bika_instruments[instrument_name] self.assertFalse(instrument.isCalibrationInProgress())