Ejemplo n.º 1
0
def getComponentsOf(ensEntry, isEnsData=True):
    """ Get all the components of the piece,
    or the piece itself if it's a basic piece.
    """
    # Get the item entry from any type of entry.s
    entry = None
    if isEnsData:
        entry = ensDataToItemData(ensEntry)
    else:
        entry = ensEntry

    # Get the symbol
    symbol = idb.getField(entry, "SYMBOLE")

    # Get all the pieces of the plan
    components = edb.request("SYMB_ENS", symbol)

    # If there is no components for this plan,
    # then it's a basic piece.
    return components or None
Ejemplo n.º 2
0
def requestPlan(data):
    """ Perform a request to explode an item into basic parts.
    If the item is already basic, return itself.
    Otherwise, return each components exploded recursively.

    "data" must be a valid information : SYMBOLE or PLAN+REPERE separed
    by a blank space.
    """

    def getItemEntry(data):
        if len(data) == 8:
            return getItemById(data)
        elif len(data) == 6+6+1:
            a = data.split()
            return getItemByPlan(a[0], a[1])
        else:
            return None

    # Create the lists for keeping items.
    remainingItems = []
    basicItems = []

    # Get the first needed item we will explode.
    item = getItemEntry(data)
    if item is None:
        return item

    # The first item needs to be treated differently.
    components = getComponentsOf(item, isEnsData=False)
    if not components:
        # No components, then create a final entry and make it the only
        # basic item.
        symbol = idb.getField(item, "SYMBOLE")
        design = idb.getField(item, "DESIGN")
        qte = "1"
        falseEnsEntry = [None, symbol, None, design, qte]
        basicItem.append(falseEnsEntry)
    else:
        # Otherwise, there is some components, so add them into the
        # list of potentially exploded items.
        [remainingItems.append(t) for t in components]

    

    # While there is items to explode.
    while remainingItems:
        item = remainingItems.pop()

        # Get the components of the current item.
        components = getComponentsOf(item)

        # If no components for the item, it is a final item
        if not components:
            basicItems.append(item)

        # Otherwise, there is more items to explode
        else:
            [remainingItems.append(t) for t in components]

            
    for i in basicItems:print(i)
    # Then, get the interresting fields of the final result. (All the basic items)
    fields = ("SYMB_COMP", "DESIGN", "QTE")
    result = edb.getFields(basicItems, fields)

    # Merge the same items
    return listFusion(result)