(self)
| 21 | self.savedStateCheckChanges = None |
| 22 | |
| 23 | def Do(self): |
| 24 | pyfalog.debug('Doing addition of projected fit {} for fit {}'.format(self.projectedFitID, self.fitID)) |
| 25 | sFit = Fit.getInstance() |
| 26 | fit = sFit.getFit(self.fitID) |
| 27 | projectedFit = sFit.getFit(self.projectedFitID, projected=True) |
| 28 | |
| 29 | # Projected fit could have been deleted if we are redoing |
| 30 | if projectedFit is None: |
| 31 | pyfalog.debug('Projected fit is not available') |
| 32 | return False |
| 33 | |
| 34 | # If we already have info about projection - means that fit is already projected |
| 35 | # and we just need to increase amount of fits |
| 36 | if projectedFit in fit.projectedFits and projectedFit.ID in fit.projectedFitDict: |
| 37 | from .changeAmount import CalcChangeProjectedFitAmountCommand |
| 38 | self.changeAmountCommand = CalcChangeProjectedFitAmountCommand( |
| 39 | fitID=self.fitID, |
| 40 | projectedFitID=self.projectedFitID, |
| 41 | amount=self.amount, |
| 42 | relative=True) |
| 43 | if not self.changeAmountCommand.Do(): |
| 44 | return False |
| 45 | sFit.recalc(fit) |
| 46 | self.savedStateCheckChanges = sFit.checkStates(fit, None) |
| 47 | return True |
| 48 | else: |
| 49 | self.changeAmountCommand = None |
| 50 | |
| 51 | fit.projectedFitDict[projectedFit.ID] = projectedFit |
| 52 | # This bit is required, see issue #83 |
| 53 | eos.db.saveddata_session.flush() |
| 54 | eos.db.saveddata_session.refresh(projectedFit) |
| 55 | |
| 56 | if self.amount is not None or self.state is not None: |
| 57 | projectionInfo = projectedFit.getProjectionInfo(self.fitID) |
| 58 | if projectionInfo is None: |
| 59 | pyfalog.warning('Fit projection info is not available') |
| 60 | self.Undo() |
| 61 | return False |
| 62 | if self.amount is not None: |
| 63 | projectionInfo.amount = self.amount |
| 64 | if self.state is not None: |
| 65 | projectionInfo.active = self.state |
| 66 | |
| 67 | sFit.recalc(fit) |
| 68 | self.savedStateCheckChanges = sFit.checkStates(fit, None) |
| 69 | return True |
| 70 | |
| 71 | def Undo(self): |
| 72 | pyfalog.debug('Undoing addition of projected fit {} for fit {}'.format(self.projectedFitID, self.fitID)) |
no test coverage detected