def execute(self):
        cmd = self.command
        user = self.command.sms.user

        if RECORD_SELL not in user.permissions:
            logging.info('{} - User {} does not have permission {}'.format(
                cmd.sms.id, user.id, RECORD_SELL))
            return _('Command not allowed')

        harvest_total = Farm.query(ndb.AND(Farm.district_id == user.district_id,
                                           Farm.crop_name == cmd.plant,
                                           Farm.action == 'harvest')).get()

        if not harvest_total or harvest_total.quantity < cmd.amount:
            logging.info('{} - Not enough {} harvested'.format(cmd.sms.id,
                                                               cmd.plant))
            return _('Not enough {} harvested').format(cmd.plant)

        sell_total = Farm.query(ndb.AND(Farm.district_id == user.district_id,
                                        Farm.crop_name == cmd.plant,
                                        Farm.action == 'sell')).get()
        if not sell_total:
            sell_total = Farm(id=Farm.id(),
                              district_id=user.district_id,
                              action=self.CMD,
                              crop_name=cmd.plant,
                              quantity=0)

        harvest_total.quantity -= cmd.amount
        harvest_total.put()
        sell_total.quantity += cmd.amount
        sell_total.put()

        return _('Sell command succeeded')
Exemplo n.º 2
0
    def execute(self):
        """
        Update plant totals
        """
        cmd = self.command
        user = cmd.sms.user

        if RECORD_PLANT not in user.permissions:
            logging.info('{} - User {} does not have permission {}'.format(
                cmd.sms.id, user.id, RECORD_PLANT))
            return _('Command not allowed')

        plant = Farm.query(ndb.AND(Farm.district_id == user.district_id,
                                   Farm.crop_name == cmd.plant,
                                   Farm.action == 'plant')).get()
        if not plant:
            plant = Farm(id=Farm.id(),
                         district_id=user.district_id,
                         action=self.CMD,
                         crop_name=cmd.plant,
                         quantity=0)

        plant.quantity += cmd.amount
        plant.put()

        return _('Plant command succeeded')
    def execute(self):
        """
        Update plant totals
        """
        cmd = self.command
        user = cmd.sms.user

        if RECORD_PLANT not in user.permissions:
            logging.info('{} - User {} does not have permission {}'.format(
                cmd.sms.id, user.id, RECORD_PLANT))
            return _('Command not allowed')

        plant = Farm.query(
            ndb.AND(Farm.district_id == user.district_id,
                    Farm.crop_name == cmd.plant,
                    Farm.action == 'plant')).get()
        if not plant:
            plant = Farm(id=Farm.id(),
                         district_id=user.district_id,
                         action=self.CMD,
                         crop_name=cmd.plant,
                         quantity=0)

        plant.quantity += cmd.amount
        plant.put()

        return _('Plant command succeeded')
    def execute(self):
        """
        Update plant and harvest totals
        """
        cmd = self.command
        user = cmd.sms.user

        if RECORD_HARVEST not in user.permissions:
            logging.info("{} - User {} does not have permission {}".format(cmd.sms, user.id, RECORD_HARVEST))
            return _("Command not allowed")

        plant_total = Farm.query(
            ndb.AND(Farm.district_id == user.district_id, Farm.crop_name == cmd.plant, Farm.action == "plant")
        ).get()

        if not plant_total or plant_total.quantity < cmd.amount:
            logging.info("{} - Not enough {} planted".format(cmd.sms.id, cmd.plant))
            return _("Not enough {} planted").format(cmd.plant)

        harvest_total = Farm.query(
            ndb.AND(Farm.district_id == user.district_id, Farm.crop_name == cmd.plant, Farm.action == "harvest")
        ).get()
        if not harvest_total:
            harvest_total = Farm(
                id=Farm.id(), district_id=user.district_id, action=self.CMD, crop_name=cmd.plant, quantity=0
            )

        plant_total.quantity -= cmd.amount
        plant_total.put()
        harvest_total.quantity += cmd.amount
        harvest_total.put()

        return _("Harvest command succeeded")
Exemplo n.º 5
0
    def execute(self):
        cmd = self.command
        user = self.command.sms.user

        if RECORD_SELL not in user.permissions:
            logging.info('{} - User {} does not have permission {}'.format(
                cmd.sms.id, user.id, RECORD_SELL))
            return _('Command not allowed')

        harvest_total = Farm.query(ndb.AND(Farm.district_id == user.district_id,
                                           Farm.crop_name == cmd.plant,
                                           Farm.action == 'harvest')).get()

        if not harvest_total or harvest_total.quantity < cmd.amount:
            logging.info('{} - Not enough {} harvested'.format(cmd.sms.id,
                                                               cmd.plant))
            return _('Not enough {} harvested').format(cmd.plant)

        sell_total = Farm.query(ndb.AND(Farm.district_id == user.district_id,
                                        Farm.crop_name == cmd.plant,
                                        Farm.action == 'sell')).get()
        if not sell_total:
            sell_total = Farm(id=Farm.id(),
                              district_id=user.district_id,
                              action=self.CMD,
                              crop_name=cmd.plant,
                              quantity=0)

        harvest_total.quantity -= cmd.amount
        harvest_total.put()
        sell_total.quantity += cmd.amount
        sell_total.put()

        return _('Sell command succeeded')
    def execute(self):
        """
        Update plant and harvest totals
        """
        cmd = self.command
        user = cmd.sms.user

        if RECORD_HARVEST not in user.permissions:
            logging.info('{} - User {} does not have permission {}'.format(
                cmd.sms, user.id, RECORD_HARVEST))
            return _('Command not allowed')

        plant_total = Farm.query(ndb.AND(Farm.district_id == user.district_id,
                                         Farm.crop_name == cmd.plant,
                                         Farm.action == 'plant')).get()

        if not plant_total or plant_total.quantity < cmd.amount:
            logging.info('{} - Not enough {} planted'.format(cmd.sms.id,
                                                             cmd.plant))
            return _('Not enough {} planted').format(cmd.plant)

        harvest_total = Farm.query(ndb.AND(Farm.district_id == user.district_id,
                                           Farm.crop_name == cmd.plant,
                                           Farm.action == 'harvest')).get()
        if not harvest_total:
            harvest_total = Farm(id=Farm.id(),
                                 district_id=user.district_id,
                                 action=self.CMD,
                                 crop_name=cmd.plant,
                                 quantity=0)

        plant_total.quantity -= cmd.amount
        plant_total.put()
        harvest_total.quantity += cmd.amount
        harvest_total.put()

        return _('Harvest command succeeded')