Code Duplication    Length = 33-34 lines in 2 locations

chezbetty/datalayer.py 2 locations

@@ 395-428 (lines=34) @@
392
            item.enabled = True
393
            # Create a subtransaction to track that this item was added
394
            rli = transaction.RestockLineItem(t, total, item, quantity, wholesale, coupon, salestax, btldeposit)
395
            DBSession.add(rli)
396
            #amount += Decimal(total)
397
398
        elif type(thing) is Box:
399
            box = thing
400
401
            # Create a subtransaction to record that the box was restocked
402
            rlb = transaction.RestockLineBox(t, total, box, quantity, wholesale, coupon, salestax, btldeposit)
403
            DBSession.add(rlb)
404
            DBSession.flush()
405
406
            # Iterate all the subitems and update the stock
407
            for itembox in box.items:
408
                subitem = itembox.item
409
                subquantity = itembox.quantity * quantity
410
                subitem.enabled = True
411
                subitem.in_stock += subquantity
412
413
                rlbi = transaction.RestockLineBoxItem(rlb, subitem, subquantity)
414
                DBSession.add(rlbi)
415
416
        amount += Decimal(total)
417
418
    t.update_amount(amount)
419
    return e
420
421
422
# Call this when a user runs inventory
423
def reconcile_items(items, admin):
424
    e = event.Inventory(admin)
425
    DBSession.add(e)
426
    DBSession.flush()
427
    t = transaction.Inventory(e)
428
    DBSession.add(t)
429
    DBSession.flush()
430
    total_amount_missing = Decimal(0)
431
    for item, quantity in items.items():
@@ 458-490 (lines=33) @@
455
    safe_c = account.get_cash_account("safe")
456
    expected_amount = safe_c.balance
457
    amount_missing = expected_amount - amount
458
459
    if amount_missing != 0.0:
460
        # If the amount in the safe doesn't match what we expected there to
461
        # be, we need to adjust the amount in the cash box be transferring
462
        # to or from a null account
463
464
        if amount_missing > 0:
465
            # We got less in the box than we expected
466
            # Move money from the safe account to null with transaction type
467
            # "lost"
468
            t1 = transaction.Lost(e, account.get_cash_account("safe"), amount_missing)
469
            DBSession.add(t1)
470
471
        else:
472
            # We got more in the box than expected! Use a found transaction
473
            # to reconcile the difference
474
            t1 = transaction.Found(e, account.get_cash_account("safe"), abs(amount_missing))
475
            DBSession.add(t1)
476
477
478
    # Now move all the money from the safe to chezbetty
479
    t2 = transaction.EmptySafe(e, amount)
480
    DBSession.add(t2)
481
    return e
482
483
484
# Call this to move all of the money from the cash box to the safe.
485
# We don't actually count the amount, so we do no reconciling here, but it
486
# means that money isn't sitting in the store.
487
def cashbox_to_safe(admin):
488
    e = event.EmptyCashBox(admin)
489
    DBSession.add(e)
490
    DBSession.flush()
491
492
    t = transaction.EmptyCashBox(e)
493
    DBSession.add(t)