Code Duplication    Length = 33-34 lines in 2 locations

chezbetty/datalayer.py 2 locations

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