Beispiel #1
0
def contract_create(values, context):

    if context.is_admin:
        values['contract_id'] = uuidutils.generate_uuid()
        # exception for foreign key constraint needed here
        offers = values['offers']

        del values['offers']
        contract_ref = models.Contract()
        contract_ref.update(values)
        contract_ref.save(get_session())
        # update foreign key for offers
        for offer_id in offers:
            ocr_data = dict(contract_id=values['contract_id'],
                            offer_id=offer_id,
                            status=statuses.AVAILABLE)
            offer_contract_relationship_create(context, ocr_data)
        return contract_ref
    else:
        raise exception.RequiresAdmin(resource_type="Contract")
Beispiel #2
0
def contract_create(values, context):

    if context.is_admin:
        values['contract_id'] = uuidutils.generate_uuid()
        # exception for foreign key constraint needed here
        offers = values['offers']

        del values['offers']
        contract_ref = models.Contract()
        contract_ref.update(values)
        contract_ref.save(get_session())
        # update foreign key for offers
        for offer_id in offers:
            ocr_data = dict(contract_id=values['contract_id'],
                            marketplace_offer_id=offer_id,
                            status='unretrieved')
            offer_contract_relationship_create(context, ocr_data)
        return contract_ref
    else:
        return None