예제 #1
0
파일: invoice.py 프로젝트: Jasu/Lokki
def commandInvoiceMerge(args, session):
    sourceInvoice = session.query(Invoice).filter_by(invoice_number=args.source_invoice_number).first()

    targetInvoice = session.query(Invoice).filter_by(invoice_number=args.target_invoice_number).first()

    dieIf(not sourceInvoice, "Source invoice not found.")
    dieIf(not targetInvoice, "Target invoice not found.")
    dieIf(sourceInvoice.is_billed, "Source invoice is billed.")
    dieIf(targetInvoice.is_billed, "Target invoice is billed.")

    # Make copy of the array, since elements are removed from it during moving,
    # making for loop to iterate only 1/2 rows.
    rows = sourceInvoice.rows[:]
    for row in rows:
        print("Moving row #" + str(row.id) + ".")
        row.invoice = targetInvoice

    session.commit()

    compressIndices(session, Row, invoice_id=targetInvoice.id)

    session.commit()

    print(
        "Moved rows from invoice #"
        + str(args.source_invoice_number)
        + " to invoice #"
        + str(args.target_invoice_number)
        + "."
    )
예제 #2
0
파일: subrow.py 프로젝트: Jasu/Lokki
def commandSubrowMv(args, session):
    invoice = beginRowCommand(args, session)
    srcRow = invoice.rows[int(args.src_row_index) - 1]
    dstRow = invoice.rows[int(args.dst_row_index) - 1]

    if srcRow == dstRow:
        print('Source and destination are the same row.')
        print('Nothing done.')
        return 

    subrow = findSubrow(srcRow, args.subrow_index)

    subrow.row_id = dstRow.id
    subrow.index = len(dstRow.subrows) + 1
    session.commit()

    compressIndices(session, Subrow, row_id=srcRow.id)

    session.commit()
예제 #3
0
파일: composite.py 프로젝트: Jasu/Lokki
def commandCompositeMerge(args, session):
    invoice = beginRowCommand(args, session)
    sourceRow = invoice.rows[int(args.source_index) - 1] 
    targetRow = invoice.rows[int(args.target_index) - 1] 
    dieIf(not isinstance(sourceRow, CompositeRow), 
          "Source row is not a composite row.");
    dieIf(not isinstance(targetRow, CompositeRow), 
          "Target row is not a composite row.");
    dieIf(sourceRow == targetRow, 
          "Source and target rows cannot be the same row.")

    subrows = sourceRow.subrows[:]
    for subrow in subrows:
        subrow.row = targetRow

    session.delete(sourceRow);

    session.commit();

    compressIndices(session, Subrow, row_id=targetRow.id)
    compressIndices(session, Row, invoice_id=invoice.id)

    session.commit();
예제 #4
0
파일: row.py 프로젝트: Jasu/Lokki
def commandRowMv(args, session):
    dieIf(not isConfigurationValid(session), 
        "Cannot execute row commands with incomplete configuration.")
    src_invoice = (session.query(Invoice)
        .filter_by(invoice_number=args.src_invoice_number)
        .first())
    dst_invoice = (session.query(Invoice)
        .filter_by(invoice_number=args.dst_invoice_number)
        .first())
    dieIf(src_invoice.is_billed, 
        "Cannot execute row commands on a billed source invoice.")
    dieIf(dst_invoice.is_billed, 
        "Cannot execute row commands on a billed source invoice.")
    dieIf(int(args.row) > len(src_invoice.rows), 'Row index is too large.')
    dieIf(int(args.row) < 1, 'Row index below one.')
    row = src_invoice.rows[int(args.row) - 1]
    row.invoice = dst_invoice

    session.commit()
    compressIndices(session, Row, invoice=dst_invoice)
    compressIndices(session, Row, invoice=src_invoice)
    session.commit()
    print("Moved row '" + str(row.index) + "'.")