Esempio n. 1
0
    def notify_aging_repairs(self):
        """
        Reports on cases that have been red for a day
        """
        now = timezone.now()
        limit = now - timedelta(days=1)

        for l in Location.objects.filter(enabled=True):
            table = CsvTable()
            subject = _(u"Repairs aging beyond limits at %s") % l.title
            table.addheader(['ORDER', 'ASSIGNED_TO', 'STATUS', 'DAYS_RED'])

            # "Aging" repairs are ones that have been red for at least a day
            orders = Order.objects.filter(location=l,
                                          state__lt=Order.STATE_CLOSED,
                                          status_limit_yellow__lt=limit)

            for o in orders:
                username = o.get_user_name() or _("Nobody")
                status_title = o.get_status_name() or _("No Status")
                days = (now - o.status_limit_yellow).days
                table.addrow([o.code, username, status_title, days])

            if Configuration.notify_location():
                recipient = l.manager.email if l.manager else l.email
                send_table(self.mail_sender, recipient, subject, table)
            if self.mail_recipient:
                send_table(self.mail_sender, self.mail_recipient, subject, table)
Esempio n. 2
0
    def notify_stock_limits(self):
        """
        Notifies the correct parties of inventory items stocking status
        """
        subject = _(u"Products stocked below limit")

        for l in Location.objects.filter(enabled=True):
            out_of_stock = Inventory.objects.filter(
                location=l,
                amount_stocked__lt=F('amount_minimum')
            )

            table = CsvTable()
            table.addheader(['PRODUCT', 'MINIMUM', 'STOCKED'])

            for i in out_of_stock:
                table.addrow([i.product.code, i.amount_minimum, i.amount_stocked])

            if Configuration.notify_location():
                recipient = l.manager.email if l.manager else l.email
                send_table(self.mail_sender, recipient, subject, table)
            if self.mail_recipient:
                send_table(self.mail_sender, self.mail_recipient, subject, table)