Code Duplication    Length = 33-34 lines in 2 locations

chezbetty/datalayer.py 2 locations

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