| 8 | |
| 9 | |
| 10 | class CalcAddCargoCommand(wx.Command): |
| 11 | |
| 12 | def __init__(self, fitID, cargoInfo): |
| 13 | wx.Command.__init__(self, True, 'Add Cargo') |
| 14 | self.fitID = fitID |
| 15 | self.cargoInfo = cargoInfo |
| 16 | |
| 17 | def Do(self): |
| 18 | pyfalog.debug('Doing addition of cargo {} to fit {}'.format(self.cargoInfo, self.fitID)) |
| 19 | fit = Fit.getInstance().getFit(self.fitID) |
| 20 | cargo = next((c for c in fit.cargo if c.itemID == self.cargoInfo.itemID), None) |
| 21 | if cargo is not None: |
| 22 | cargo.amount += self.cargoInfo.amount |
| 23 | else: |
| 24 | cargo = self.cargoInfo.toCargo() |
| 25 | fit.cargo.append(cargo) |
| 26 | if cargo not in fit.cargo: |
| 27 | pyfalog.warning('Failed to append to list') |
| 28 | return False |
| 29 | return True |
| 30 | |
| 31 | def Undo(self): |
| 32 | pyfalog.debug('Undoing addition of cargo {} to fit {}'.format(self.cargoInfo, self.fitID)) |
| 33 | from .remove import CalcRemoveCargoCommand |
| 34 | cmd = CalcRemoveCargoCommand(fitID=self.fitID, cargoInfo=self.cargoInfo) |
| 35 | return cmd.Do() |