def get_payment_status(self, d=None):
        return PaymentStatus(
            price=self.price,
            discount=self.get_discounted(d),
            explanation=",\n".join(
                discount.explanation.strip()
                for discount in self.all_discounts
                if (d is None or discount.accounted.date() <= d) and discount.explanation.strip()
            ),
            received=self.get_received(d),
            returned=self.get_returned(d),
            current_date=d or date.today(),
            due_from=self.payment_requested
            and (
                self.payment_requested.date()
                if self.subject.orderable.due_from_days is None
                else max(
                    self.start_date - timedelta(days=self.subject.orderable.due_from_days),
                    self.payment_requested.date(),
                )
            ),
            due_date=self.payment_requested
            and max(
                self.start_date - timedelta(days=self.subject.orderable.due_date_days),
                self.payment_requested.date() + timedelta(days=self.subject.min_due_date_days),
            ),
        )