def assign_only_product_as_production(db):
    "Assign only product as reference product.\n\n    Skips datasets that already have a reference product or no production exchanges. Production exchanges must have a ``name`` and an amount.\n\n    Will replace the following activity fields, if not already specified:\n\n    * 'name' - name of reference product\n    * 'unit' - unit of reference product\n    * 'production amount' - amount of reference product\n\n    "
    for ds in db:
        if ds.get('reference product'):
            continue
        products = [x for x in ds.get('exchanges', []) if (x.get('type') == 'production')]
        if (len(products) == 1):
            product = products[0]
            assert product['name']
            ds['reference product'] = product['name']
            ds['production amount'] = product['amount']
            ds['name'] = (ds.get('name') or product['name'])
            ds['unit'] = (ds.get('unit') or product.get('unit') or 'Unknown')
    return db
Assign only product as reference product.

Skips datasets that already have a reference product or no production exchanges. Production exchanges must have a ``name`` and an amount.

Will replace the following activity fields, if not already specified:

* 'name' - name of reference product
* 'unit' - unit of reference product
* 'production amount' - amount of reference product
def assign_only_product_as_production(db):
    "Assign only product as reference product.\n\n    Skips datasets that already have a reference product or no production exchanges. Production exchanges must have a ``name`` and an amount.\n\n    Will replace the following activity fields, if not already specified:\n\n    * 'name' - name of reference product\n    * 'unit' - unit of reference product\n    * 'production amount' - amount of reference product\n\n    "
    for ds in db:
        if ds.get('reference product'):
            continue
        products = [x for x in ds.get('exchanges', []) if (x.get('type') == 'production')]
        if (len(products) == 1):
            product = products[0]
            assert product['name']
            ds['reference product'] = product['name']
            ds['production amount'] = product['amount']
            ds['name'] = (ds.get('name') or product['name'])
            ds['unit'] = (ds.get('unit') or product.get('unit') or 'Unknown')
    return db