Next on my list...
On Dec 20, 2013 5:35 PM, "Tyler Wymer" <notifications@github.com> wrote:

> In casexml/apps/phone/restore.py:
>
> >              )
> > -        for supply_point, products in product_by_supply_point.iteritems():
> > -            as_of = max(p['last_reported'] for p in products)
> > -            as_of = 'T'.join(as_of.split()) + 'Z' # FIXME convert to iso properly
> > -            products.sort(key=lambda p: p['product_name'])
> > -            yield E.balance(*(mk_product(e) for e in products), **{'entity-id': supply_point, 'date': as_of})
> > +        for supply_point in supply_points:
> > +            relevant_reports = StockTransaction.objects.filter(case_id=supply_point._id)
> > +            if relevant_reports:
> > +                product_ids = relevant_reports.values_list('product_id', flat=True).distinct()
> > +                products = [relevant_reports.filter(product_id=p).order_by('-report__date').select_related()[0] for p in product_ids]
> > +                as_of = json_format_datetime(max(p.report.date for p in products))
> > +                # todo: fix sorting for tests
> > +                # products.sort(key=lambda p: p['product_name'])
>
> Uh oh!
>
> —
> Reply to this email directly or view it on GitHub<https://github.com/dimagi/casexml/pull/140/files#r8513263>
> .
>