x Sorry, these patches are not available anymore due to data migration. Please run a fresh inspection.

Code Duplication    Length = 33-34 lines in 2 locations

chezbetty/datalayer.py 2 locations

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