diff --git a/combo/apps/lingo/models.py b/combo/apps/lingo/models.py index cec8bfc8..f196a5b2 100644 --- a/combo/apps/lingo/models.py +++ b/combo/apps/lingo/models.py @@ -29,6 +29,7 @@ from django.db import models from django.forms import models as model_forms, Select from django.utils.translation import ugettext_lazy as _ from django.utils import timezone +from django.core.exceptions import PermissionDenied from ckeditor.fields import RichTextField @@ -52,7 +53,8 @@ def build_remote_item(data, regie): display_id=data['display_id'], total_amount=data.get('total_amount'), amount=data.get('amount'), - subject=data.get('label')) + subject=data.get('label'), + has_pdf=data.get('has_pdf')) class Regie(models.Model): @@ -106,6 +108,17 @@ class Regie(models.Model): return [build_remote_item(item, self) for item in items.get('data')] return [] + def download_item(self, request, item_id): + """ + downloads item's file + """ + if self.is_remote(): + if hasattr(request, 'session') and request.session.get('mellon_session'): + mellon = request.session.get('mellon_session') + url = self.webservice_url + '/invoice/%s/pdf' % item_id + return self.get_url(request, url, NameID=mellon['name_id_content']) + raise PermissionDenied + def as_api_dict(self): return {'slug': self.slug, 'label': self.label, @@ -144,7 +157,7 @@ class BasketItem(models.Model): class RemoteItem(object): def __init__(self, id, regie, creation_date, total_amount, - amount, display_id, subject): + amount, display_id, subject, has_pdf): self.id = id self.regie = regie self.creation_date = parser.parse(creation_date) @@ -152,6 +165,7 @@ class RemoteItem(object): self.display_id = display_id self.amount = amount self.subject = subject + self.has_pdf = has_pdf class Transaction(models.Model): diff --git a/combo/apps/lingo/templates/lingo/combo/items.html b/combo/apps/lingo/templates/lingo/combo/items.html index 4e249c44..304f941a 100644 --- a/combo/apps/lingo/templates/lingo/combo/items.html +++ b/combo/apps/lingo/templates/lingo/combo/items.html @@ -9,6 +9,7 @@