You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
1.9 KiB

6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
  1. # -*- coding: utf-8 -*-
  2. from datetime import datetime
  3. import logging
  4. from openerp import api, fields, models
  5. _logger = logging.getLogger(__name__)
  6. class PaymentTransaction(models.Model):
  7. _inherit = 'payment.transaction'
  8. release_capital_request = fields.Many2one('account.invoice',
  9. string="Release Capital request")
  10. @api.model
  11. def process_online_payment_reception(self, tx):
  12. release_capital_request = tx.release_capital_request
  13. release_capital_request.subscription_request[0].state = 'paid'
  14. effective_date = datetime.now().strftime("%d/%m/%Y")
  15. release_capital_request.sudo().set_cooperator_effective(effective_date)
  16. return True
  17. @api.v7
  18. def _paypal_form_validate(self, cr, uid, tx, data, context=None):
  19. status = data.get('payment_status')
  20. res = {
  21. 'acquirer_reference': data.get('txn_id'),
  22. 'paypal_txn_type': data.get('payment_type'),
  23. }
  24. if status in ['Completed', 'Processed']:
  25. _logger.info('Validated Paypal payment for tx %s: set as done' % (tx.reference))
  26. res.update(state='done', date_validate=fields.Datetime.now())
  27. result = tx.write(res)
  28. self.process_online_payment_reception(cr, uid, tx)
  29. return result
  30. elif status in ['Pending', 'Expired']:
  31. _logger.info('Received notification for Paypal payment %s: set as pending' % (tx.reference))
  32. res.update(state='pending', state_message=data.get('pending_reason', ''))
  33. return tx.write(res)
  34. else:
  35. error = 'Received unrecognized status for Paypal payment %s: %s, set as error' % (tx.reference, status)
  36. _logger.info(error)
  37. res.update(state='error', state_message=error)
  38. return tx.write(res)