<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def create_order(order):
 """ Create an order on fulfil from order_details. See the calling function below for an example of the order_details """

    SaleOrder = client.model('sale.sale')
    SaleOrderLine = client.model('sale.line')

    # Check if customer exists, if not create one
    customer_id = get_customer(order['customer']['code'])
    if not customer_id:
        customer_id = create_customer(
            order['customer']['name'],
            order['customer']['email'],
            order['customer']['phone'],
        )

    # No check if there is a matching address
    invoice_address = get_address(
        customer_id,
        order['invoice_address']
    )
    if not invoice_address:
        invoice_address = create_address(
            customer_id,
            order['invoice_address']
        )

    # See if the shipping address exists, if not create it
    shipment_address = get_address(
        customer_id,
        order['shipment_address']
    )
    if not shipment_address:
        shipment_address = create_address(
            customer_id,
            order['shipment_address']
        )

    sale_order_id, = SaleOrder.create([{
        'reference': order['number'],
        'sale_date': order['date'],
        'party': customer_id,
        'invoice_address': invoice_address,
        'shipment_address': shipment_address,
    }])

    # fetch inventory of all the products before we create lines
    warehouses = get_warehouses()
    warehouse_ids = [warehouse['id'] for warehouse in warehouses]

    lines = []
    for item in order['items']:
        # get the product. We assume ti already exists.
        product = get_product(item['product'])

        # find the first location that has inventory
        product_inventory = get_product_inventory(product, warehouse_ids)
        for location, quantities in product_inventory.items():
            if quantities['quantity_available'] >= item['quantity']:
                break

        lines.append({
            'sale': sale_order_id,
            'product': product,
            'quantity': item['quantity'],
            'unit_price': item['unit_price'],
            'warehouse': location,
        })

    SaleOrderLine.create(lines)

    SaleOrder.quote([sale_order_id])
    SaleOrder.confirm([sale_order_id])