Skip to content

Commit

Permalink
Merge pull request #819 from akvo/feature/796_paypal_code
Browse files Browse the repository at this point in the history
[#796] Re-added Invoice signal
  • Loading branch information
kardan committed Oct 21, 2014
2 parents ac197ef + 354bebc commit a4175ea
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 4 deletions.
14 changes: 14 additions & 0 deletions akvo/rsr/models/invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

from mollie.ideal.utils import get_mollie_banklist

from paypal.standard.ipn.signals import payment_was_flagged

from ..fields import ValidXMLCharField, ValidXMLTextField


Expand Down Expand Up @@ -149,3 +151,15 @@ class Meta:
app_label = 'rsr'
verbose_name = u'invoice'
ordering = ['-id', ]


# PayPal IPN listener
def process_paypal_ipn(sender, **kwargs):
ipn = sender
if ipn.payment_status == 'Completed':
invoice = Invoice.objects.get(pk=int(ipn.invoice))
invoice.amount_received = invoice.amount - ipn.mc_fee
invoice.ipn = ipn.txn_id
invoice.status = 3
invoice.save()
payment_was_flagged.connect(process_paypal_ipn)
3 changes: 2 additions & 1 deletion akvo/scripts/rain/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,8 @@ def load_xml(location):
ACTION_CREATE_IOI = 'internal org id created'
ACTION_CREATE_ORG = 'organisation created'
ACTION_UPDATE_ORG = 'organisation updated'
ACTION_PUBLISHING_SET = 'set publishing status'
ACTION_PROJECT_PUBLISHED = 'project published'
ACTION_PROJECT_NOT_PUBLISHED = 'project not published'
ACTION_PROJECT_POST_PROCESS_DONE = 'project saved'

ERROR_COUNTRY_CODE = 'invalid country code'
Expand Down
29 changes: 26 additions & 3 deletions akvo/scripts/rain/post_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
from akvo.scripts.rain import (
RAIN_ORG_ID, print_log, log, ERROR_IMAGE_UPLOAD, ACTION_SET_IMAGE, init_log, outsys, RainActivity, RAIN_ACTIVITY_NS,
AKVO_NS, RAIN_POST_PROCESS_CSV_FILE,ERROR_PROJECT_NOT_FOUND, ERROR_PROJECT_DATA_INVALID, ERROR_PROJECT_NOT_SAVED,
ERROR_IMAGE_NOT_FOUND, ACTION_PROJECT_POST_PROCESS_DONE, load_xml, RAIN_IATI_ACTIVITES_URL
)
ERROR_IMAGE_NOT_FOUND, ACTION_PROJECT_POST_PROCESS_DONE, load_xml, RAIN_IATI_ACTIVITES_URL,
ACTION_PROJECT_PUBLISHED, ACTION_PROJECT_NOT_PUBLISHED)

import logging
logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -153,7 +153,30 @@ def _sync_owner(self):
self.project.sync_owner = rain

def _publish(self):
self.project.publishingstatus.status = PublishingStatus.STATUS_PUBLISHED
has_image = self.project.current_image != ''
has_lat_long = self.project.primary_location.latitude != 0 or self.project.primary_location.longitude != 0
if has_image and has_lat_long:
self.project.publishingstatus.status = PublishingStatus.STATUS_PUBLISHED
log(
"Project ID: {rsr_id} published",
dict(
rsr_id=self.project.pk,
internal_id=self.activity.internal_id(),
iati_id=self.activity.iati_id(),
event=ACTION_PROJECT_PUBLISHED,
)
)
else:
self.project.publishingstatus.status = PublishingStatus.STATUS_UNPUBLISHED
log(
"Project ID: {rsr_id} not published",
dict(
rsr_id=self.project.pk,
internal_id=self.activity.internal_id(),
iati_id=self.activity.iati_id(),
event=ACTION_PROJECT_NOT_PUBLISHED,
)
)
self.project.publishingstatus.save()

def process(self):
Expand Down

0 comments on commit a4175ea

Please sign in to comment.