def save_pdf(self, save_model=True):
        """
        Save the receipt as a PDF related to this model.

        The related :class:`~.Receipt` should be validated first, of course.

        :param bool save_model: If True, immediately save this model instance.
        """
        from django_afip.views import ReceiptPDFView

        if not self.receipt.is_validated:
            raise exceptions.DjangoAfipException(
                _('Cannot generate pdf for non-authorized receipt')
            )

        self.pdf_file = File(BytesIO(), name='{}.pdf'.format(uuid.uuid4().hex))
        render_pdf(
            template='receipts/code_{}.html'.format(
                self.receipt.receipt_type.code,
            ),
            file_=self.pdf_file,
            context=ReceiptPDFView.get_context_for_pk(self.receipt_id),
        )

        if save_model:
            self.save()
Save the receipt as a PDF related to this model.

        The related :class:`~.Receipt` should be validated first, of course.

        :param bool save_model: If True, immediately save this model instance.