Code Duplication    Length = 14-16 lines in 2 locations

chezbetty/models/transaction.py 2 locations

@@ 745-760 (lines=16) @@
742
            raise AttributeError
743
744
    @classmethod
745
    @limitable_all
746
    def all_item(cls, id):
747
        return DBSession.query(cls)\
748
                        .join(Transaction)\
749
                        .join(event.Event)\
750
                        .filter(cls.item_id == id)\
751
                        .filter(event.Event.deleted==False)\
752
                        .order_by(desc(event.Event.timestamp))
753
754
    @classmethod
755
    @limitable_all
756
    def all_item_purchases(cls, id):
757
        return DBSession.query(cls)\
758
                        .join(Transaction)\
759
                        .join(event.Event)\
760
                        .filter(cls.item_id == id)\
761
                        .filter(event.Event.deleted==False)\
762
                        .filter(event.Event.type=="purchase")\
763
                        .order_by(desc(event.Event.timestamp))
@@ 424-437 (lines=14) @@
421
        days = Transaction.get_days_in_debt_for_user(u)
422
        if days >= 7:
423
            deadbeats.append(u)
424
425
    return deadbeats
426
user.User.get_deadbeats = __get_deadbeats
427
428
# This is in a stupid place due to circular input problems
429
@property
430
def __days_since_last_purchase(self):
431
    last_purchase = object_session(self).query(event.Event)\
432
            .join(Transaction)\
433
            .filter(Transaction.fr_account_virt_id == self.id)\
434
            .filter(event.Event.type == 'purchase')\
435
            .filter(event.Event.deleted==False)\
436
            .order_by(desc(event.Event.timestamp)).first()
437
438
    if last_purchase:
439
        diff = arrow.now() - last_purchase.timestamp
440
        return diff.days