From 7392e351f801dfe18fcbd2f3b0c7913a11520265 Mon Sep 17 00:00:00 2001 From: gfawcett Date: Sun, 5 Apr 2009 20:42:51 +0000 Subject: [PATCH] fleshing out the mark-item-as-received workflow. New PhysicalObject table. Vestigial small-integer ID support. git-svn-id: svn://svn.open-ils.org/ILS-Contrib/servres/trunk@278 6d9bc8c9-1ec2-4278-b937-99fde70a366f --- conifer/syrup/admin.py | 2 +- conifer/syrup/models.py | 31 ++++++++++++++++++++++-- conifer/syrup/urls.py | 1 + conifer/syrup/views.py | 31 ++++++++++++++++++++++++ conifer/templates/phys/mark_arrived_choose.xhtml | 11 ++++++--- conifer/templates/simplemessage.xhtml | 2 +- 6 files changed, 71 insertions(+), 7 deletions(-) diff --git a/conifer/syrup/admin.py b/conifer/syrup/admin.py index 084f743..9ac7f1a 100644 --- a/conifer/syrup/admin.py +++ b/conifer/syrup/admin.py @@ -6,7 +6,7 @@ import django.db.models from conifer.syrup.models import * for m in [LibraryUnit, ServiceDesk, Member, Department, Course, Term, UserProfile, NewsItem, - Target]: + Target, PhysicalObject]: admin.site.register(m) diff --git a/conifer/syrup/models.py b/conifer/syrup/models.py index 03eb491..b33818f 100644 --- a/conifer/syrup/models.py +++ b/conifer/syrup/models.py @@ -558,16 +558,43 @@ class Target(m.Model): # SIP checkout class CheckInOut(m.Model): - """A log of checkout events.""" + """A log of checkout-to-patron and item-return events.""" is_checkout = m.BooleanField() # in or out? is_successful = m.BooleanField() # did the transaction work? staff = m.ForeignKey(User) # who processed the request? patron = m.CharField(max_length=100) # barcode patron_descrip = m.CharField(max_length=512) # ILS descrip - item = m.CharField(max_length=100, null=True) + item = m.CharField(max_length=100, null=True) # item barcode item_descrip = m.CharField(max_length=512, null=True) outcome = m.CharField(max_length=1024, null=True) # text msg from ILS about transaction processed = m.DateTimeField(auto_now_add=True) +class PhysicalObject(m.Model): + """A record of a physical object entering and leaving the Reserves area.""" + barcode = m.CharField(max_length=100) # item barcode + receiver = m.ForeignKey(User, related_name='receiver') # who received the item? + received = m.DateTimeField(auto_now_add=True) + departer = m.ForeignKey(User, blank=True, null=True, related_name='departer') # who sent it away? + departed = m.DateTimeField(blank=True, null=True) + # an optional small-integer used as a human-shareable barcode by some institutions. + smallint = m.IntegerField(blank=True, null=True) + + + def save(self, force_insert=False, force_update=False): + # Must ensure that barcode is unique for non-departed items. Same with smallint + try: + already = PhysicalObject.objects.exclude(pk=self.id).get(departed=None) + if self.smallint: + already = PhysicalObject.objects.exclude(pk=self.id).get(smallint=smallint) + except PhysicalObject.DoesNotExist: + super(PhysicalObject, self).save(force_insert, force_update) + else: + raise AssertionError, 'barcode is not unique in active PhysicalObject collection.' + + @classmethod + def by_barcode(cls, barcode): + """Find object by barcode, searching *only* the non-departed items.""" + res = cls.objects.filter(departed=None, barcode=barcode) + return res and res[0] or None diff --git a/conifer/syrup/urls.py b/conifer/syrup/urls.py index bda3362..36b9170 100644 --- a/conifer/syrup/urls.py +++ b/conifer/syrup/urls.py @@ -50,6 +50,7 @@ urlpatterns = patterns('conifer.syrup.views', (r'^phys/$', 'phys_index'), (r'^phys/checkout/$', 'phys_checkout'), (r'^phys/mark_arrived/$', 'phys_mark_arrived'), + (r'^phys/mark_arrived/match/$', 'phys_mark_arrived_match'), (r'^course/(?P\d+)/reseq$', 'course_reseq'), (ITEM_PREFIX + r'reseq', 'item_heading_reseq'), diff --git a/conifer/syrup/views.py b/conifer/syrup/views.py index 133311c..1c181c2 100644 --- a/conifer/syrup/views.py +++ b/conifer/syrup/views.py @@ -1330,6 +1330,12 @@ def phys_mark_arrived(request): return g.render('phys/mark_arrived.xhtml') else: barcode = request.POST.get('item', '').strip() + already = models.PhysicalObject.by_barcode(barcode) + if already: + msg = _('This item has already been marked as received. Date received: %s') + msg = msg % str(already.received) + return simple_message(_('Item already marked as received'), msg) + bib_id = lib_integration.barcode_to_bib_id(barcode) marcxml = lib_integration.bib_id_to_marcxml(bib_id) dct = marcxml_to_dictionary(marcxml) @@ -1342,3 +1348,28 @@ def phys_mark_arrived(request): bib_id=bib_id, ranked=ranked, metadata=dct) + +@admin_only +def phys_mark_arrived_match(request): + #[(u'barcode', u'30007000110717'), (u'choose_27', u'on')] + choices = [int(k.split('_')[1]) for k in request.POST if k.startswith('choose_')] + if not choices: + return simple_message(_('No matching items selected!'), + _('You must select one or more matching items from the list.')) + else: + barcode = request.POST.get('barcode', '').strip() + assert barcode + smallint = request.POST.get('smallint', '').strip() # will be '' for now. + phys = models.PhysicalObject(barcode=barcode, + receiver = request.user, + smallint = smallint or None) + phys.save() + + for c in choices: + item = models.Item.objects.get(pk=c) + if not item.barcode(): + item.metadata_set.create(name='syrup:barcode', value=barcode) + item.save() + return simple_message(_('Matches saved.'), '', go_back=False) + + diff --git a/conifer/templates/phys/mark_arrived_choose.xhtml b/conifer/templates/phys/mark_arrived_choose.xhtml index b3b8df1..cde15bb 100644 --- a/conifer/templates/phys/mark_arrived_choose.xhtml +++ b/conifer/templates/phys/mark_arrived_choose.xhtml @@ -21,7 +21,6 @@ title = _('Mark Items as Arrived: Choose Match')

${title}

-
@@ -36,7 +35,13 @@ title = _('Mark Items as Arrived: Choose Match')

Matches

-

+ +
+ Optional: Small-number ID for this item: + +
+

+ @@ -52,7 +57,7 @@ title = _('Mark Items as Arrived: Choose Match') +
- diff --git a/conifer/templates/simplemessage.xhtml b/conifer/templates/simplemessage.xhtml index 82f5329..78f9a27 100644 --- a/conifer/templates/simplemessage.xhtml +++ b/conifer/templates/simplemessage.xhtml @@ -8,6 +8,6 @@

${title}

${content} -

Go back

+

Go back

-- 2.11.0