Create or update a record matching xmlid with values

def create_or_update(ctx, model, xmlid, values):
    """ Create or update a record matching xmlid with values """
    if isinstance(model, basestring):
        model = ctx.env[model]

    record = ctx.env.ref(xmlid, raise_if_not_found=False)
    if record:
        record.update(values)
    else:
        record = model.create(values)
        add_xmlid(ctx, record, xmlid)
    return record