Exemple #1
0
def post_transaction_save(sender, instance, **kwargs):
    transaction = instance

    if hasattr(transaction, '.recently_transitioned'):
        delattr(transaction, '.recently_transitioned')
        transaction.update_document_state()

    if hasattr(transaction, '.cleaned'):
        delattr(transaction, '.cleaned')

    if not getattr(transaction, 'previous_instance', None):
        # we know this instance is freshly made as it doesn't have an old_value
        logger.info(
            '[Models][Transaction]: %s', {
                'detail':
                'A transaction was created.',
                'transaction_id':
                transaction.id,
                'customer_id':
                transaction.customer.id,
                'invoice_id':
                transaction.invoice.id if transaction.invoice else None,
                'proforma_id':
                transaction.proforma.id if transaction.proforma else None
            })
Exemple #2
0
def post_transaction_save(sender, instance, **kwargs):
    transaction = instance

    if hasattr(transaction, '.recently_transitioned'):
        delattr(transaction, '.recently_transitioned')
        transaction.update_document_state()

    if hasattr(transaction, '.cleaned'):
        delattr(transaction, '.cleaned')

    FAIL_MAIL = getattr(settings, 'EMAIL_ON_TRANSACTION_FAIL', False)

    if FAIL_MAIL:
        print("bbq")
        if transaction.state == Transaction.States.Failed:
            subject = "Transaction %s has failed" % transaction.id
            kwargs = {
                # 'fail_silently': True,
            }
            msg_kwargs = {
                'detail': 'Transaction has failed.',
                'transaction_id': transaction.id,
                'customer_id': transaction.customer.id,
                'invoice_id': transaction.invoice.id \
                    if transaction.invoice else None,
                'proforma_id':
                    transaction.proforma.id if transaction.proforma else None
            }

            try:
                mail_managers(subject, msg % msg_kwargs, **kwargs)
            except:
                logger.info('Unable to send mail - [Models][Transaction]: %s',
                            msg_kwargs)

    if not getattr(transaction, 'previous_instance', None):
        # we know this instance is freshly made as it doesn't have an old_value
        logger.info(
            '[Models][Transaction]: %s', {
                'detail':
                'A transaction was created.',
                'transaction_id':
                transaction.id,
                'customer_id':
                transaction.customer.id,
                'invoice_id':
                transaction.invoice.id if transaction.invoice else None,
                'proforma_id':
                transaction.proforma.id if transaction.proforma else None
            })
Exemple #3
0
def post_transaction_save(sender, instance, **kwargs):
    transaction = instance

    if hasattr(transaction, '.recently_transitioned'):
        delattr(transaction, '.recently_transitioned')
        transaction.update_document_state()

    if hasattr(transaction, '.cleaned'):
        delattr(transaction, '.cleaned')

    if not getattr(transaction, 'previous_instance', None):
        # we know this instance is freshly made as it doesn't have an old_value
        logger.info('[Models][Transaction]: %s', {
            'detail': 'A transaction was created.',
            'transaction_id': transaction.id,
            'customer_id': transaction.customer.id,
            'invoice_id': transaction.invoice.id if transaction.invoice else None,
            'proforma_id':
                transaction.proforma.id if transaction.proforma else None
        })