Beispiel #1
0
    def send_errors(self, transactions, bad_codes):
        report_helper = ProductsReportHelper(self.user.sql_location,
                                             transactions)

        kwargs = {}

        if report_helper.reported_products():
            kwargs['stocks'] = ", ".join([
                product.code for product in
                report_helper.reported_products().order_by('code')
            ])
            error_message = 'You reported: {stocks}, but there were errors: {err}'
        else:
            error_message = '{err}'

        missing = report_helper.missing_products()
        if missing:
            kwargs['missing'] = ", ".join(
                [product.code for product in missing])
            error_message += " Please report {missing}"

        bad_codes = ', '.join(bad_codes)
        if bad_codes:
            kwargs[
                'err'] = 'Unrecognized commodity codes: {bad_codes}.'.format(
                    bad_codes=bad_codes)

        self.respond('{} {}'.format(error_message.format(**kwargs),
                                    unicode(ASSISTANCE_MESSAGE)))
Beispiel #2
0
def stock_alerts(transactions, user):
    report_helper = ProductsReportHelper(user.sql_location, transactions)
    products_below = report_helper.low_supply()
    stockouts = report_helper.stockouts()
    overstocked = report_helper.overstocked()
    receipts = report_helper.receipts()
    missings = report_helper.missing_products()
    message = ""
    super_message = ""
    if missings:
        products_codes_str = ' '.join(sorted([missing.code for missing in missings]))
        message += " still missing %s. " % products_codes_str

    if stockouts:
        products_codes_str = ' '.join([stockout.sql_product.code for stockout in stockouts])
        products_names_str = ' '.join([stockout.sql_product.name for stockout in stockouts])
        message += " " + STOCKOUTS_MESSAGE % {'products': products_codes_str}
        super_message = _("stockouts %s; ") % products_names_str

    if products_below:
        products_codes_str = ' '.join([product.sql_product.code for product in products_below])
        products_names_str = ' '.join([product.sql_product.name for product in products_below])
        message += " " + LOW_SUPPLY_MESSAGE % {'low_supply': products_codes_str}
        super_message += _("below reorder level %s; ") % products_names_str

    if stockouts or products_below:
        reorders = [
            u'%s %s' % (code, amount)
            for (code, amount) in report_helper.reorders()
            if amount
        ]
        if reorders:
            message += " Please order %s." % ' '.join(reorders)

    if overstocked:
        if not message:
            products_codes_str = ' '.join([overstock.sql_product.code for overstock in overstocked])
            message += " " + OVERSTOCKED_MESSAGE % {'username': user.username, 'overstocked': products_codes_str}
        products_names_str = ' '.join([overstock.sql_product.name for overstock in overstocked])
        super_message += _("overstocked %s; ") % products_names_str

    if not message:
        if not receipts:
            message = COMPLETE_REPORT % user.username
        else:
            products_str = ' '.join(
                [
                    "%s %s" % (SQLProduct.objects.get(product_id=receipt.product_id).code, receipt.quantity)
                    for receipt in receipts
                ]
            )
            message = RECEIPT_MESSAGE % {'username': user.username, 'received': products_str}
    else:
        message = (_('Dear %s,') % user.username) + message

    if super_message:
        stripped_message = super_message.strip().strip(';')
        super_message = _('Dear %s, %s is experiencing the following problems: ') + stripped_message
        send_message_to_admins(user, super_message.rstrip())
    send_sms_to_verified_number(user.get_verified_number(), message.rstrip())
Beispiel #3
0
    def get_alerts(self, transactions):
        report_helper = ProductsReportHelper(self.sql_location, transactions)
        products_below = report_helper.low_supply()
        stockouts = report_helper.stockouts()
        overstocked = report_helper.overstocked()
        receipts = report_helper.receipts()
        missings = report_helper.missing_products()
        message = ""
        super_message = ""
        if missings:
            products_codes_str = " ".join(sorted([missing.code for missing in missings]))
            message += " still missing %s. " % products_codes_str

        if stockouts:
            products_codes_str = " ".join([stockout.sql_product.code for stockout in stockouts])
            products_names_str = " ".join([stockout.sql_product.name for stockout in stockouts])
            message += " " + STOCKOUTS_MESSAGE % {"products": products_codes_str}
            super_message = _("stockouts %s; ") % products_names_str

        if products_below:
            products_codes_str = " ".join([product.sql_product.code for product in products_below])
            products_names_str = " ".join([product.sql_product.name for product in products_below])
            message += " " + LOW_SUPPLY_MESSAGE % {"low_supply": products_codes_str}
            super_message += _("below reorder level %s; ") % products_names_str

        if stockouts or products_below:
            reorders = [u"%s %s" % (code, amount) for (code, amount) in report_helper.reorders() if amount]
            if reorders:
                message += " Please order %s." % " ".join(reorders)

        if overstocked:
            if not message:
                products_codes_str = " ".join([overstock.sql_product.code for overstock in overstocked])
                message += " " + OVERSTOCKED_MESSAGE % {
                    "username": self.user.full_name,
                    "overstocked": products_codes_str,
                }
            products_names_str = " ".join([overstock.sql_product.name for overstock in overstocked])
            super_message += _("overstocked %s; ") % products_names_str

        if not message:
            if not receipts:
                message = COMPLETE_REPORT % self.user.full_name
            else:
                products_str = " ".join(
                    [
                        "%s %s" % (SQLProduct.objects.get(product_id=receipt.product_id).code, receipt.quantity)
                        for receipt in receipts
                    ]
                )
                message = RECEIPT_MESSAGE % {"username": self.user.full_name, "received": products_str}
        else:
            message = (_("Dear %s,") % self.user.full_name) + message

        if super_message:
            stripped_message = super_message.strip().strip(";")
            super_message = _("Dear %(name)s, %(location)s is experiencing the following problems: ") + stripped_message

        return message.rstrip(), super_message
Beispiel #4
0
    def send_errors(self, transactions, bad_codes):
        report_helper = ProductsReportHelper(self.user.sql_location, transactions)

        kwargs = {}

        if report_helper.reported_products():
            kwargs['stocks'] = ", ". join(
                [product.code for product in report_helper.reported_products().order_by('code')]
            )
            error_message = 'You reported: {stocks}, but there were errors: {err}'
        else:
            error_message = '{err}'

        missing = report_helper.missing_products()
        if missing:
            kwargs['missing'] = ", ".join([product.code for product in missing])
            error_message += " Please report {missing}"

        bad_codes = ', '.join(bad_codes)
        if bad_codes:
            kwargs['err'] = 'Unrecognized commodity codes: {bad_codes}.'.format(bad_codes=bad_codes)

        self.respond('{} {}'.format(error_message.format(**kwargs), unicode(ASSISTANCE_MESSAGE)))
Beispiel #5
0
    def send_errors(self, transactions, bad_codes):
        report_helper = ProductsReportHelper(self.user.sql_location, transactions)

        kwargs = {}

        if report_helper.reported_products():
            kwargs["stocks"] = ", ".join(
                [product.code for product in report_helper.reported_products().order_by("code")]
            )
            error_message = "You reported: {stocks}, but there were errors: {err}"
        else:
            error_message = "{err}"

        missing = report_helper.missing_products()
        if missing:
            kwargs["missing"] = ", ".join([product.code for product in missing])
            error_message += " Please report {missing}"

        bad_codes = ", ".join(bad_codes)
        if bad_codes:
            kwargs["err"] = "Unrecognized commodity codes: {bad_codes}.".format(bad_codes=bad_codes)

        self.respond("{} {}".format(error_message.format(**kwargs), unicode(ASSISTANCE_MESSAGE)))
Beispiel #6
0
    def get_alerts(self, transactions):
        report_helper = ProductsReportHelper(self.sql_location, transactions)
        products_below = report_helper.low_supply()
        stockouts = report_helper.stockouts()
        overstocked = report_helper.overstocked()
        receipts = report_helper.receipts()
        missings = report_helper.missing_products()
        message = ""
        super_message = ""
        if missings:
            products_codes_str = ' '.join(sorted([missing.code for missing in missings]))
            message += " still missing %s. " % products_codes_str

        if stockouts:
            products_codes_str = ' '.join([stockout.sql_product.code for stockout in stockouts])
            products_names_str = ' '.join([stockout.sql_product.name for stockout in stockouts])
            message += " " + STOCKOUTS_MESSAGE % {'products': products_codes_str}
            super_message = _("stockouts %s; ") % products_names_str

        if products_below:
            products_codes_str = ' '.join([product.sql_product.code for product in products_below])
            products_names_str = ' '.join([product.sql_product.name for product in products_below])
            message += " " + LOW_SUPPLY_MESSAGE % {'low_supply': products_codes_str}
            super_message += _("below reorder level %s; ") % products_names_str

        if stockouts or products_below:
            reorders = [
                u'%s %s' % (code, amount)
                for (code, amount) in report_helper.reorders()
                if amount
            ]
            if reorders:
                message += " Please order %s." % ' '.join(reorders)

        if overstocked:
            if not message:
                products_codes_str = ' '.join([overstock.sql_product.code for overstock in overstocked])
                message += " " + OVERSTOCKED_MESSAGE % {'username': self.user.full_name,
                                                        'overstocked': products_codes_str}
            products_names_str = ' '.join([overstock.sql_product.name for overstock in overstocked])
            super_message += _("overstocked %s; ") % products_names_str

        if not message:
            if not receipts:
                message = COMPLETE_REPORT % self.user.full_name
            else:
                products_str = ' '.join(
                    [
                        "%s %s" % (SQLProduct.objects.get(product_id=receipt.product_id).code, receipt.quantity)
                        for receipt in receipts
                    ]
                )
                message = RECEIPT_MESSAGE % {'username': self.user.full_name, 'received': products_str}
        else:
            message = (_('Dear %s,') % self.user.full_name) + message

        if super_message:
            stripped_message = super_message.strip().strip(';')
            super_message = _('Dear %(name)s, %(location)s is experiencing the following problems: ') + stripped_message

        return message.rstrip(), super_message